InternalGetWindowText函数为我们提供了获取Windows NT/2000系统中窗口标题的最快速的方法。它位于User32.dll。这个函数的功能类似于 GetWindowText,但是比GetWindowText快多了,因为它使用INT 2E 中断。InternalGetWindowText 是一个未公开的函数,它只能在Windows NT/2000 系统中使用,Windows 95/98系统中虽然也有这个函数,但只是摆摆样子而已,每次调用都返回错误代码 ERROR_CALL_NOT_IMPLEMENTED。
// fastgetwndtext.cpp (Windows NT/2000)
//
// This example will show you the most faster method how you can obtain
// the text of the specified window's title bar under Windows NT/2000 system.
#include <windows.h>
#include <stdio.h>
// User32!InternalGetWindowText (NT specific!)
//
// The function copies the text of the specified window's title bar
// (if it has one) into a buffer. The InternalGetWindowText function is
// much faster then documented GetWindowText because it uses INT 2E interrupt
//
// int InternalGetWindowText(
// HWND hWnd, // handle to window or control with text
// LPWSTR lpString, // pointer to buffer for text (UNICODE!!!)
// int nMaxCount // maximum number of characters to copy
// );
typedef int (WINAPI *PROCINTERNALGETWINDOWTEXT)(HWND,LPWSTR,int);
PROCINTERNALGETWINDOWTEXT InternalGetWindowText;
void main(int argc, char* argv[])
{
if (argc<2)
{
printf("Usage:\n\nfastgetwndtext.exe hWnd\n");
return;
}
HWND hWnd;
sscanf(argv[1],"%lx",&hWnd);
if (!IsWindow(hWnd))
{
printf("Incorrect window handle\n");
return;
}
HMODULE hUser32 = GetModuleHandle("user32");
if (!hUser32)
return;
InternalGetWindowText = (PROCINTERNALGETWINDOWTEXT)
GetProcAddress(hUser32,"InternalGetWindowText");
if (!InternalGetWindowText)
return;
WCHAR wCaption[280];
// retrieves the window's caption by using INT 2E interruption
if (InternalGetWindowText(hWnd,wCaption,sizeof(wCaption)))
printf("%S",wCaption);
}