Windows Programming subwindow

Source: Internet
Author: User
Lresult callback wndproc (hwnd, uint message, wparam, lparam) {static colorref crprim [3] = {RGB (0,255, 0), RGB (, 0 ), RGB (255,)}; static hbrush [3], hbrushstatic; static hwnd hwndscroll [3], hwndlabel [3], hwndvalue [3], hwndrect; static int color [3], cychar; static rect rccolor; static tchar * szcolorlabel [] = {text ("red"), text ("green "), text ("blue")}; hinstance; int I, cxclient, cyclie NT; tchar szbuffer [10]; Switch (Message) {Case wm_create: // obtain handle hinstance = (hinstance) getwindowlong (hwnd, gwl_hinstance ); // create a static rectangle hwndrect = createwindow (text ("static"), null, ws_child | ws_visible | ss_whiterect, 0,0, 0,0, hwnd, (hmenu) 9, hinstance, null); // create three scroll bar controls for (I = 0; I <3; I ++) {// create, pay attention to ws_tabtop. After adding this, you can use the tab; sbs_vert is a vertical scroll hwndscroll [I] = createwindow (text ("scrollbar"), null, ws_child | ws_visible | ws_tabstop | sbs_vert, 0, 0, 0, hwnd, (hmenu) I, hinstance, null); // set the range of the scroll bar control. False indicates that setscrollrange (hwndscroll [I], sb_ctl, 0,255, false); // set the initial position setscrollpos (hwndscroll [I], sb_ctl, 0, false); // create a static text box above the scroll bar and set (hmenu) to a unique ID, hwndlabel [I] = createwindow (text ("static"), szcolorlabel [I], ws_child | ws_visible | ss_center, hwnd, (hmenu) (I + 3), hinstance, null); // create hwndvalue [I] = createwindow (text ("static "), text ("0"), WS _ Child | ws_visible | ss_center, hwnd, (hmenu) (I + 6), hinstance, null); // The callback function is called. // gwl_wndproc: obtain the address of the window process or the handle representing the address of the window process. You must use the callwindowproc function to call the window process. // For the moment, it is unclear what oldscroll [I] = (wndproc) setwindowlong (hwndscroll [I], gwl_wndproc, (long) scrollproc) is used to set the return value ); // create three logic brushes with the specified color hbrush [I] = createsolidbrush (crprim [I]);} hbrushstatic = createsolidbrush (getsyscolor (color_btnhighlight )); // cychar = hiword (getdialogbaseunits (); Return 0; Case wm_size: // cxclient = loword (lparam); cyclient = hiword (lparam ); // set the rectangle content. Here is the setrect (& rccolor, cxclient/, cxclient, cyclient ); // Set the size and position of the area of the nine sub-windows on the left movewindow (hwndrect, cxclient/2, cyclient, true); // set the size, location for (I = 0; I <3; I ++) {movewindow (hwndscroll [I], (2 * I + 1) * cxclient/14,2 * cychar, cxclient/14, cyClient-4 * cychar, true); movewindow (hwndlabel [I], (4 * I + 1) * cxclient/28, cychar/2, cxclient/7, cychar, true); movewindow (hwndvalue [I], (4 * I + 1) * cxclient/28, cyClient-3 * cychar/2, cxclient/7, cychar, true );} // set the focus to the parent window setfocus (hwnd); Return 0; Case WM _ Setfocus: // set focus setfocus (hwndscroll [idfocus]); Return 0; Case wm_vscroll: // get Idi = getwindowlong (hwnd) lparam, gwl_id ); // determine the key switch (loword (wparam) {// omitted some} // set the position setscrollpos (hwndscroll [I], sb_ctl, color [I], true ); wsprintf (szbuffer, text ("% I"), color [I]); // set the number setwindowtext (hwndvalue [I], szbuffer) below the scroll bar; // gcl_hbrbackground: replace the handle of the class-related background brush. Deleteobject (hbrush) setclasslong (hwnd, gcl_hbrbackground, (long) createsolidbrush (RGB (color [0], color [1], color [2]); // re-painting area. True indicates that the background invalidaterect (hwnd, & rccolor, true) is cleared before re-painting; return 0; // when a small window needs to be re-painted, return the corresponding brush case wm_ctlcolorscrollbar: I = getwindowlong (hwnd) lparam, gwl_id); Return (lresult) hbrush [I]; // when the static text is repainted, return the corresponding brush case wm_ctlcolorstatic: I = getwindowlong (hwnd) lparam, gwl_id); if (I> = 3 & I <= 8) {settextcolor (HDC) WP Aram, crprim [I % 3]); setbkcolor (HDC) wparam, getsyscolor (color_btnhighlight); Return (lresult) hbrushstatic;} break; // when the system color is changed, recreate hbrushstaticcase wm_syscolorchange: deleteobject (hbrushstatic); hbrushstatic = createsolidbrush (getsyscolor (batch); Return 0; // some cases of cleanup wm_destroy: deleteobject (hbrush) setclasslong (hwnd, gcl_hbrbackground, (long) getstockobject (white_brush); for (I = 0; I <3; I ++) deleteob Ject (hbrush [I]); deleteobject (hbrushstatic); postquitmessage (0); Return 0;} return defwindowproc (hwnd, message, wparam, lparam );} lresult callback scrollproc (hwnd, uint message, wparam, lparam) {int id = getwindowlong (hwnd, gwl_id); Switch (Message) {// key operation case wm_keydown: // implement the tab function if (wparam = vk_tab) setfocus (getdlgitem (getparent (hwnd), (ID + (getkeystate (vk_shift) <0? 2:1) % 3); break; Case wm_setfocus: idfocus = ID; break;} return callwindowproc (oldscroll [ID], hwnd, message, wparam, lparam );}

There are many things worth learning, including the use of scroll bar controls, transmission of Button messages and messages in the parent window, acquisition of IDS, setting of Button colors, and overall layout.

CodeIt is part of colors1. When I leave, I will go back to the dormitory. Otherwise, I will be shut out.

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.