#include
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
WNDCLASS wndclass;
HWND hWnd;
MSG msg;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName="window窗口创建";
if(!RegisterClass(&wndclass))
return FALSE;
hWnd=CreateWindowExW(WS_OVERLAPPEDWINDOW,"window窗口创建","window窗口创建",WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_PAINT:HDC hdc;
PAINTSTRUCT ps;
hdc=BeginPaint(hWnd,&ps);
TextOutW(hdc,10,20,"哈哈,windows编程创建的窗口!",28);
EndPaint(hWnd,&ps);
return 0;
case WM_DESTROY:PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd,message,wParam,lParam);
}
这代码报如下错误:
------ 已启动生成: 项目: 应用编程, 配置: Debug Win32 ------
1> hellomfc.cpp
1>c:\documents and settings\administrator\my documents\visual studio 2010\projects\应用编程\应用编程\hellomfc.cpp(17): error C2440: “=”: 无法从“const char [15]”转换为“LPCWSTR”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
1>c:\documents and settings\administrator\my documents\visual studio 2010\projects\应用编程\应用编程\hellomfc.cpp(21): error C2664: “CreateWindowExW”: 不能将参数 2 从“const char [15]”转换为“LPCWSTR”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
1>c:\documents and settings\administrator\my documents\visual studio 2010\projects\应用编程\应用编程\hellomfc.cpp(38): error C2664: “TextOutW”: 不能将参数 4 从“const char [28]”转换为“LPCWSTR”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========