Creating dialogbased Win32 Application (2)/Create a dialog-based WIN32 application (ii) button application, new subform/Win32, VC + +, Windows

Source: Internet
Author: User

Create a dialog-based WIN32 application (ii)--button app, New Subform

You can find the form created in the previous section, click OK and cancel two buttons without any reaction. Now let's add the ability to exit the dialog box for them.

6. First define the macro replacement as follows:

7. The function (Dlg_oncommand) that invokes the response message in the callback function (DLG_PROC) is as follows:

8, because Handle_wm_command is defined in the Windowsx.h header file, add its reference.

9. Next, define the message response function (Dlg_oncommand) that you just called, as follows:

Where Idok and Idcancel are the corresponding identifiers for button OK and cancel respectively.

10. Press F5 Start Debugging, then click OK or Cancel button to see the new dialog will be closed.

Here we show how to create a new subform.

11, first in Solution Explorer or Resources View right-click Add Resource, select dialog. and find the new dialog in the resources View, right-propertise modify the relevant content.

12. Click and press DELETE to delete the useless OK and Cancel buttons in the new sub-dialog box. Remember to delete or comment out the associated code for the deleted control when the Reasource.h or. cpp file exists.

13. Open Toolbox (ctrl+alt+x) in view, add the static test control to the new subform, modify the contents of the control, and adjust both 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 message response function (Dlg_oncommand), call Dialogboxparam in the Idnew case, and write the callback function (NEWDLG_PROC) of the Child dialog 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 don't work properly for dialog7 //boxes because Dlgproc returns a BOOL instead of an LRESULT ( like8 //Wndprocs). This chhandle_dlgmsg macro corrects the problem:9 #defineChhandle_dlgmsg (hWnd, message, FN)Ten     Case(message):return(Setdlgmsgresult (hWnd, umsg, One handle_# #message (hWnd), (WParam), (LParam), (FN) ))) A  - int_ptr WINAPI Newdlg_proc (HWND hwnd, UINT umsg, WPARAM WPARAM, LPARAM LPARAM) { -     Switch(umsg) the     { -      CaseWm_close: -EndDialog (HWnd,0); -          Break; +     } -  +     return(FALSE); A } at  - voidDlg_oncommand (HWND hwnd,intID, HWND hwndctl, UINT codenotify) { -  -     Switch(ID) { -      Caseidnew: - Dialogboxparam (NULL, Makeintresource (idd_newdialog), in hWnd, Newdlg_proc, NULL); -          Break; to      CaseIDCANCEL: +SendMessage (HWnd, Wm_close,0,0); -          Break; the  *     } $ }Panax Notoginseng  - int_ptr WINAPI Dlg_proc (HWND hwnd, UINT umsg, WPARAM WPARAM, LPARAM LPARAM) { the     Switch(umsg) +     { A chhandle_dlgmsg (hWnd, WM_COMMAND, Dlg_oncommand); the      CaseWm_close: +EndDialog (HWnd,0); -          Break; $     } $  -     return(FALSE); - } the  - intWINAPI WinMain (hinstance hinstexe, hinstance, Ptstr Pszcmdline,int) {Wuyi Dialogboxparam (Hinstexe, Makeintresource (idd_dialog), the NULL, Dlg_proc, _ttoi (Pszcmdline)); -     return(0); Wu}
Win32WindowsApplication.cpp

16. Press F5 Start Debugging, then click the New button to see the New sub-dialog box that you just created.

————————————————

This article for my original, reproduced please indicate the source.

Creating dialogbased Win32 Application (2)/Create a dialog-based WIN32 application (ii) button application, new subform/Win32, VC + +, Windows

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.