Creating Dialogbased Win32 Application (2)/create a dialog box-based Win32 Application (2) Button Application, create a subform/Win32, VC ++, Windows, easyuidialogbutton

Source: Internet
Author: User

Creating Dialogbased Win32 Application (2)/create a dialog box-based Win32 Application (2) Button Application, create a subform/Win32, VC ++, Windows, easyuidialogbutton

Create a dialog box-based Win32 application (2) -- A Button application and a new subform

 

You can see that in the form created in the previous section, clicking OK and Cancel does not respond. Now let's add the exit dialog box function for them.

6. First, define the Command Message response function (Dlg_OnCommand) as follows:

 

The IDOK and IDCANCEL are the identifiers corresponding to the buttons "OK" and "Cancel" respectively.

7. Next, define macro replacement as follows:

 

8. In the callback function (Dlg_Proc), replace the Call Command Message response function (Dlg_OnCommand) with a macro as follows:

 

9. Because HANDLE_WM_COMMAND is defined in the header file of windowsx. h, It is referenced.

 

10. Press F5 Start Debugging and then click OK or Cancel. The new dialog box is closed.

 

The following shows how to create a subform.

11. Right-click Solution Explorer or Resources View to Add Resource and select Dialog. In the Resources View, find the new Dialog and right-click Propertise to modify the relevant content.

 

 

12. Click and press Delete to Delete the useless OK and Cancel buttons in the create subdialog box. When the code of the deleted control exists in the. h/. rc/. cpp file, delete or comment out the code.

 

13. Open Toolbox (Ctrl + Alt + X) in the View, add the Static Test control to the new subform, modify the control content, and adjust the control content to the appropriate size.

 

14. Find the Button in the previous Dialog and modify its Propertise.

 

15. Switch to the. cpp file, modify the called Command Message response function (Dlg_OnCommand), call DialogBoxParam in the idnew case, and write the callback function (NewDlg_Proc) in the subdialog box ).

 

1 # include <Windows. h> 2 # include <windowsx. h> 3 # include <tchar. h> 4 # include "Resource. h "5 6 // The normal HANDLE_MSG macro in WindowsX. h does not work properly for dialog 7 // boxes because DlgProc returns a BOOL instead of an LRESULT (like 8 // WndProcs ). this chHANDLE_DLGMSG macro corrects the problem: 9 # define chHANDLE_DLGMSG (hWnd, message, fn) \ 10 case (message): return (SetDlgMsgResult (hWnd, uMsg, \ 11 HANDLE _ # message (hWnd), (wParam), (lParam), (fn) 12 13 INT_PTR WINAPI NewDlg_Proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {14 switch (uMsg) 15 {16 case WM_CLOSE: 17 EndDialog (hWnd, 0); 18 break; 19} 20 21 return (FALSE ); 22} 23 24 void Dlg_OnCommand (HWND hWnd, int id, HWND hWndCtl, UINT codenostrap) {25 26 switch (id) {27 case IDNEW: 28 DialogBoxParam (NULL, MAKEINTRESOURCE (IDD_NEWDIALOG), 29 hWnd, NewDlg_Proc, NULL); 30 break; 31 case IDCANCEL: 32 SendMessage (hWnd, WM_CLOSE, 0, 0); 33 break; 34 35} 36} 37 38 INT_PTR WINAPI Dlg_Proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {39 switch (uMsg) 40 {41 chHANDLE_DLGMSG (hWnd, WM_COMMAND, dlg_OnCommand); 42 case WM_CLOSE: 43 EndDialog (hWnd, 0); 44 break; 45} 46 47 return (FALSE); 48} 49 50 int WINAPI WinMain (HINSTANCE hinstExe, HINSTANCE, PTSTR psz1_line, int) {51 DialogBoxParam (hinstExe, MAKEINTRESOURCE (IDD_DIALOG), 52 NULL, Dlg_Proc, _ ttoi (psz1_line); 53 return (0); 54}Win32WindowsApplication. cpp

16. Press F5 Start Debugging and then click the New button. The newly created subdialog box is displayed.

 

----------------

This article is original. For more information, see the source.

Related Article

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.