|
#include
#define IDI_APPLICATION MAKEINTRESOURCE(32512)
#define WS_OVERLAPPEDWINDOW (WS_OVERLAPPED | \
WS_CAPTION | \
WS_SYSMENU | \
WS_THICKFRAME | \
WS_MINIMIZEBOX | \
WS_MAXIMIZEBOX)
LONG WINAPI WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPWSTR lpCmdLine,int nCmdShow)
{
WNDCLASS wc;
HWND hwnd;
MSG msg;
BOOL bReg;
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 = NULL;
wc.lpszClassName = L"First Window Class";
RegisterClass(&wc);
hwnd = CreateWindow(
L"First Window Class",
L"第一个Windows应用程序",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
200,
300,
HWND_DESKTOP,
NULL,
hInstance,
NULL
);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
int bRet;
while((bRet=GetMessage(&msg,NULL,0,0))!=0)
{
if(bRet == -1)
{}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
LPCWSTR szHello = L"欢迎使用VC++2005";
switch(message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
RECT rc;
GetClientRect(hWnd, &rc);
DrawText(hdc, szHello, 12, &rc, DT_CENTER);
EndPaint(hWnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
因为开始时,出现错误:
.\Win32Project.cpp(15) : error C2065: 'IDI_APPLICATION' : undeclared identifier
.\Win32Project.cpp(35) : error C2065: 'WS_OVERLAPPEDWINDOW' : undeclared identifier
所以我只能在文件开始处,自己定义:
#define IDI_APPLICATION MAKEINTRESOURCE(32512)
#define WS_OVERLAPPEDWINDOW (WS_OVERLAPPED | \
WS_CAPTION | \
WS_SYSMENU | \
WS_THICKFRAME | \
WS_MINIMIZEBOX | \
WS_MAXIMIZEBOX)
这样定义好以后,编译是通过了,但是运行的时候出现连接错误:
Linking...
Win32Project.obj : error LNK2019: unresolved external symbol __security_cookie referenced in function "long __cdecl WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YAJPAUHWND__@@IIJ@Z)
Win32Project.obj : error LNK2019: unresolved external symbol __security_check_cookie referenced in function "long __cdecl WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YAJPAUHWND__@@IIJ@Z)
Pocket PC 2003 (ARMV4)\Debug/Win32Project.exe : fatal error LNK1120: 2 unresolved externals
问题1:是不是需要加什么头文件,就可以不用自己定义IDI_APPLICATION和WS_OVERLAPPEDWINDOW了啊?
问题2:连接错误的话应该怎么解决?
注意:我用的是VS2005,在Win32 Smart Device Project中新建项目并添加的C++文件里编译的。(我在Win32 Project中新建项目添加的C++文件里编译和运行都可以通过的。不知道为什么?)
谢谢帮忙!
|
|