Windows Program Design dialog box 3

Source: Internet
Author: User
Tags case statement drawtext
# Include <windows. h> # include "resource. H "lresult callback wndproc (hwnd, uint, wparam, lparam); bool callback aboutdlgproc (hwnd, uint, wparam, lparam); lresult callback (hwnd, uint, wparam, lparam); int winapi winmain (hinstance, hinstance hprevinstance, pstr szcmdline, int icmdshow) {static tchar szappname [] = text ("about3"); MSG; hwnd; wndclass; wndclass. style = cs_hredraw | cs_vr Edraw; wndclass. lpfnwndproc = wndproc; wndclass. cbclsextra = 0; wndclass. cbwndextra = 0; wndclass. hinstance = hinstance; wndclass. hicon = loadicon (hinstance, szappname); wndclass. hcursor = loadcursor (null, idc_arrow); wndclass. hbrbackground = (hbrush) getstockobject (white_brush); wndclass. lpszclassname = szappname; wndclass. lpszmenuname = szappname; If (! Registerclass (& wndclass) {MessageBox (null, text ("this program requires Windows NT! "), Szappname, mb_iconerror); Return 0;} wndclass. style = cs_vredraw | cs_hredraw; wndclass. lpfnwndproc = ellippushwndproc; wndclass. cbclsextra = 0; wndclass. cbwndextra = 0; wndclass. hinstance = hinstance; wndclass. hicon = NULL; wndclass. hcursor = loadcursor (null, idc_arrow); wndclass. hbrbackground = (hbrush) (color_btnface + 1); wndclass. lpszmenuname = NULL; wndclass. lpszclassname = text ("ellippush"); // register the ellippush class in winmain and specify the callback function as E. Struct (& wndclass); hwnd = createwindow (szappname, text ("about box demo program"), ws_overlappedwindow, cw_usedefault, null, null, hinstance, null); showwindow (hwnd, icmdshow); updatewindow (hwnd); While (getmessage (& MSG, null, 0, 0) {translatemessage (& MSG ); dispatchmessage (& MSG);} return MSG. wparam;} lresult callback wndproc (hwnd, uint message, wparam W Param, lparam) {static hinstance; Switch (Message) {Case wm_create: hinstance = (lpcreatestruct) lparam)-> hinstance; return 0; Case wm_command: switch (loword (wparam) {Case idm_app_about: dialogbox (hinstance, text ("aboutbox"), hwnd, aboutdlgproc); Return 0;} break; Case wm_destroy: postquitmessage (0); Return 0;} return defwindowproc (hwnd, message, wparam, lparam);} bool callback aboutdlgproc (hwnd hdlg, uint Message, wparam, lparam) {Switch (Message) {Case wm_initdialog: Return true; Case wm_command: Switch (loword (wparam) {Case idok: enddialog (hdlg, 0); Return true;} break;} return false;} lresult callback ellippushwndproc (hwnd, uint message, wparam, lparam) {tchar sztext [40]; hbrush; HDC; paintstruct pS; rect; Switch (Message) {Case wm_paint: // the size of this rect is only for the getclient of the small OK Control Rect (hwnd, & rect); // obtain the text, and draw getwindowtext (hwnd, sztext, sizeof (sztext) with drawtext; HDC = beginpaint (hwnd, & PS ); // create the paint brush hbrush = createsolidbrush (getsyscolor (color_window); // select the device description table hbrush = (hbrush) SelectObject (HDC, hbrush); // set the color setbkcolor (HDC, HDC, getsyscolor (color_window); settextcolor (HDC, getsyscolor (color_windowtext); // Draw Ellipse (HDC, rect. left, rect. top, rect. right, rect. bottom); // write drawtext (HDC, sztext,-1, & rect, DT _ Singleline | dt_center | dt_vcenter); deleteobject (SelectObject (HDC, hbrush); endpaint (hwnd, & PS); Return 0; // The following case statement does not return 0, run the following command to trigger sendmessagecase wm_keyup: If (wparam! = Vk_space) break; Case wm_lbuttonup: // send a message to the upper window to trigger the idok under wm_command. The last parameter does not feel useful. I do not know why to pass this sendmessage (getparent (hwnd ), wm_command, getwindowlong (hwnd, gwl_id), (lparam) hwnd); Return 0;} return defwindowproc (hwnd, message, wparam, lparam );} //////////////////////////////////////// /// // custom is used in the Resource control, the code I wrote directly copies the resource files in the original program. //////////////////////////////////////// ////////////////////////////////

I went to drink with my teacher at noon, went to bed in the afternoon, and took the Mandarin test at night. Fortunately, I have finished writing it today.

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.