将CString转换为LPCTSTR [英] Converting CString to LPCTSTR

查看:179
本文介绍了将CString转换为LPCTSTR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在大多数情况下,直接分配是有效的(我亲自尝试并成功在VC6和Visual Studio 8中做到了这一点),即:

CString s ="hello";
LPCTSTR p = s;

解决方案

通过删除OP很难找到问题,您的问题代码为

kartikdasani写道:

 CString p;
m_editbox-> GetWindowText(p);
CWND * c = FindWindow(NULL,p); 


标题也不是一个幸运的选择,因为我认为问题不在于从CStringLPCTSTR的转换.

CWnd派生类中,对FindWindow()的调用是正确的.但是您应该看一下CWnd::FindWindow()的描述,它只会找到顶层窗口,而不是子窗口.

正如已经发布的< removed class ="Error"> CPallini,请向我们提供更多详细信息.


按您的说法,您的代码甚至无法编译(FindWindow返回).
请发布您的实际代码,并清楚说明您得到了什么(以及您的期望).

顺便说一句:请修改您的原始帖子,而不要添加虚假答案.
:)


我建​​议您阅读这篇出色的文章 [ ^ ]


Direct assignment works in most cases( I have personally tried and succeeded in doing so in VC6 and Visual Studio 8)that is:

CString s="hello";
LPCTSTR p = s;

解决方案

By deleting your OP it is not easy to find the problem, your code for the question was

kartikdasani wrote:

CString p;
m_editbox->GetWindowText(p);
CWND *c = FindWindow(NULL,p);


Also the title is no lucky choice, because I think the problem is not the conversion from CString to LPCTSTR.

The call to FindWindow() is correct, when it is inside a CWnd derived class. But you should look at the description of CWnd::FindWindow() it will only find top-level windows, not child windows.

As <removed class="Error">CPallini already posted, give us more details.


As it stands your code doesn''t even compile (FindWindow returns a HWND).
Please post your actual code, and state clearly what do you get (and what you expect).

BTW: please modify your original post instead of adding fake answers.
:)


I suggest you read this excellent article[^]


这篇关于将CString转换为LPCTSTR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆