主题:WinMain() 为什么有错误呢?[求助]
[b]VC+XP 提示我 HINSTANCE 未定义等等[/b]
#include <windows.h>
INT PASCAL WinMain([b]HINSTANCE[/b],HINSTANCE,LPSTR,INT);
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE myhInst;
char szAppName[]="WinAPIDome";
char szAppTitle[]="A Application use Windows API";
INT PASCAL WinMain(HINSTACE hInstacne,HINSTANCE hPrevInstance,LPSTR IpCmdLine,int nShowCmd)
{
HWND hMainwnd;
MSG message;
WNDCLASS myWC;
if(!hPrevInstance)
{
myWC.style =CS_HREDRAW | CS_VREDRAW; //定义窗口类型
myWC.lpszWndProc =WndProc; //子程序名
myWC.cbClsExtra =0; //
myWC.cbWndExtra =0;
myWC.hInstance =hInstance;
myWC.hIcon =LoadIcon(NULL,IDI_APPLICATION);
myWC.hCursor =LoadCursor(NULL,IDC_ARROW);
myWC.hbrBackground=GetStockObject(WHITE_BRUSH);
myWC.lpszClassName=szAppName;
myWC.lpszMenuName =NULL;
RegisterClass(&myWC);
}
hMainwnd=CreateWindow(szAppName,
szAppTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hMainwnd,SW_SHOWMAXIMIZED);
UpdateWindow(hMainwnd);
while(GetMessage(&message,NULL,0,0))
{
TranslateMessage(&message);
DispatchMessage(&message);
}
return message.wParam;
}
LRESULT CALLBACK WndProc(HWND hMainwnd,
UINT message,
WPARAM wParam,
LPARAM IParam)
{
char messageLeft[]="This is demo program using in API.\n";
char messageRight[]="This is demo program using in API RIGHT.\n";
switch(message)
{
case WM_RBUTTONDOWN;
{
MessageBeep(MB_ICONINFORMATION);
MessageBox(GetFocus(),messageRight,"Message",
MB_OK | MB_ICONINFORMATION);
break;
}
case WM_LBUTTONDOWN;
{
MessageBeep(MB_ICONINFORMATION);
MessageBox(GetFoucus(),messageLeft,"Message",
MB_OK | MB_ICONINFORMATION);
break;
}
case WM_DESTROY;
{
PostQuitMessage(0);
return 0;
}
default:
break;
}
return DefWindowProc(hMainwnd,message,wParam,IParam);
}
#include <windows.h>
INT PASCAL WinMain([b]HINSTANCE[/b],HINSTANCE,LPSTR,INT);
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE myhInst;
char szAppName[]="WinAPIDome";
char szAppTitle[]="A Application use Windows API";
INT PASCAL WinMain(HINSTACE hInstacne,HINSTANCE hPrevInstance,LPSTR IpCmdLine,int nShowCmd)
{
HWND hMainwnd;
MSG message;
WNDCLASS myWC;
if(!hPrevInstance)
{
myWC.style =CS_HREDRAW | CS_VREDRAW; //定义窗口类型
myWC.lpszWndProc =WndProc; //子程序名
myWC.cbClsExtra =0; //
myWC.cbWndExtra =0;
myWC.hInstance =hInstance;
myWC.hIcon =LoadIcon(NULL,IDI_APPLICATION);
myWC.hCursor =LoadCursor(NULL,IDC_ARROW);
myWC.hbrBackground=GetStockObject(WHITE_BRUSH);
myWC.lpszClassName=szAppName;
myWC.lpszMenuName =NULL;
RegisterClass(&myWC);
}
hMainwnd=CreateWindow(szAppName,
szAppTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hMainwnd,SW_SHOWMAXIMIZED);
UpdateWindow(hMainwnd);
while(GetMessage(&message,NULL,0,0))
{
TranslateMessage(&message);
DispatchMessage(&message);
}
return message.wParam;
}
LRESULT CALLBACK WndProc(HWND hMainwnd,
UINT message,
WPARAM wParam,
LPARAM IParam)
{
char messageLeft[]="This is demo program using in API.\n";
char messageRight[]="This is demo program using in API RIGHT.\n";
switch(message)
{
case WM_RBUTTONDOWN;
{
MessageBeep(MB_ICONINFORMATION);
MessageBox(GetFocus(),messageRight,"Message",
MB_OK | MB_ICONINFORMATION);
break;
}
case WM_LBUTTONDOWN;
{
MessageBeep(MB_ICONINFORMATION);
MessageBox(GetFoucus(),messageLeft,"Message",
MB_OK | MB_ICONINFORMATION);
break;
}
case WM_DESTROY;
{
PostQuitMessage(0);
return 0;
}
default:
break;
}
return DefWindowProc(hMainwnd,message,wParam,IParam);
}