#include<windows.h>
#include<iostream.h>
LRESULT CALLBACK Procwin(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)
{
WNDCLASS sxh;
sxh.style=0;
sxh.lpfnWndProc=Procwin;
sxh.cbClsExtra=0;
sxh.cbWndExtra=0;
sxh.hInstance=hInstance;
sxh.hIcon=LoadIcon(NULL,IDI_APPLICATION);
sxh.hCursor=LoadCursor(NULL,IDC_ARROW);
sxh.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
sxh.lpszMenuName=NULL;
sxh.lpszClassName="我的第一个窗口";
RegisterClass(&sxh);
HWND hwnd;
hwnd=CreateWindow("sxh","hehe",WS_OVERLAPPEDWINDOW,0,0,640,480,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//return msg.wParam;
return 0;
}
LRESULT CALLBACK Procwin(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
char messageleft[]="this my first form!";
switch(uMsg)
{
case WM_LBUTTONDOWN:
{
MessageBox(GetFocus(),messageleft,"hello",MB_OK|MB_ICONINFORMATION);
break;
}
case WM_DESTROY:
{
PostQuitMessage(0);
break;
}
default:
{
return DefWindowProc(hwnd,uMsg,wParam,lParam);
break;
}
return 0;
}
}
那位高手帮看一下为什么不能LINK!
參考答案:ATL支持把一个服务器编连优化成最小尺寸或者依赖性最小。我们可以定义三个预处理器符号来影响服务器的优化。
_ATL_MIN_CRT 服务器不链接标准的C/C++运行库
_ATL_DLL 服务器动态链接工具函数库atl.dll
_ATL_STATIC_REGISTRY 服务器静态链接对组件注册的支持
如果定义了预处理器符号_ATL_MIN_CRT,那么我们的服务器不链接C/C++运行库,并且ATL提供了函数malloc、realloc、new和delete的一个实现。当定义了这个符号时,我们不能调用任何其他的C/C++运行库的函数。否则,就会受到这样的待遇:
LIBCMT.LIB(crt0.obj) : error LNK2001: unresolved external symbol _main
ATL向导生成的ATL工程为所有的Release版本的编连定义了_ATL_MIN_CRT,但是没有为Debug版本定义这个符号。
Debug配置没有定义这三个符号中的任何一个。
RelMinSize配置定义了_ATL_MIN_CRT和_ATL_DLL。
RelMinDependency配置定义了_ATL_MIN_CRT和_ATL_STATIC_REGISTRY。
下面方法中的任何一个都可以纠正这个错误:
1 去除_ATL_MIN_CRT这个预处理符号;
2 打开stdafx.cpp,注释掉#include <atlimpl.cpp>这句话,然后编译,即可;
3 在工程的配置对话框的Link页面上,"ignore libraries"编辑框中输入Libcmt.lib,然后编译.