开发者

win32 Api programming

I want to get a running application text e.g if i am running notepad then i want to get the text written inside it .For this first i have to get the handle of notepad but i don't know how to get the notepad 开发者_如何转开发handle so please tell me .Then through which functions i can get its inside text ? which header files to include ? what are necessary declarations? Please help me i am new to windows API programming.i have gone through basic tutorials of windows programming but that doesn't help me a lot.


Use FindWindowEx. Though you must have been able to find this yourself, if you were looking/googling for a way to "find notepad handle in C++" ;)

You can even find complete examples on "Sending text to notepad in C++"


To expand on GolezTrol's answer, you could do this:

#include <windows.h>
#include <tchar.h>

int CALLBACK _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow ) {
  HWND hwnd = FindWindow( _T("Notepad"), NULL);
  hwnd      = FindWindowEx( hwnd, NULL, _T("edit"), NULL );

  TCHAR lpText[256];
  SendMessage( hwnd, WM_GETTEXT, _countof(lpText), (LPARAM)lpText);
  MessageBox(0, lpText, lpText, 0);
  return ERROR_SUCCESS;
}

In reality, you would probably use a more reliable method of window identification (eg. enumerating all windows and verifying what process it belongs to)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜