PDA

Ver la Versión Completa : Como averiguar que ventana de windows esta activa?


JuanErasmo
17-04-2006, 15:34:07
Buenos dias!
Estoy intentando averiguar con C++ Builder, que ventana esta activa cada 10 segundos.....es decir si el usuario esta en Word, que me diga que esta ahi... si esta en Excel...o en Internet....etc....Que función me puede servir?
Muchas gracias!

luisgutierrezb
17-04-2006, 15:44:35
de la ayuda de windows:

The GetForegroundWindow function returns the handle of the foreground window (the window with which the user is currently working). The system assigns a slightly higher priority to the thread that creates the foreground window than it does to other threads.

HWND GetForegroundWindow(VOID)

Parameters
This function has no parameters.

Return Values
The return value is the handle of the foreground window.

JuanErasmo
17-04-2006, 16:19:53
Hola y muchas gracias por la respuesta!
Ese me duvuelve el Handle...pero yo quiero conocer el nombre de la clase...
hay otra funcion para que me de el nombre de la clase?
por ej...Word = OpusApp...
Gracias

OSKR
17-04-2006, 16:41:17
char ClassName[256];
GetClassName(GetForegroundWindow(),ClassName,255);
Claro, esto deberia estar en un ciclo hasta q se encuentre el tamaño adecuado pero con 256b creo q basta

JuanErasmo
17-04-2006, 17:56:33
Gracias por la respuesta es justo lo que buscaba...
pero ahora quiero el nombre de la ventana...no de la clase...
por ejemplo en esta ventana la calse es IEFrame...pero el nombre es :
"Foros Club Delphi - Responder a Topico - Microsoft Internet Explorer"...
Como hago para acceder a este nombre?
Para conocerlo?
Gracias!

luisgutierrezb
17-04-2006, 21:47:40
De nuevo de la ayuda de Win32 Programmer's Reference

The GetWindowText function copies the text of the specified window's title bar (if it has one) into a buffer. If the specified window is a control, the text of the control is copied.

int GetWindowText(
HWND hWnd, // handle of window or control with text
LPTSTR lpString, // address of buffer for text
int nMaxCount // maximum number of characters to copy
);


Parameters
hWnd
Identifies the window or control containing the text.
lpString
Points to the buffer that will receive the text.
nMaxCount
Specifies the maximum number of characters to copy to the buffer. If the text exceeds this limit, it is truncated.

Return Values
If the function succeeds, the return value is the length, in characters, of the copied string, not including the terminating null character. If the window has no title bar or text, if the title bar is empty, or if the window or control handle is invalid, the return value is zero. To get extended error information, call GetLastError.