Win32编程使用CreateWindowW 宽字符L“abc”作为标题名称,为什么标题名称只显示“a"?
#include <windows.h>LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
static unsigned short szAppName[] = L"abc";
int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE,
LPSTR szCmdLine,
int iCmdShow)
{
HWND hWnd;
MSG Msg;
WNDCLASSW WndClass;
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 (GRAY_BRUSH);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = szAppName;
RegisterClassW (&WndClass);
hWnd = CreateWindowW (szAppName,
szAppName,[/color]
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow (hWnd, iCmdShow);
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)
{
HDC hDc;
PAINTSTRUCT Ps;
RECT Rect;
switch (message)
{
case WM_PAINT:
hDc = BeginPaint (hWnd, &Ps);
GetClientRect (hWnd, &Rect);
DrawTextW (hDc, szAppName, -1, &Rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint (hWnd, &Ps);
return 0;
case WM_DESTROY:
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hWnd, message, wParam, lParam);
}