Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get Hwnd of the Window

Status
Not open for further replies.

sulacco

Technical User
Nov 8, 2002
74
RU
How to get hwnd of the window. Thanks for advance.
It's can be obtained if you call CreateWindow. What if i dont call this function. What can i do?
with due respect. sulacco
 
How about you look at the MSDN help for CWnd, and realize there is a method called GetSafeHwnd()?

I hope that helps,

Vincent
 
If I understand correctly, you want to get the handle to a window that is already created, rather than creating a new window with CreateWindow.

If the window is a top-level window, you can find it using EnumWindows. If you have the handle for a child of the window, you can call GetParent to get it.
 
There is a problem. I'm not using MFC to use GetSafeHwnd().

Second: I'm not called CreateWindow. Code look's like this:

...

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{

MSG msg;
First();
OnHook();


while( GetMessage( &msg, NULL, 0, 0 ) ) {
TranslateMessage( &msg );
DispatchMessage( &msg );
}


return 0;
}
...
It's just bare skeleton. but in next to this function i have to get hwnd.
 
You have no window - why do you need hWnd? Most API calls have parameter hWnd, but it could be NULL, I think. What API calls do you use namelly?
Use NULL or hWnd of the desktop - HWND_DESKTOP. Or may be create dummy invisible window using CreateWindow?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top