SDK callback function to switch between the pages bis

#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <stdio.h>
#include "resource.h"
INT_PTR CALLBACK DialogProc(HWND hwndDlog, UINT uMsg, WPARAM wParam, LPARAM lparam)
{//消息回调函数
    switch (uMsg)
    {
    case WM_COMMAND:
        if (LOWORD(wParam) == IDOK)
        {
            float left1 = GetDlgItemInt(hwndDlog, IDC_LEFT1);
            float right1 = GetDlgItemInt(hwndDlog, IDC_RIGHT1);
            SetDlgItemInt(hwndDlog, IDC_RESULT1, left1 + right1);
        }if (LOWORD(wParam) == IDCANCEL)
        {
            EndDialog(hwndDlog, IDCANCEL); 
        }
        break;
    }
    return 0;
}
INT_PTR CALLBACK DialogProc1(HWND hwndDlog, UINT uMsg, WPARAM wParam, LPARAM lparam)
{
    switch (uMsg)
    {
    case WM_COMMAND:
        if (LOWORD(wParam) == IDOK)
        {
            EndDialog(hwndDlog, IDCANCEL);
            DialogBox(NULL, (LPCTSTR)IDD_D, NULL, DialogProc);
        }
        if (LOWORD(wParam) == IDCANCEL)
        {
            EndDialog(hwndDlog, IDCANCEL);
        }
        break;
    }
    return FALSE;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    DialogBox(hInstance, (LPCSTR)IDD_DIALOG1, NULL, DialogProc1);
    
    return 0;
}

 In this code, I have two pre-built dialog controls, their ID were ID_D (this is the second page), IDD_DIALOG1 (first page, login page);

When we want to use the first page calls the second page, we need to think about only after first page that appears and click on the first page of the buttons above to make the second page pop up;

Then how does he achieve?

We want to trigger the binding ID above this event in a first page, that is: When you click this button, a second pop will pop up, so there is a callback function;

 

INT_PTR CALLBACK DialogProc1(HWND hwndDlog, UINT uMsg, WPARAM wParam, LPARAM lparam)
{
    switch (uMsg)
    {
    case WM_COMMAND:
        if (LOWORD(wParam) == IDOK)
        {
       DialogBox(NULL, (LPCTSTR)IDD_D, NULL, DialogProc);
EndDialog(hwndDlog, IDCANCEL); }
if (LOWORD(wParam) == IDCANCEL) { EndDialog(hwndDlog, IDCANCEL); } break; } return FALSE; }

 

This is what we naturally think of, bring up a second dialog box to destroy the first, but when we run will find doing so, the first dialog box will not end with the second the emergence of destruction;

Only in the second dialog box click on the button of the destruction, the first one was destroyed along with the dialog box a second;

Let's change the code

 case WM_COMMAND:
        if (LOWORD(wParam) == IDOK)
        {
       EndDialog (hwndDlog, IDCANCEL); 

       DialogBox (NULL, (LPCTSTR) IDD_D, NULL, DialogProc);
            
        }

Then we found that in the second pop-up, the first one also will be destroyed;

How is this going?

This is because when running to     

DialogBox (NULL, (LPCTSTR) IDD_D, NULL, DialogProc);

    When the code will stay here, waiting for news of the implementation of the second dialog box, so   

EndDialog (hwndDlog, IDCANCEL);

   Unreachable, when we change the order of two, it will become a second dialog box after the destruction;



Guess you like

Origin www.cnblogs.com/jianmoxiansheng-Guo/p/11961661.html