使用CreateWindowExA碰到的问题?

iamluda 2009-04-03 10:55:56
示例代码如下:
char app_name[512]={0};
sprintf(app_name, "%s", "123我的测试程序");

char title_name[512]={0};
sprintftitle_name"%s", "123程序");

return CreateWindowExA(dwExStyle, app_name,title_name, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);

如果应用程序的名称和标题的名称 中没有包含中文,则程序的执行结果正确.
如果上面2个包含中文,则程序的执行结果不正确.

碰到这个问题该如何处理呢?
...全文
546 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
影子LEON 2009-04-03
  • 打赏
  • 举报
回复
CreateWindowExA
你用的是带A滴。。。
建议使用TCHAR[]=_T("");
使用CreateWindowEx函数
。。。。。。。。。
Paradin 2009-04-03
  • 打赏
  • 举报
回复
#define _UNICODE

_T("...")
yyyapple 2009-04-03
  • 打赏
  • 举报
回复
char app_name[512]={0};

////////////////////////
这里是字节数组,不是字符数组,你把中文保存在字节数组中,
然后用ansi版CreateWindowExA 函数去设置标题,当然只会一个一个字节去解释成ansi字符,
最后只会编程乱码,lz还是用unicode的吧省心
老邓 2009-04-03
  • 打赏
  • 举报
回复
给你个代码对比:
#include <windows.h>

/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/* Make the class name into a global variable */
char szClassName[ ] = "这是中文";

int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */

/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);

/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;

/* The class is registered, let's create the program*/
hwnd = CreateWindowExA (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"这还是中文", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);

/* Make the window visible on the screen */
ShowWindow (hwnd, nCmdShow);

/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}

/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}


/* This function is called by the Windows function DispatchMessage() */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;
}
mengde007 2009-04-03
  • 打赏
  • 举报
回复

#include <iostream>
#include <string>
#include <TCHAR.h>
using namespace std;

int main()
{

TCHAR app_name[512]={0};
sprintf(app_name, "%s", "123我的测试程序");
cout<<app_name;
return 0;
}

老邓 2009-04-03
  • 打赏
  • 举报
回复
楼上几位别误导了:谁说ANSI不支持中文???
只是不支持GBK和GB18030罢了。
GB2312是没问题的!!

所以楼主的问题绝对不是中文的问题。
如果程序能运行到CreateWindowExA的话,则一定是其他地方出了问题。
但楼主没给完整代码,所以不可能判断具体问题。
mengde007 2009-04-03
  • 打赏
  • 举报
回复
估计又是unicode吧
_T("……");
老邓 2009-04-03
  • 打赏
  • 举报
回复
与中文没关系!把整个示例代码发上来,我帮你调试。
tangshuiling 2009-04-03
  • 打赏
  • 举报
回复

用wchar_t wsprintf试试
yyyapple 2009-04-03
  • 打赏
  • 举报
回复
CreateWindowExA //只支持anscii字符吧,改用unicode函数
iamluda 2009-04-03
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 Loaden 的回复:]
楼上几位别误导了:谁说ANSI不支持中文???
只是不支持GBK和GB18030罢了。
GB2312是没问题的!!

所以楼主的问题绝对不是中文的问题。
如果程序能运行到CreateWindowExA的话,则一定是其他地方出了问题。
但楼主没给完整代码,所以不可能判断具体问题。
[/Quote]

你的思路是完全正确的

64,680

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧