标题:Win32编程使用CreateWindowW 宽字符L“abc”作为标题名称,为什么标题名称只 ...
取消只看楼主
kekuri
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2015-6-14
结帖率:0
已结贴  问题点数:20 回复次数:0 
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);
}
搜索更多相关主题的帖子: include 
2015-06-14 01:05



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-446570-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.225386 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved