C++ win32程序如何获取Edit Control控件输入的文本值?

psy0324 2009-12-01 04:43:50
我现在用C++创建了一个win32程序,在一个新创建了一个Dialog对话框,对话框中拖了一个Edit Control控件,我想程序运行后,通过操作弹出那个Dialog,我想获取用户在Edit Control输入的文本值,如何获取?高手希望能提供点代码,本人以前是做.net的,现在初学C++, 很多不懂。。。
...全文
1969 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhoulunchongqing 2009-12-01
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 psy0324 的回复:]
2楼,int GetWindowText(          HWND hWnd,
    LPTSTR lpString,
    int nMaxCount
);
第一个参数我明白,句柄。后面两个参数哪里来?
[/Quote]

lpString 是你将要用来存储用户输入的字符缓冲区指针
nMaxCount是存储的字符串中字符的最大个数

你可以这样使用
char buffer[100];
GetWindowText(hwnd,buffer,100)
或者GetWindowText(hwnd,buffer,strlen(buffer)+1)
mmilmf 2009-12-01
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 psy0324 的回复:]
2楼,int GetWindowText(          HWND hWnd,
    LPTSTR lpString,
    int nMaxCount
);
第一个参数我明白,句柄。后面两个参数哪里来?
[/Quote]
lpString是指向存储字符缓冲区的指针
nMaxCount是缓冲区中容纳的最多字符的个数

使用
char str[80]存储获取到字符串
GetWindowText(hWnd,str,80);//即可
老邓 2009-12-01
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 psy0324 的回复:]
2楼,int GetWindowText(          HWND hWnd,
    LPTSTR lpString,
    int nMaxCount
);
第一个参数我明白,句柄。后面两个参数哪里来?
[/Quote]

TCHAR buf[MAX_PATH];
GetWindowText(hWnd, buf, MAX_PATH);
mstlq 2009-12-01
  • 打赏
  • 举报
回复
hWnd
[in] Handle to the window or control containing the text.
lpString
[out] Pointer to the buffer that will receive the text. If the string is as long or longer than the buffer, the string is truncated and terminated with a NULL character.
nMaxCount
[in] Specifies the maximum number of characters to copy to the buffer, including the NULL character. If the text exceeds this limit, it is truncated.
psy0324 2009-12-01
  • 打赏
  • 举报
回复
2楼,int GetWindowText( HWND hWnd,
LPTSTR lpString,
int nMaxCount
);
第一个参数我明白,句柄。后面两个参数哪里来?
mstlq 2009-12-01
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/en-us/library/ms633520(VS.85).aspx
  • 打赏
  • 举报
回复 1
int GetWindowText(          HWND hWnd,
LPTSTR lpString,
int nMaxCount
);
老邓 2009-12-01
  • 打赏
  • 举报
回复 1
GetWindowText(hWnd...

64,650

社区成员

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

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