将CString转换为LPCTSTR [英] Converting CString to LPCTSTR
问题描述
在大多数情况下,直接分配是有效的(我亲自尝试并成功在VC6和Visual Studio 8中做到了这一点),即:
CString s ="hello";
LPCTSTR p = s;
通过删除OP很难找到问题,您的问题代码为kartikdasani写道:
CString p; m_editbox-> GetWindowText(p); CWND * c = FindWindow(NULL,p);
标题也不是一个幸运的选择,因为我认为问题不在于从CString
到LPCTSTR
的转换.
在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 waskartikdasani 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 fromCString
toLPCTSTR
.
The call toFindWindow()
is correct, when it is inside aCWnd
derived class. But you should look at the description ofCWnd::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 aHWND
).
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屋!