码迷,mamicode.com
首页 > Windows程序 > 详细

拿下Win32非模态对话框

时间:2021-02-01 12:52:36      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:button   ddl   windows   color   false   指定   lse   cmd   com   

1、点击不同按钮分别创建出模态与非模态对话框子窗口,分别指定每个窗口单独的对话框窗口函数。

#include <Windows.h>
#include <tchar.h>
#include <CommCtrl.h>
#include "resource.h"
INT_PTR WINAPI DialogFuncModal(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
    case WM_COMMAND:
    {
        UINT ControlID = LOWORD(wParam);
        UINT ControlCode = HIWORD(wParam);
        if (ControlCode == BN_CLICKED)
        {
            if (ControlID == IDCANCEL)
            {
                int iRet = MessageBox(hWndDlg, _T("是否关闭对话框"), _T("标题"), MB_OKCANCEL);
                if (iRet == IDOK)
                {
                    EndDialog(hWndDlg, 0);
                }
            }
        }
    }
        break;
    default:
        break;
    }
    return FALSE;
}
INT_PTR WINAPI DialogFuncUnmodal(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
    case WM_COMMAND:
    {
        UINT ControlID = LOWORD(wParam);
        UINT ControlCode = HIWORD(wParam);
        if (ControlCode == BN_CLICKED)
        {
            if (ControlID == IDCANCEL)
            {
                int iRet = MessageBox(hWndDlg, _T("是否关闭对话框"), _T("标题"), MB_OKCANCEL);
                if (iRet == IDOK)
                {
                    DestroyWindow(hWndDlg);
                }
            }
        }
    }
    break;
    default:
        break;
    }
    return FALSE;
}
INT_PTR WINAPI DialogFunc(HWND hWndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
    switch (uMsg)
    {
    case WM_INITDIALOG:
        //MessageBox(hWndDlg, _T("AA"), _T("A"), NULL);
        break;
    case WM_COMMAND:
    {
        UINT ControlID = LOWORD(wParam);
        UINT ControlCode = HIWORD(wParam);
        if (ControlCode == BN_CLICKED)
        {
            if (ControlID == IDC_BUTTON1)
            {
                DialogBox(NULL, MAKEINTRESOURCE(IDD_DIALOG2), hWndDlg, DialogFuncModal);
            }
            if (ControlID == IDC_BUTTON2)
            {
                HWND hWndUnmodal = CreateDialog(NULL, MAKEINTRESOURCE(IDD_DIALOG2), hWndDlg, DialogFuncUnmodal);
                ShowWindow(hWndUnmodal,SW_SHOW);
            }
            if (ControlID == IDCANCEL)
            {
                int iRet = MessageBox(hWndDlg, _T("是否关闭对话框"), _T("标题"), MB_OKCANCEL);
                if (iRet == IDOK)
                {
                    DestroyWindow(hWndDlg);
                    PostQuitMessage(1);
                }
            }
        }
    }
        break;
    default:
        break;
    }
    return FALSE;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow)
{
    HWND hWndDlg = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DialogFunc);
    ShowWindow(hWndDlg, SW_SHOW);
    MSG msg = { 0 };
    while (GetMessage(&msg,NULL,0,0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return 0;
}

 

拿下Win32非模态对话框

标签:button   ddl   windows   color   false   指定   lse   cmd   com   

原文地址:https://www.cnblogs.com/SakuraQAQ/p/14352905.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!