如下程序的作用是建立一个Windows窗口,可是总是报错。
#include<windows.h>
HWND hWndMain;
LRESULT CALLBACK MainWndProc(HWND,UINT,WPARAM,LPARAM);
int APIENTRY WinMain(HINSTANCE hIns,
HINSTANCE hPrev,
LPSTR lpCmdLine,
int nCmdShow){
MSG msg;
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hIns;
wndclass.lpfnWndProc=(WNDPROC)MainWndProc;
wndclass.lpszClassName="WndClass";
wndclass.lpszMenuName=NULL;
wndclass.style=0;
RegisterClass(&wndclass);
hWndMain=CreateWindow("WndClass","My Window",WS_OVERLAPPEDWINDOW,
20,20,300,300,NULL,NULL,hIns,NULL);
ShowWindow(hWndMain,nCmdShow);
UpdateWindow(hWndMain);
while(GetMessage(&msg,NULL,0,0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK MainWndProc(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam){
switch(message){
case WM_DESTROY:
PostQuitMessage(0);
default:
return(DefWindowProc(hWnd,message,wParam,lParam));
}
}错误信息:
E:\Program Files\Microsoft\Visual Studio 6.0\MSDev98\MyProjects\window\Main.cpp(12) : error C2440: '=' : cannot convert from 'void *' to 'struct HBRUSH__ *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
Error executing cl.exe.
#include<windows.h>
HWND hWndMain;
LRESULT CALLBACK MainWndProc(HWND,UINT,WPARAM,LPARAM);
int APIENTRY WinMain(HINSTANCE hIns,
HINSTANCE hPrev,
LPSTR lpCmdLine,
int nCmdShow){
MSG msg;
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hIns;
wndclass.lpfnWndProc=(WNDPROC)MainWndProc;
wndclass.lpszClassName="WndClass";
wndclass.lpszMenuName=NULL;
wndclass.style=0;
RegisterClass(&wndclass);
hWndMain=CreateWindow("WndClass","My Window",WS_OVERLAPPEDWINDOW,
20,20,300,300,NULL,NULL,hIns,NULL);
ShowWindow(hWndMain,nCmdShow);
UpdateWindow(hWndMain);
while(GetMessage(&msg,NULL,0,0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK MainWndProc(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam){
switch(message){
case WM_DESTROY:
PostQuitMessage(0);
default:
return(DefWindowProc(hWnd,message,wParam,lParam));
}
}错误信息:
E:\Program Files\Microsoft\Visual Studio 6.0\MSDev98\MyProjects\window\Main.cpp(12) : error C2440: '=' : cannot convert from 'void *' to 'struct HBRUSH__ *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
Error executing cl.exe.
WINAPI和APIENTRY 的区别是什麽?能推荐一本相关的学习教材吗?
这里要强制类型转换。