vc++之getwindowtext

函數功能

  該函數將指定窗口的標題條文本(如果存在)拷貝到一個緩存區內。如果指定的窗口是一個控件,則拷貝控件的文本。但是,GetWindowTeXt不能接收在其他應用程序中的控件的文本。

  函數原型:Int GetWindowText(HWND hWnd,LPTSTR lpString,Int nMaxCount);

參數

  hWnd:帶文本的窗口或控件的句柄。

  IpString:指向接收文本的緩衝區的指針。

  nMaxCount:指定要保存在緩衝區內的字符的最大個數,其中包含NULL字符。如果文本超過界限,它就被截斷。

  getwindowtext的DELPHI例子:

  var

  p:pchar;

  begin

  getmem(p,255);

  getwindowtext(application.Handle,p,255);

  showmessage(strpas(p));

  freemem(p);

  end;

返回值

  如果函數成功,返回值是拷貝的字符串的字符個數,不包括中斷的空字符;如果窗口無標題欄或文本,或標題欄爲空,或窗口或控制的句柄無效,則返回值爲零。若想獲得更多錯誤信息,請調用GetLastError函數。

  函數不能返回在其他應用程序中的編輯控件的文本。

備註

  如果目標窗口屬於當前進程,GetWindowText函數給指定的窗口或控件發送WM_GETTEXT消息。如果目標窗口屬於其他進程,並且有一個窗口標題,則GetWindowTeXt返回窗口的標題文本,如果窗口無標題,則函數返回空字符串。

  速查:Windows NT:3.1以上版本;Windows:95以上版本:Windows CE:1.0以上版本;頭文件:Winuser.h;庫文件:user32.lib:Unicode:在Windows NT上實現爲Unicode和ANSI兩種版本。

  int GetWindowText(

  LPTSTR lpszStringBuf,

  int nMaxCount

  ) const;

  void GetWindowText(

  CString& rString

  ) const;

  Parameters

  lpszStringBuf

  Points to the buffer that is to receive the copied string of the window's title.

  nMaxCount

  Specifies the maximum number of characters to be copied to the buffer, including the terminating null character. If the string is longer than the number of characters specified in nMaxCount, it is truncated.

  rString

  A CString object that is to receive the copied string of the window's title.

  Return Value

  Specifies the length, in characters, of the copied string, not including the terminating null character. It is 0 if CWnd has no caption or if the caption is empty.

  Remarks

  If the CWnd object is a control, the GetWindowText member function copies the text within the control instead of copying the caption.

  This member function causes the WM_GETTEXT message to be sent to the CWnd object.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章