Windows SDK notes (6): create a window using the resources in the dialog box

Source: Internet
Author: User
I. Overview
In Charles Petzold's book, we introduced a method for directly using dialog box resources to create the main window.
Using this method, you can easily arrange child controls in the main window, while other parts of the Code are the same as when using a normal window.

As we know, the dialog box is a pre-defined "window class", which has its own window processing function. The message processing function of the Self-written dialog box is not a real window message processing function.
However, in the dialog box template script, you can specify the dialog box to use the window class defined by ourselves, instead of the system dialog box class. In this way, the message processing function in the dialog box is "grafted" into our own message processing function.

2. Write a "real" window message processing function
Follow the normal window to write the good message processing function.
(Do not miss defwindowproc)

Iii. Registration window
Register a window class with the written message processing function.

4. Create a dialog box resource and specify the window class as the custom window class.
Manually write a dialog box resource, save it as a separate file, and include it in the resource file.
(In the menu view-> resource endpoints dialog box that appears, enter the file name in the compile-time derective column. This will add a line in the RC file: "# include" "Some. DLG """)
Example:
Create a file some. DLG
Writing:

Hexc1c dialog-1,-1,102,122 style ws_overlapped | ws_caption | ws_sysmenu | ws_minimizeboxclass "hexc1c" // enter your registered class name caption "hex calculator" {Pushbutton "D", 68, 8, 24, 14, 14 Pushbutton "A", 65, 8, 40, 14, 14 // various controls}

5. Create the main window using the non-mode dialog box
Use createdialog when creating the main window.

Hwnd = createdialog (hinstance, szappname, // dialog box template 0, null); showwindow (hwnd, icmdshow );

All other parts are the same as common Windows (registration window class, message loop, etc ).

Ii. Create a custom subwindow in the dialog box

You can customize controls and then use them in the dialog box template.

1. Define "window class" and message processing functions
In winmain
Besides registering the main window class,
In addition, register the class used for the dialog box and specify the message processing function corresponding to the class.

Wndclass. style = cs_hredraw | cs_vredraw; wndclass. lpfnwndproc = somewndproc; // corresponding message processing function 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 ("somecontrol"); registerclass (& wndclass );

At the same time, it also needs to write the good message processing function somewndproc.

2. Add a custom control window in the dialog box template
In the dialog box template, add "custom control", set properties, and enter your own defined class name somecontrol.

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.