标题:Win32编程使用CreateWindowW 宽字符L“abc”作为标题名称,为什么标题名称只 ...
只看楼主
kekuri
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2015-6-14
结帖率:0
已结贴  问题点数:20 回复次数:3 
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
w2009w
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:2
帖 子:190
专家分:542
注 册:2015-4-20
得分:20 
不知道,百度一下嘛!
2015-06-14 15:09
yuccn
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:何方
等 级:版主
威 望:167
帖 子:6809
专家分:42393
注 册:2010-12-16
得分:0 
static unsigned short szAppName[] = L"abc";
改成w_char szAppName[] = L"abc" 或者 WCHAR szAppName[] = L"abc"

我行我乐
我的博客:
http://blog.yuccn. net
2015-08-10 10:08
blza3127672
Rank: 2
等 级:论坛游民
帖 子:13
专家分:13
注 册:2012-7-19
得分:0 
short是短整型,类名是一个字符串,改成WCHAR 就行了
2016-09-23 08:28



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




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

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