jdl
jdl

Reputation: 6323

Getting handle of current window to GetWindowText?

I want to display the Title of the Dialog box:

HWND hWnd = ::GetActiveWindow();
char cc[101];
::GetWindowText(hWnd,cc,100);
MessageBox(cc);

but the result yields a blank "".

not sure what is wrong??

Upvotes: 0

Views: 4999

Answers (2)

Skelli
Skelli

Reputation: 283

This may coming a bit late but anyway. If you want to get the current (active) window on the system at any time, the best approach is by using a procedure implemented in a DLL, then installing a global hook that call this procedure.

The following resources are quite helpful:

  1. Creating and using your DLL
  2. An overview on Hooks

Upvotes: 0

JosephH
JosephH

Reputation: 8815

According to MSDN:

Retrieves the window handle to the active window attached to the calling thread's message queue.

This means that if the thread which you are calling the function from doesn't own any window, the function will fail.

You probably want GetForegroundWindow instead.

Upvotes: 1

Related Questions