高手指教,C++window程序 HWND hwnd = CreateWindow();为什么不好转换
#include<Windows.h>charName[]="AdvWin";LRESULTCALLBACKWndProc(HWNDhwnd,UINTMessage,WP...
#include<Windows.h>
char Name[] = "AdvWin";
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
BOOL Register(HINSTANCE hInst);
HWND Create(HINSTANCE hInst, int nCmdShow);
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
{
MSG Msg;
if (!Register(hInst))
return FALSE;
if (!Create(hInst, nCmdShow))
return FALSE;
while (GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
BOOL Register(HINSTANCE hInst)
{
WNDCLASS WndClass;
WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInst;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = L"Name";
return(RegisterClass(&WndClass) != 0);
}
HWND Create(HINSTANCE hInst, int nCmdShow)
{
HWND hwnd = CreateWindow(Name, Name, WS_OVERLAPPEDWINDOW, 10, 10, 600, 400, NULL, NULL, hInst, NULL);
if (hwnd == NULL)
return FALSE;
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
return hwnd;
}
void my_OnDestroy(HWND hwnd);
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch (Message)
{
case WM_DESTROY:
my_OnDestroy(hwnd);
break;
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}
void my_OnDestroy(HWND hwnd)
{
PostQuitMessage(0);
}
Error C2664 'HWND CreateWindowExW(DWORD,LPCWSTR,LPCWSTR,DWORD,int,int,int,int,HWND,HMENU,HINSTANCE,LPVOID)': cannot convert argument 2 from 'char [7]' to 'LPCWSTR' 展开
char Name[] = "AdvWin";
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
BOOL Register(HINSTANCE hInst);
HWND Create(HINSTANCE hInst, int nCmdShow);
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
{
MSG Msg;
if (!Register(hInst))
return FALSE;
if (!Create(hInst, nCmdShow))
return FALSE;
while (GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
BOOL Register(HINSTANCE hInst)
{
WNDCLASS WndClass;
WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInst;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = L"Name";
return(RegisterClass(&WndClass) != 0);
}
HWND Create(HINSTANCE hInst, int nCmdShow)
{
HWND hwnd = CreateWindow(Name, Name, WS_OVERLAPPEDWINDOW, 10, 10, 600, 400, NULL, NULL, hInst, NULL);
if (hwnd == NULL)
return FALSE;
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
return hwnd;
}
void my_OnDestroy(HWND hwnd);
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch (Message)
{
case WM_DESTROY:
my_OnDestroy(hwnd);
break;
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}
void my_OnDestroy(HWND hwnd)
{
PostQuitMessage(0);
}
Error C2664 'HWND CreateWindowExW(DWORD,LPCWSTR,LPCWSTR,DWORD,int,int,int,int,HWND,HMENU,HINSTANCE,LPVOID)': cannot convert argument 2 from 'char [7]' to 'LPCWSTR' 展开
1个回答
2017-02-02
展开全部
提示很清楚了,你不能把char [7]转换成LPCWSTR
LPCWSTR是 const wchar *类型,你得用wchar,字符串要用L""包裹,比如
wchar Name[] = L"AdvWin";
LPCWSTR是 const wchar *类型,你得用wchar,字符串要用L""包裹,比如
wchar Name[] = L"AdvWin";
追问
HWND hwnd = CreateWindow(Name, Name, WS_OVERLAPPEDWINDOW, 10, 10, 600, 400, NULL, NULL, hInst, NULL);
这一句怎么改呢?
追答
不用改
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询