Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement ControlTemplate with C++ Code

2025-01-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you about how to use C++ code to achieve ControlTemplate, the article is rich in content and professional analysis and description for you, I hope you can get something after reading this article.

Now the mainstream development language is C++ language, but it doesn't feel as flexible as that implemented in C language. Now let's introduce how to implement ControlTemplate in the code. I hope you can learn and discuss it. OK, here is an example of C++ code:

FrameworkElementFactory fe = new FrameworkElementFactory (typeof (Image), "Image"); BitmapImage bi = new BitmapImage (); bi.BeginInit (); bi.UriSource = new Uri (@ "E:ChartControlHanYangChartControlImageMainBackground.jpg"); bi.EndInit (); fe.SetValue (Image.SourceProperty, bi) / / display content 2 (TextBox here) FrameworkElementFactory fe2 = new FrameworkElementFactory (typeof (TextBox), "TextBox"); fe2.SetValue (TextBox.WidthProperty,100.0); fe2.SetValue (TextBox.HeightProperty, 100.0) / / encapsulate the display content to be rendered FrameworkElementFactory f = new FrameworkElementFactory (typeof (Grid), "Grid"); f.AppendChild (fe); f.AppendChild (fe2)

As you can see from the table above, int is the same as long. So why does C++ code distinguish between these two data types? Actually, this is a legacy problem. In a 16-bit programming environment, int requires 2 bytes and long requires 4 bytes. In a 32-bit programming environment, both types of data are stored in 4 bytes.

C++Builder generates only 32-bit programs, so int is the same as long. It shows that Bool is a real data type in C++ Builder and BorLand C++ 5.0. Some C++ compilers have the Bool keyword, then Bool is not a true data type.

Sometimes Bool is just a typedef, making Bool equivalent to int. Typedef actually creates aliases that allow the compiler to equate one symbol with another. The syntax for typedef is as follows: typedef int Bool; tells the compiler that Bool is an alias for int. Indicates that only double and float data types use floating-point numbers (numbers with decimal points).

Other data types involve only integer values. Although the integer data type can also specify a value with a decimal point, the decimal part is discarded and only the integer part is assigned to the integer variable. For example: int x = 3.75; the value of x is 3. Note that this integer value is not rounded, but discards the decimal part. By the way, most Windows programs rarely use floating-point numbers.

C++ code can convert between different data types if necessary. For example: short result;long num1 = 200 th long num2 = 200 X result = num1 * num2; here I want to assign the product of two long integers to a short integer. Although this formula uses a mixture of two data types, C++ can be converted. What will be the result of the calculation? The result will surprise you, it's 25536, which is the result of wrop.

As can be seen from Table 1.1, the value of * * for short integers is 32767. What if you add 1 to the value of * *? What I got was 32768. This is actually the same as the car odometer from 99999 to 00000. To illustrate this, enter and run the program contained in listing 1.3 below.

Simply not using C++ (Linus's practice) to avoid the complexity of C++ is tantamount to giving up eating for fear of choking. "C++ is a better language than C in all the areas where C and C++ are available. When I say" better ", I'm saying that C++ has safer type checking, better abstraction mechanisms, and better libraries than C.

Of course, there are exceptions to everything, if you do project 1) not big. 2) there is no abstract mechanism in coding, not even ADT (abstract data types, such as std::complex, which does not contain polymorphism and inheritance), RAII, and exceptions.

3) you don't even need basic libraries (such as smart pointers and smart containers that simplify resource management). Then maybe it's okay for you to use C; so if that's your case, don't argue with me, because I can't refute you. The areas we are talking about here are roughly those that Bjarne listed in the list of C++ apps.

Even opponents of C++ may find it hard to find a reason to say, "I still don't use C++ code." In my opinion, a person who is really rationally opposed to using C++ in a practical sense has only one reason: the confusion caused by C++ 's complexity offsets or even outweighs the benefits of C++ 's abstract mechanisms and libraries (in his particular project).

It is worth noting that there is a trap to be avoided here, that is, once people decide that "C++ code is bad", then this reason will "grow their own feet", that is, even if we remove the complexity of C++, they may still insist on not using C++ and find a bunch of reasons for it.

I assume you're not like that. However, perhaps the most likely thing is that he will say: "the problem is that the C++ we use today is not so (concise), and your hypothesis is not valid." Yes, my hypothesis is not valid. But although we cannot eliminate complexity, we can actually easily avoid complexity and avoid weaknesses and strengths. This is also the main point of this article, let me elaborate later.

The above is the editor for you to share how to use C++ code to achieve ControlTemplate, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 206

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report