可以运行,但是不显示对话框,不知道怎么回事?请大家看看:mp.cpp#include <windows.h>
#include "mp_01.h"BOOL CALLBACK DialogFunc(
HWND hwndDlg, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
MSG msg;
HWND hDlg;
hDlg=CreateDialog(hInstance,MAKEINTRESOURCE(IDD_DLG),NULL,(DLGPROC)DialogFunc);
ShowWindow(hDlg,SW_SHOW);
UpdateWindow(hDlg);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}BOOL CALLBACK DialogFunc(
HWND hDlg, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDD_OPEN:
MessageBox(hDlg,"you click open","",MB_OK);
return TRUE;
}
case WM_CLOSE:
DestroyWindow(hDlg);
return TRUE;
break;
case WM_DESTROY:
PostQuitMessage(0);
return TRUE;
break;
}
return FALSE;
}
mp.h#define IDD_OPEN 100
#define IDD_DLG 101mp.rc#include <windows.h>
#include "mp_01.h"MyDB DIALOG 30,30,150,250
CAPTION "mp_01"
STYLE DS_MODALFRAME|WS_POPUP|WS_CAPTION|WS_SYSMENU
CLASS "Dlg"
{
DEFPUSHBUTTON "open",IDD_OPEN,40,40,30,13,
WS_CHILD|WS_VISIBLE|WS_TABSTOP
}
#include "mp_01.h"BOOL CALLBACK DialogFunc(
HWND hwndDlg, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
MSG msg;
HWND hDlg;
hDlg=CreateDialog(hInstance,MAKEINTRESOURCE(IDD_DLG),NULL,(DLGPROC)DialogFunc);
ShowWindow(hDlg,SW_SHOW);
UpdateWindow(hDlg);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}BOOL CALLBACK DialogFunc(
HWND hDlg, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDD_OPEN:
MessageBox(hDlg,"you click open","",MB_OK);
return TRUE;
}
case WM_CLOSE:
DestroyWindow(hDlg);
return TRUE;
break;
case WM_DESTROY:
PostQuitMessage(0);
return TRUE;
break;
}
return FALSE;
}
mp.h#define IDD_OPEN 100
#define IDD_DLG 101mp.rc#include <windows.h>
#include "mp_01.h"MyDB DIALOG 30,30,150,250
CAPTION "mp_01"
STYLE DS_MODALFRAME|WS_POPUP|WS_CAPTION|WS_SYSMENU
CLASS "Dlg"
{
DEFPUSHBUTTON "open",IDD_OPEN,40,40,30,13,
WS_CHILD|WS_VISIBLE|WS_TABSTOP
}
这里对话框ID是IDD_DLG,
RC文件中对话框又是MyDB DIALOG 30,30,150,250,当然不能显示了,根本就没有IDD_DLG这个对话框模板
switch(uMsg)
里面的case,请每个都加一个break!
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDD_OPEN:
MessageBox(hDlg,"you click open","",MB_OK);
return TRUE;
}
case WM_CLOSE:
DestroyWindow(hDlg);
return TRUE;
break;
此处,如果不是 IDD_OPEN ,那么,就执行了WM_CLOSE了!
他的意思是 你把MyDB DIALOG 30,30,150,250 改成 IDD_DLG DIALOG 30,30,150,250