| |

VerySource

 Forgot password?
 Register
Search
View: 1083|Reply: 8

How to create a dialog box under Win32 program?

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-5 20:30:01
| Show all posts |Read mode
I need to add a dialog box under the Win32 program.
I first created a dialog resource and then generated a class using ClassWizard. However, there is always a problem that "stdafx.h" does not exist when compiling! !! !! !! !! !! !! !!
I would like to ask everyone, how to add a dialog box in Win32 program?

Waiting online ...
Reply

Use magic Report

0

Threads

17

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-3-24 10:45:01
| Show all posts
Create a WIN32 program, complete
After clicking about, there will be a dialog box
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-4-7 17:30:01
| Show all posts
1 Add dialog resources
2 Call the DialogBox function in the WinMain function
3 Define the message processing function of the dialog box, the format refers to MSDN
4 Message mapping

<< Windows Core Programming >> has specific examples in the book

INT_PTR CALLBACK MyDlgProc (HWND hwndDlg,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam
); // Window function prototype declaration

BOOL Dlg_OnInitDialog (HWND hwnd, HWND hwndFocus, LPARAM lParam) // Message processing (required)
{

}

VOID Dlg_OnCommand (HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) // Command message processing
{

}

INT_PTR CALLBACK MyDlgProc (HWND hwndDlg,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam
)
{
switch (uMsg)
{
case WM_INITDIALOG:
return SetDlgMsgResult (hwndDlg, uMsg, HANDLE_WM_INITDIALOG ((hwndDlg), (wParam), (lParam), (Dlg_OnInitDialog)));
break; //// Message map
case WM_COMMAND:
return SetDlgMsgResult (hwndDlg, uMsg, HANDLE_WM_COMMAND ((hwndDlg), (wParam), (lParam), (Dlg_OnCommand)));
break;

}
return FALSE;
}


int WINAPI WinMain (HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow
)
{
DialogBox (hInstance, MAKEINTRESOURCE (IDD_DLG), NULL, MyDlgProc);
}
Reply

Use magic Report

0

Threads

8

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-4-8 09:45:01
| Show all posts
I know the above method is possible
Is there a method that does not use my own message loop, that is, a method that can display a simple dialog box such as Dlg.Modal
Reply

Use magic Report

0

Threads

9

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-4-9 12:00:01
| Show all posts
You can encapsulate a dialog call yourself!
Reply

Use magic Report

0

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-4-9 22:00:01
| Show all posts
Can't use classwizard under win32 program?
Need to use a set of win32 to do. After adding the dialog resource, call
:: DialogBox (...)
Reply

Use magic Report

0

Threads

18

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-8-16 23:45:01
| Show all posts
Look for a book about WIN32 programming, it will talk about it.
Reply

Use magic Report

0

Threads

14

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-8-17 01:30:01
| Show all posts
Use pre-compiled, and then run it down.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 Invalid IP Address

Post time: 2020-8-17 06:15:01
| Show all posts
//First declare the dialog box callback function
LRESULT CALLBACK YourDialog(HWND,UINT,WPARAM,LPARAM);//Callback function of game menu dialog
//Implementation part
LRESULT CALLBACK YourDialog(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)
{
    HDC hdc = (HDC)wParam;
switch (message)
{
case WM_INITDIALOG:
return TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
To
break;
                 case XXXXXX:
                      Here you can add other news
                     break;
}
    return FALSE;
}

//Then you need to call the dialog box, such as when you click the left button
DialogBox(hInst, (LPCTSTR)IDD_MENU, hWnd, (DLGPROC)YourDialog)
You can also deal with the return value judgment
switch(DialogBox(hInst, (LPCTSTR)IDD_MENU, hWnd, (DLGPROC)GameMenu))
{
   case OK:
case XXX
At this time the dialog box comes out
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list