首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

怎样获取对话框输入的字符串解决思路

2012-06-05 
怎样获取对话框输入的字符串用什么API函数获取对话框里输入的字符串,对话框只包含一个文本输入框和取消确

怎样获取对话框输入的字符串
用什么API函数获取对话框里输入的字符串,对话框只包含一个文本输入框和取消确定按钮,不用MFC直接用API函数

[解决办法]
int GetWindowText( HWND hWnd,
LPTSTR lpString,
int nMaxCount
);
Parameters

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. 

[解决办法]
//char *FindString=NULL;//你既然知道野指针的坏处,那就应该明白分配内吧...
char FindString[256]="";//改成这样就行了
先获取编辑框的句柄
HWND hEdit=GetDlgItem(hWndDlg,IDC_FINDSTRING)//hWndDlg(对话框)

GetWindowText(hEdit,FindString,sizeof(Find));

或者直接一句搞定
GetDlgItemTExt(hWndDlg,IDC_FINDSTRING,FindString,sizeof(FindString));

热点排行