/*
------------------------------------------------------------
Hello.c
------------------------------------------------------------
*/
#include "windows.h"
LPCTSTR lpszAppName=TEXT("MyApp");
LPCTSTR lpszTitle=TEXT("My Application");
/*
typedef struct WNDCLASS
{
UINT style;
WNDPROC lpfnWndProc;
INT cbClsExtra;
INT cbWndExtra;
HANDLE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCTSTR lpszMenuName;
LPCTSTR lpszClassName;
}WNDCLASS;
*/
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
//LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{
MSG msg;
HWND hWnd;
WNDCLASSE wc;
// 注册主应用程序的窗口类
wc.style=CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc=(WNDPROC)WndProc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=hInstance;
wc.hIcon=LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor=LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName=lpszAppName;
wc.lpszClassName=lpszAppName;
if(!RegisterClass(&wc))
return(FALSE);
// 创建主应用程序的窗口
hWnd=CreateWindow(lpszAppName, lpszTitle,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,0, CW_USEDEFAULT, 0,
NULL, NULL, hInstance, NULL);
if (!hWnd)
return(FALSE);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(msg.wParam);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam)
{
RECT rect;
HDC hdc;
PAINTSTRUCT ps;
static int uRed=0, uGreen=0, uBlue=0;
switch(uMsg)
{
case WM_PAINT :
hdc=BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rect);
SetTextColor(hdc, RGB(uRed, uGreen, uBlue));
DrawText (hdc, TEXT ("Hello, You Are Welcoming!"), -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
EndPaint(hWnd, &ps);
break;
case WM_KEYDOWN :
uRed=rand() % 255;
uGreen=rand() % 255;
uBlue=rand() % 255;
InvalidateRect(hWnd, NULL, TRUE);
break;
case WM_DESTROY :
PostQuitMessage(0);
break;
default :
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return(0L);
}
====================================================================================
自己定义也不行,,又冲突了。
注释掉,又显示未定义。
main.cpp
d:\debug\test4\main.cpp(44) : error C2065: 'WNDCLASSE' : undeclared identifier
d:\debug\test4\main.cpp(44) : error C2146: syntax error : missing ';' before identifier 'wc'
d:\debug\test4\main.cpp(44) : error C2065: 'wc' : undeclared identifier
d:\debug\test4\main.cpp(48) : error C2228: left of '.style' must have class/struct/union type
d:\debug\test4\main.cpp(50) : error C2228: left of '.lpfnWndProc' must have class/struct/union type
d:\debug\test4\main.cpp(52) : error C2228: left of '.cbClsExtra' must have class/struct/union type
d:\debug\test4\main.cpp(54) : error C2228: left of '.cbWndExtra' must have class/struct/union type
d:\debug\test4\main.cpp(56) : error C2228: left of '.hInstance' must have class/struct/union type
d:\debug\test4\main.cpp(58) : error C2228: left of '.hIcon' must have class/struct/union type
d:\debug\test4\main.cpp(60) : error C2228: left of '.hCursor' must have class/struct/union type
d:\debug\test4\main.cpp(62) : error C2228: left of '.hbrBackground' must have class/struct/union type
d:\debug\test4\main.cpp(64) : error C2228: left of '.lpszMenuName' must have class/struct/union type
d:\debug\test4\main.cpp(66) : error C2228: left of '.lpszClassName' must have class/struct/union type
执行 cl.exe 时出错.
Creating browse info file...
test4.exe - 1 error(s), 0 warning(s)