Get the text within a dialog box

落爺英雄遲暮 提交于 2019-12-12 04:44:50

问题


What Windows API function can I use to get text within a dialog? For example, if I had the handle of an error message dialog, how could I get the displayed error message?


回答1:


If I correctly understand your question, your problem is very easy. Open Spy++ from the Visual Studio Tools menu. Then press Ctrl + F to receive a dialog for finding windows. Drag & drop the "Finder tool" on the control inside the dialog box from which you want to read the text; look at properties of the window, the field "Control ID" is what you need.

If you have a handle of the Dialog Window (HWND hDlg) you should use the GetDlgItemText function (see http://msdn.microsoft.com/en-us/library/ms645489(VS.85).aspx)

UINT GetDlgItemText(HWND hDlg,
    int nIDDlgItem,
    LPTSTR lpString,
    int nMaxCount
);

to read the text. As a nIDDlgItem parameter you should place the identifier of the control. It is the value which you have found using Spy++.




回答2:


Dialog boxes don't actually contain text - they contain other controls which contain the text. You must enumerate or otherwise find the appropriate child window of the dialog box, and get its text with GetWindowText.



来源:https://stackoverflow.com/questions/2751400/get-the-text-within-a-dialog-box

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!