flat assembler
Message board for the users of flat assembler.

Index > Windows > Getting a Window Handle from a Process

Author
Thread Post new topic Reply to topic
VitalOne



Joined: 29 Jul 2003
Posts: 54
Location: USA
VitalOne 02 Oct 2004, 05:00
Say I execute a file, using ShellExecute or WinExec or some function, how would I get the window handle of that executed file?
Post 02 Oct 2004, 05:00
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
Rookie



Joined: 21 Aug 2003
Posts: 44
Location: Planet Romania
Rookie 02 Oct 2004, 07:01
Assuming the app will put a window in the foreground, you can use
GetForegroundWindow. It has no params and returns the handle of the foreground window.
Post 02 Oct 2004, 07:01
View user's profile Send private message Reply with quote
VitalOne



Joined: 29 Jul 2003
Posts: 54
Location: USA
VitalOne 13 Oct 2004, 00:55
That could work, except on applications where it takes a certain amount of time for it to load.
Post 13 Oct 2004, 00:55
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld 13 Oct 2004, 08:21
Use CreateProcess to create a process, then enumerate windows (EnumWindows) and call GetWindowThreadProcessId for each window handle passed. Compare recieved values with ones from calling CreateProcess (last parameter, PROCESS_INFORMATION structure) to determine if this window is what you need.

I little bit weird but who knows, maybe it'll work for you Wink
Post 13 Oct 2004, 08:21
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
kongo bongo



Joined: 22 Nov 2004
Posts: 1
kongo bongo 22 Nov 2004, 23:59
Try this function from the user32.dll

Set the first parameter to NULL, and the second to the name in the mainwindows "titlebar" ( and lets hope there isn't 2 windows with equal name ).

Well, there are several other ways to do this, and a good startingpoint to investigate it is the following link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows.asp


HWND FindWindow(
LPCTSTR lpClassName,
LPCTSTR lpWindowName
);

Parameters

lpClassName

[in] Pointer to a null-terminated string that specifies the class name or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low-order word of lpClassName; the high-order word must be zero.
If lpClassName points to a string, it specifies the window class name. The class name can be any name registered with RegisterClass or RegisterClassEx, or any of the predefined control-class names.

If lpClassName is NULL, it finds any window whose title matches the lpWindowName parameter.


lpWindowName

[in] Pointer to a null-terminated string that specifies the window name (the window's title). If this parameter is NULL, all window names match.
Return Value

If the function succeeds, the return value is a handle to the window that has the specified class name and window name.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.


Remarks

If the lpWindowName parameter is not NULL, FindWindow calls the GetWindowText function to retrieve the window name for comparison. For a description of a potential problem that can arise, see the Remarks for GetWindowText.

To check if the Microsoft® IntelliType version 1.x software is running, call FindWindow as follows:

FindWindow("MSITPro::EventQueue",NULL);
Post 22 Nov 2004, 23:59
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.