Non-modal dialog box in Windows Programming

Source: Internet
Author: User
Tags case statement
# Include <windows. h> lresult callback wndproc (hwnd, uint, wparam, lparam); bool callback colorscrdlg (hwnd, uint, wparam, lparam); hwnd hdlgmodeless; int winapi winmain (hinstance, hinstance hprevinstance, pstr szcmdline, int icmdshow) {static tchar szappname [] = text ("color2"); MSG; hwnd; wndclass. style = cs_vredraw | cs_hredraw; wndclass. lpfnwndproc = wndproc; wndclass. cbclsextra = 0; wndcia SS. cbwndextra = 0; wndclass. hbrbackground = createsolidbrush (0l); wndclass. hinstance = hinstance; wndclass. hicon = loadicon (null, idi_application); wndclass. hcursor = loadcursor (null, idc_arrow); wndclass. lpszmenuname = NULL; wndclass. lpszclassname = szappname; If (! Registerclass (& wndclass) {MessageBox (null, text ("this program requires Windows NT! "), Szappname, mb_iconerror); Return 0;} // ws_clipchildren indicates that the repaster window hwnd = createwindow (szappname, text (" color scroll ") does not erase the dialog box "), required | ws_clipchildren, cw_usedefault, null, null, hinstance, null); showwindow (hwnd, icmdshow); updatewindow (hwnd); hdlgmodeless = createdi( alog hinstance, text ("colorscrdlg"), hwnd, colorscrdlg); While (getmessage (& MSG, null,) {// determine this location Whether the message breaking cycle is the IF (hdlgmodeless = 0 |! Isdialogmessage (hdlgmodeless, & MSG) {translatemessage (& MSG); dispatchmessage (& MSG) ;}} return MSG. wparam;} lresult callback wndproc (hwnd, uint message, wparam, lparam) {Switch (Message) {Case wm_destroy: // change the background brush of the class before closing, and delete the newly created deleteobject (hgdiobj) setclasslong (hwnd, gcl_hbrbackground, (long) getstockobject (white_brush ))); postquitmessage (0); Return 0;} return defwindowproc (hwnd, message, wparam, lparam);} bool callback colorscrdlg (hwnd hdlg, uint message, wparam, lparam) {static int icolor [3]; hwnd hwndparent, hctrl; int ictrlid, iindex; Switch (Message) {Case wm_initdialog: For (ictrlid = 10; ictrlid <13; ictrlid ++) {// The ictrlid corresponds to the resource. // obtain the handle hctrl = getdlgitem (hdlg, ictrlid); // set the range setscrollrange (hctrl, sb_ctl, 0,255, false ); // set the starting point setscrollpos (hctrl, sb_ctl, 0, false);} return true; Case wm_vscroll: // What lparam passes in is the handle hctrl = (hwnd) lparam; // get the ID, hctrl here is the window on the three scroll bars ictrlid = getwindowlong (hctrl, gwl_id); iindex = iCtrlID-10; // hwndparent is the window handle that shows color changes hwndparent = getparent (hdlg); // wparam low is control switch (loword (wparam )) {// if there is no break after this case statement, the sb_linedown will be triggered to move 1 down. // you can determine whether the result is the lowest case sb_pagedown: icolor [iindex] + = 15; // click the case sb_linedown button on the scroll bar: icolor [iindex] = min (255, icolor [iindex] + 1); break; Case sb_pageup: icolor [iindex]-= 15; Case sb_lineup: icolor [iindex] = max (0, icolor [iindex]-1); break; Case sb_top: icolor [iindex] = 0; break; Case sb_bottom: icolor [iindex] = 255; break; Case sb_thumbposition: Case sb_thumbtrack: // icolor [iindex] = hiword (wparam); break; default: Return false;} setscrollpos (hctrl, sb_ctl, icolor [iindex], true); // set the number setdlgitemint (hdlg, ictrlid + 3, icolor [iindex], false); // Replace the class-related background brush, delete the returned brush handle deleteobject (hgdiobj) setclasslong (hwndparent, gcl_hbrbackground, (long) createsolidbrush (RGB (icolor [0], icolor [1], icolor [2]); // re-paint invalidaterect (hwndparent, null, true); Return true ;} return false ;}

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.