Commemorating a previous software product (2)-Basic Technologies and textures

Source: Internet
Author: User
Document directory
  • 3.3.1 handle the issue of hiding all windows with the host key
  • 3.3.2 full screen/non-full screen problems

"Many o2o entrepreneurs have the idea of" Big and full platform "in their hearts, but it is often unrealistic to start a business at the very beginning. We need to fully consider 'Resource allocation 'at hand ', this indicates whether you have the ability to hold external data. I hope to see more entrepreneurs who are full of lofty ideals and conscientiously performing things in a down-to-earth Manner. don't stick to the Great Blueprint, but you can't grasp the starting point. You must be able to identify the vertical segments and make it transparent !" -- This is a sentence I recently saw on Weibo. I am deeply touched by the fact that the development of the Internet industry is increasingly impossible for me to wait for the grassroots. In fact, according to Old Wu's thoughts, I want to build this software into a platform ...... I will not start this project, but I will continue to talk about this project and its related technologies. I hope someone will be able to benefit from it.

III. Basic Technology 3.1, C ++ or. NET

When I started this project, I used C ++ as the development language. Speaking of C ++, I had a lot to talk about. I don't want to start a boring language competition here, but I want to say:Every programmer should master C ++. Of course, this project uses C ++ instead. net is not just the reason of my personal preference. Considering the hardware of Windows Mobile and many actual situations, only the performance of C ++ can be met, reference the old man in the Windows Mobile Development Group: "Use. net is not a fast and slow issue, but a question of whether it can be run at all." The program uses a large number of textures, system notification message processing, registry access, and even hardware operations. These functions are easy to implement using native code. net has no advantages at all, not to mention that many Windows Mobile phones are not installed.. net, if the user is forced to install it, it will be in conflict with the user to a certain extent.

Note: In Windows Mobile,. Net stands for ". NET Compact framwork", which is different from. Net in windows. If you are interested, refer to [Wikipedia].

I used pure Windows Programming and directly used Windows APIs to write this program. I didn't even use MFC, because in such a special application, those class libraries did not help much.

Now let's look back and look at some questions: when we talk about performance, is the performance poor for Android development in Java? Are there any problems mentioned above today? -- To a large extent, none of these problems have been solved, because today's mobile phones are so powerful that quad-core phones are becoming popular and Android systems are also being standardized, google has been focusing on improving Android fragmentation, so developers do not have to bother exploring the underlying functions and methods of the system to implement some of their own functions.

3.2. Today's plug-ins are still common programs

Windows Mobile has a desktop named "today" since it was a Pocket PC, which is equivalent to Windows desktop. Let's take a look:

(Windows Mobile's "desktop"-Today)

Do you think it's quite old? How can I operate such a small object with my fingers? However, this design also makes sense. In the past, mobile phones were very different from those of the present. Some mobile phones did not have a touch screen at all, but they were chosen by the navigation key and the OK key, such as the Samsung i718 mobile phone, representative:

(Samsung i718)

Even mobile phones with touch screens may be difficult to operate with their fingers, most of which are as follows:

(Touch screen operation with pen tip)

Without limit, today's approach is to build a desktop plug-in that renders all the content on this plug-in. Of course, sosopi is also available, which is a later feature, however, it only gives users a convenient function to start sopi:

(Sosopi plug-in today)

Sosopi is not implemented as a plug-in. This part is because the debugging of the plug-in is relatively difficult today, because the plug-in has a set of rules to generate a DLL according to that set of rules, then, attach the DLL to the shell process of Windows Mobile for debugging. The other part is the meaning of Lao Wu. He hopes that the program can be hidden and the user can see his "desktop ", that is, "today ".

3.3 solve some difficult problems 3.3.1 handle the problem of hiding all windows with the host key

Windows Mobile Phones basically have a "hanging key". You should be familiar with this key, which is available on mobile phones in the past (refer to the pictures of Samsung i718 above) A dial-up key (usually green) and a hook-up key (usually red). The default act of the hook-up key is to disconnect the phone and display the desktop, so when you want to cancel all the work and hide all the programs, it is no error to press the host key. Unfortunately, the subsequent mobile phones basically remove the classic red-green keys. It is good to use the host key to hide all programs. It is a bit difficult for me because my programs, as a "desktop program", do not want to be hidden like this, I tried a lot of methods, including capturing host key events with hooks, automatically appearing after hiding, and blocking this button. The effect was not satisfactory, finally, the final solution is obtained in the Development Group. It is easy to say that the "ws_popup" attribute is added when the window is created. Oh, my God. Is that simple?

It's really that simple, but it takes me a lot of time to do this. It's not hard to say that, but a lot of things are like this ...... Have you ever had a similar experience in the development process?

3.3.2 full screen/non-full screen problems

Technically, the vast majority of Windows Mobile programs are "full screen". That is to say, only one program is displayed on a screen, and all programs are "maximized" by default ", here, full screen refers to hiding the taskbar, toolbar, input method buttons, and adjusting the size and position of the program window to full screen. This is the technical description of "full screen.

(Taskbar, menu bar and Input Method buttons)

These seemingly non-problematic things have become a problem in Windows Mobile because they are fragmented. Now we hear the most fragmentation from the Android system, every mobile phone manufacturer wants to make some differentiated customization of the system and intentionally or unintentionally modifies the default behavior of the system. As a result, the software manufacturer encounters some incompatibility problems during development, what I want to say is: Compared with Windows Mobile, Android is really much better. At least it still has some rules to follow, while Windows Mobile has no rules. I will elaborate on this later.

Finally, I found a better way to enable the program to be displayed in full screen and easily switch to non-full screen display. It has passed the test on many machines, so there is no big problem. Of course, there have also been a lot of attempts. The code snippet is as follows:

            if(g_gm.IsFullScreen())            {                // It is the responsibility of the application to make sure it is sized                // FULL SCREEN before using this flag. Otherwise, it will appear as though                // the function did nothing.                //     -- MSDN                RECT rectFullScreen;                SetRect(&rectFullScreen, 0, 0, GetSystemMetrics(SM_CXSCREEN),                    GetSystemMetrics(SM_CYSCREEN));                SetWindowPos(hWnd, 0, rectFullScreen.left, rectFullScreen.top,                    rectFullScreen.right-rectFullScreen.left, rectFullScreen.bottom-rectFullScreen.top,                    SWP_NOZORDER);                SHFullScreen(hWnd, SHFS_HIDETASKBAR|SHFS_HIDESIPBUTTON);            }            else            {                SHFullScreen(hWnd, SHFS_SHOWTASKBAR|SHFS_SHOWSTARTICON|SHFS_HIDESIPBUTTON);                RECT rectWorkArea;                SystemParametersInfo(SPI_GETWORKAREA, 0, (PVOID)&rectWorkArea, 0);                SetWindowPos(hWnd, 0, rectWorkArea.left, rectWorkArea.top,                    rectWorkArea.right-rectWorkArea.left, rectWorkArea.bottom-rectWorkArea.top,                    SWP_NOZORDER);            }

Note that the comments are all details. This kind of details has been encountered too much during the development of Windows Mobile. This is fine, and many others are not mentioned in the document at all.

(Sosopi full screen and non-full screen)

4. Why do I use textures for texture 4.1?

When developing a program, we are used to using controls, buttons, drop-down boxes, single boxes, check boxes, text boxes ...... But do you think these things are suitable for sosopi? How many widgets are needed on the sosopi homepage and how many are needed on other pages? In Windows programming, each control is actually a child window, and the resources of Windows Mobile are very limited, in its development documentation, we do not recommend placing a large number of subwindows in one window. Another important reason is that the use of controls is not conducive to interface customization, the implementation of many effects on the sosopi interface is significantly different from that of the existing controls, which is not helpful for my development.

4.2 DirectX?

Speaking of DirectX, I am a bit confused. It is too obscure, So we program in windows. If we need to accelerate graphics, we usually use the existing engine, I am not sure I will study the DirectX interface again. I know the difficulty of it because I have done it before. I don't know much about many professional graphics products and I can't make any achievements. At present, there are many other methods to do some simple animation effects, such as WPF, Silverlight, Flash, and even HTML5. In short, you don't need to touch the underlying layer on your own. Otherwise, you can write something that can work together, I will look back at the whole article of spam code.

Another key reason is: after a series of studies, I found that Windows Mobile does not support DirectX acceleration at all. Although interfaces are provided, calling may fail inexplicably, in addition, the Paster speed is not improved because of inconsistent behaviors on each mobile phone. My conclusion is that using DirectX will not improve the efficiency, but will increase the complexity of the Code.

4.3 bitmap and texture Efficiency

There are two types of bitmaps: DiB and DDB. Dib (Device Independent Bitmap) is device-independent bitmap, and DDB (Device Dependent Bitmap) is device-related bitmap. To put it simply, the bitmap displayed on different devices is Dib; otherwise, it is DDB. So is the common JPG file DiB or DDB? -- It must be dib. jpg can be used anywhere, right? What about BMP? Not yet? It can be used everywhere. What is DDB? DDB exists in the memory of your display device (well, it is commonly known as video memory). The reason why you can see your photo on the screen is that there is such an area in the video memory, the data format in this area is device-related. Different video cards, resolutions, and colors may lead to different formats, however, it is the most direct bitmap display method, and all Dib needs to be truly displayed and converted to DDB.

I spent a lot of time studying the texture efficiency. The research result turned out to be this: if you want to map quickly, you have to convert those images to the bitmap related to the display devices of Windows Mobile.

It is quite fast to draw a device-related bitmap to the window through bitblt. After debugging, I found that a full screen bitmap usually only needs 1-2 ms, so fast enough to achieve smooth animation effect!

The device-related bitmap of Windows Mobile uses two bytes (16 bit) to represent a point (commonly known as a 16-bit color). RGB occupies 5bit, 6bit, and 5bit, respectively, use 16-bit colors instead of 24-bit colors. Now the question is: What should I do if I want to paste a translucent image?

A translucent bitmap cannot be a DDB. As mentioned above, 16 bits are used to represent a point, and there is no translucent place in it? I have no good idea about this, so I try to make the translucent texture a little smaller during the design, which will reduce the workload. In general, translucent textures are much slower than DDB's bitblt. A full-screen translucent texture takes about ms, and 20-30 ms for faster machines.

After thoroughly studying these main problems, I wrote a demo program to demonstrate the sliding effect of the Bottom Bar similar to HTC Sense. Let's show it to Lao Wu. Lao Wu Lian's mouth is endless: "It's so amazing, it's even smoother than the official (HtC!" Old Wu's praise was rare. He was very excited at the time.

I have a blog about Paster-related technologies: http://www.cppblog.com/guogangj/archive/2010/06/20/118316.html.

4.4 program texture

I have omitted the specific process of image loading, and I am somewhat worried that this article will become attractive to readers because it has described too many details. The Paster method is a set of very mixed code. Why is it so mixed? It is not because I have used a lot of skills in the code to Improve the efficiency, it is difficult to clearly describe it in text, so I drew a picture to demonstrate how to switch from one module to another by pressing the slider in the slide area.

(Texture schematic)

1. When the finger presses the slider, a screen is taken and the screen content is stored in a cache bitmap. The cached bitmap is called "fastsurface", which is my name, it is a device-related bitmap that helps to cache the saved map. This action is quite fast, usually only 1-2 ms. Then draw a layer of translucent cover on the fastsurface. This action is a translucent texture with a slow execution speed. It takes about Ms on a slow mobile phone, but fortunately, this slider only needs to be moved once.

2. In order to keep the painting process from blinking, I created a device-related bitmap with the same size as the program window, called "backsurface ", all the things that finally need to be drawn to the screen are first drawn to the backsurface. Now, draw the bitmap on fastsurface with a translucent overlay to the corresponding position of the backsurface, this process is fast and also 1-2 ms.

3. I also created a device-related bitmap as the cache for the background and content on the taskbar in the Slider Area. Now, I have drawn them to the corresponding location of the backsurface, which is also very fast, 1 ms overhead.

4. Next, draw some elements to display on the upper layer to the backsurface, including the icons, slide blocks, icons and text in the Slider Area, these contents will change with the movement of users' fingers, so they cannot be cached and can only be drawn directly. Most of them are semi-transparent textures with a relatively large overhead, but because the images to be mapped are not too large, so it can usually be completed in about 30 ms.

5. Finally, paste the backsurface to the screen. The 1-2 ms elapsed time.

When the finger moves, it repeats the action between 2 and 5 to see the animation effect. On an old machine, it can reach more than 20 frames per second, which is already the limit. On a machine with good performance, it is quite smooth to use, such as Lao Wu's HTC hd2.

From this example,My basic idea is to reduce plotting! Cache the elements that do not need to be drawn every time to the device-related bitmap, and only draw the elements that must be drawn.

The actual painting process is more complex than I described above, and there are some details, such as cutting a graph. When drawing the icons in the sliding area, I will not list the details of the parts that exceed the boundary. In principle, this is basically the case of textures.

Maybe you have to ask: Let's see why those games on Windows Mobile can achieve that smooth performance? It is also 3D. -- Well, I really don't know how to answer this question. I have actually used HTC hd2 for the Windows Mobile edition, and the results are pretty good, but I really don't know how it was made, as we all know, Windows Mobile is a system that can be customized by device manufacturers. Many mobile phone manufacturers may have added hardware support for 3D rendering, making it possible to run these large games, you want to make sure that not all mobile phones can run these games.

Finally, I would also like to mention that the Code becomes somewhat difficult to maintain because the program uses a lot of the "skills" mentioned above, if someone else maintains this code (of course this possibility is 0, here is only an academic "if"), he needs to take a good look at this article and understand my intention, in programming, the more this skill is used, the worse the quality of the code, but there is no way to do it.

4.5 image rotation

It is not difficult to use Windows GDI, GDI +, or WPF to rotate an image. However, Windows Mobile does not support image rotation. When I need to draw a simulated clock and want to use the texture method to draw the time-minute second needle, this is really a problem. I have tried many methods, the simplest way is to use the line drawing method instead of Bitmap rotation, but the effect is not good, and this is not conducive to personalization, finally, I found a method to use quadratic linear interpolation to rotate bitmap. The code is less complex. The rotation is as follows:

(Image rotation effect)

We can clearly see that the size of the rotated image has changed, and the image itself will be "out of shape". This is obvious. So, how can we draw a simulated clock? -- The central axis of the needle must be determined, so we stipulate that the needle axis should be placed at the central point during plotting! In this way, no matter how the axis is rotated, the needle axis is still at the center ...... So, is there a problem? Ladies and gentlemen.

(Clock needle)

Problem! For example, if you create a 5*5 graph, the center point is obviously () and can be rotated. This graph may become 6*6, the central point is ...... Therefore, the simulated clock drawn by using this rotating image method is a bit flawed. After countless experiments and corrections, I cannot draw a perfect clock, I think this problem is "unsolved ". In fact, there is no solution. The artist of the company took a product from someone else and showed it to me. This is a product of a foreign company. The Simulation Clock drawn out is really exquisite, in addition, the timing and seconds are very perfect. I don't know how they are implemented. Maybe they have drawn 15 time and second pasters respectively. (horizontal/vertical flip images won't go out of shape, so we only need 15 images, not 60) instead of rotating images, I guess.

Finally, sosopi does not provide the analog clock rendering function, because the bitmap rotation method I wrote for quadratic linear interpolation is too slow (in fact, I have tried my best to optimize it ), the rotation of a slightly larger image takes several hundred milliseconds and consumes much time. Therefore, the image is finally removed.

(To be continued ...)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.