Mega Code Archive

 
Categories / Delphi / System
 

How to obtain the text of a specified windows title bar

Title: How to obtain the text of a specified windows title bar function NT_InternalGetWindowText(Wnd: HWND): string; type TInternalGetWindowText = function(Wnd: HWND; lpString: PWideChar; nMaxCount: Integer): Integer; stdcall; var hUserDll: THandle; InternalGetWindowText: TInternalGetWindowText; lpString: array[0..MAX_PATH] of WideChar; //Buffer for window caption oemStr: PChar; begin Result := ''; hUserDll := GetModuleHandle('user32.dll'); if (hUserDll 0) then begin @InternalGetWindowText := GetProcAddress(hUserDll, 'InternalGetWindowText'); if Assigned(InternalGetWindowText) then begin InternalGetWindowText(Wnd, lpString, SizeOf(lpString)); Result := string(lpString); end; end; end; procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage(NT_InternalGetWindowText(Form1.Handle)); end;