读书人

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

发布时间: 2012-06-05 13:54:06 作者: rapoo

怎样获取对话框输入的字符串
用什么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));

读书人网 >C++

热点推荐