程序如下,问题是对话框的消息并没有发送到wndproc中去,请问是为什么啊,谢谢了#include <windows.h>
#include "resource.h"LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);static TCHAR szAppName[]=TEXT("maya");int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASS wndclass; wndclass.cbClsExtra =0;
wndclass.cbWndExtra =DLGWINDOWEXTRA;
wndclass.hbrBackground =(HBRUSH)(COLOR_BTNFACE+1);
wndclass.hCursor =LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon =LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance =hInstance;
wndclass.lpfnWndProc =WndProc;
wndclass.lpszClassName =TEXT("DLGCLASS");
wndclass.lpszMenuName =NULL;
wndclass.style =CS_HREDRAW|CS_VREDRAW; if(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("You should run in Windows NT"),TEXT("Error"),MB_OK);
return 0;
} hwnd=CreateDialog(hInstance,TEXT("MainDialog"),NULL,NULL); ShowWindow(hwnd,iCmdShow); while(GetMessage(&msg,NULL,0,0))
{
if (!IsDialogMessage (hwnd, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
} return msg.wParam;
}LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
PostQuitMessage(0);
break; }
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
#include "resource.h"LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);static TCHAR szAppName[]=TEXT("maya");int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASS wndclass; wndclass.cbClsExtra =0;
wndclass.cbWndExtra =DLGWINDOWEXTRA;
wndclass.hbrBackground =(HBRUSH)(COLOR_BTNFACE+1);
wndclass.hCursor =LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon =LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance =hInstance;
wndclass.lpfnWndProc =WndProc;
wndclass.lpszClassName =TEXT("DLGCLASS");
wndclass.lpszMenuName =NULL;
wndclass.style =CS_HREDRAW|CS_VREDRAW; if(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("You should run in Windows NT"),TEXT("Error"),MB_OK);
return 0;
} hwnd=CreateDialog(hInstance,TEXT("MainDialog"),NULL,NULL); ShowWindow(hwnd,iCmdShow); while(GetMessage(&msg,NULL,0,0))
{
if (!IsDialogMessage (hwnd, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
} return msg.wParam;
}LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
PostQuitMessage(0);
break; }
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
这句有问题
TEXT("MainDialog")要改为
wndclass.lpszClassName =TEXT("DLGCLASS");中的TEXT("DLGCLASS")
试试吧
#include <windows.h>
#include "resource.h"LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);static TCHAR szAppName[]=TEXT("maya");int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
{
DialogBox(hInstance,TEXT("MainDialog"),NULL,(DLGPROC)WndProc);
return 0;
}LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
EndDialog(hwnd,TRUE);
break; }
return 0;
}
return FALSE;
}你重新试试,我未验证.
里面有很多SDK的讲解