Create your own menubar on PPC and smartphone

Source: Internet
Author: User

In fact, this is what I always want to do. I want to write a menubar control with the abstract layer of graphics, with menubar, this control can work on both Symbian and Windows Mobile.

 

The first thing to do with this control is to remove the system menubar!

There is still a problem with PPC. of course, it is relatively simple to not display this bar, as long as you do not call shcreatemenu to instantiate it. however, this input method still jumps out from time to time. in the previous window, if the SIP is enabled, this sip is always displayed suddenly when I switch to my program. the interfaces related to the SIP are not used. Later, the hide sip window is directly sent when the main window receives a wm_active message, as shown in the following code:

Case wm_activate: <br/> // your y shell of our activate message <br/> showwindow (findwindow (_ T ("ms_sipbutton"), 0), sw_hide ); <br/> break;

There is another difference on smartphone. at the beginning, we saw two menubar, one self-painted, and the other default. to remove this, you need the help of movewindow: after creating the main window in createwindow, you can move it:

Hwnd = createwindow (szwindowclass, sztitle, ws_visible, <br/> cw_usedefault, <br/> cw_usedefault, null, null, hinstance, null ); <br/> If (hwnd = NULL) // createwindow failed. <br/>{< br/> rc = MessageBox (null, _ T ("cocould not create main window. "), _ T (" error "), mb_ OK); <br/> return e_fail; // Replace with specific error handling. <br/>}< br/> getwindowrect (hwnd, & rect); <br/> chgscreen = shfullscreen (hwnd, shfs_hidesipbutton); <br/> tchar szplatform [30]; <br/> systemparametersinfo (spi_getplatformtype, sizeof (szplatform), szplatform, 0); <br/> If (_ tcscmp (szplatform, _ T ("Smartphone ")) = 0) <br/> movewindow (hwnd, rect. left, rect. top, rect. right, rect. bottom, true); <br/> showwindow (hwnd, ncmdshow); <br/> updatewindow (hwnd );
Note that the current platform is also dynamically obtained here. If it is smartphone, it will move, otherwise it will not move. Otherwise, your menubar will be painted out of the screen.

 

The second step is to process the key message. specifically, soft1 and soft2. that is, vk_f1 and vk_f2 cannot receive messages such as key_down by default. what you can get is key_up. what should we do? Regiesterhotkey.

Typedef bool (_ stdcall * unregisterfunc1proc) (uint, uint); <br/> hinstance hcoredll; <br/> unregisterfunc1proc procundergisterfunc; <br/> hcoredll = loadlibrary (_ T ("coredll. DLL "); <br/> procundergisterfunc = (unregisterfunc1proc) getprocaddress (hcoredll, _ T (" unregisterfunc1 "); <br/> If (procundergisterfunc! = NULL) <br/>{< br/> procundergisterfunc (null, vk_f1); <br/> procundergisterfunc (null, vk_f2 ); <br/>}< br/> freelibrary (hcoredll); <br/> registerhotkey (hwnd, 0, null, vk_f1); <br/> registerhotkey (hwnd, 1, null, vk_f2 );

The hotkey is registered here when the wm_create message is sent. then the wm_hotkey message is sent when the two buttons are pressed. at that time, wparam was your current 0, 1. in this way, you can press the button.

 

The third step is to draw.

To plot the menubar feeling of a system, I made some effort: divide the bar with a height of 26 into two halves. the upper part is drawn using gradientfill. (The parameter of this function is very disgusting ). the red and green colors are 16 bits. in other words, do not forget to shift the left eight bits after obtaining the corresponding RGB color of your colorref (<8 )!!!!

Typedef struct _ trivertex <br/>{< br/> long X; <br/> long y; <br/> color16 red; <br/> color16 green; <br/> color16 blue; <br/> color16 Alpha; </P> <p>} trivertex, * ptrivertex, * lptrivertex;

The second half is fillrect. finally, we can draw the corresponding text transparently. after this menuitem is selected, this method is different. the color of the text must be changed. or the gradientfill direction should also be changed. all in all, it's really not easy to think about it all at once! There is one later. Yellow is the activated menuitem. You can see that you are proud of it.

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.