#include "windows.h"
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int);
int WINAPI WinMain(HINSTANCE, hInstance, HINSTANCE, hPrevInstance,
LPSTR lpCmdline, int nCmdShow)
{
WNDCLASS wcApp;
MSG msg;
HWND ghWnd = NULL;
char *szAppName = "Windows API Application";
char *szAppTitle = "Windows API 窗口程序";
wcApp.style = CS_HREDRAW;
wcApp.lpfnWndProc = WndProc;
wcApp.cbWndExtra = 0;
wcApp.cbClsExtra = 0;
wcApp.hInstance = hInstance;
wcApp.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wcApp.hCursor = LoadCursor(NULL, IDC_ARROW);
wcApp.hbrBackground = (HBRUSH)COLOR_ACTIVEBORDER;
wcApp.lpszMenuName = NULL;
wcApp.lpszClassName = szAppName;
RegisterClass(&wcApp);
ghWnd = CreateWindow(szAppName,szAppTitle,
WS_OVERLAPPEDWINDOW,
100,
100,
350,
300,
NULL,
NULL,
hInstance,
NULL);
if(NULL==ghWnd)
return 0;
ShowWindow(ghWnd,nCmdShow);
UpdateWindow(ghWnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
char *msgCreate ="收到WM_CREATE消息,建立窗口";
char *msgDestroy ="收到WM_DESTROY消息,关闭窗口";
char *msgCaption ="收到消息";
char *msgLBTN ="鼠标左键按下,收到WM_LBUTTONDOWN消息";
switch(message)
{
case WM_CREATE:
MessageBox(GetFocus(), msgCreate, msgCaption,
MB_OK|MB_ICONEXCLAMATION);
break;
case WM_LBUTTONDOWN:
MessageBox(GetFocus(), msgLBTN, msgCaption,
MB_OK|MB_ICONEXCLAMATION);
break;
case WM_DESTROY:
(GetFocus(), msgDestroy, msgCaption,
MB_OK|MB_ICONEXCLAMATION);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return FALSE;
}
编译后~~~
--------------------Configuration: program46 - Win32 Debug--------------------
Compiling...
WinAPI.cpp
f:\yuanma\program46\winapi.cpp(5) : error C2061: syntax error : identifier 'hInstance'
f:\yuanma\program46\winapi.cpp(7) : error C2731: 'WinMain' : function cannot be overloaded
f:\yuanma\program46\winapi.cpp(5) : see declaration of 'WinMain'
f:\yuanma\program46\winapi.cpp(18) : error C2065: 'hInstance' : undeclared identifier
f:\yuanma\program46\winapi.cpp(18) : error C2440: '=' : cannot convert from 'int' to 'struct HINSTANCE__ *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
f:\yuanma\program46\winapi.cpp(40) : error C2065: 'nCmdShow' : undeclared identifier
执行 cl.exe 时出错.
WinAPI.obj - 1 error(s), 0 warning(s)
请问各位大虾 怎么回师~~