473,769 Members | 2,044 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get the correct Window Handle for a application opened using createprocess api

17 New Member
Dear All,

We have a requirement to open any document with a specific application and display it within a OCX control (Example - word, excel, adobe reader, MSPaint, Photoshop etc). We are using CreateProcess Api to open the application. This APi returns process id and process handle. Once the application is opened, i need the exact window handle to show within the container (OCX control). I use "EnumWindow s" to enumerate all top level windows and check
whether there is no parent and check for the process id. If the process id matches, i check the application class name to get the exact handle (many handles are returned for the same process id). I beleive the application class name will be unique for each window handle. Is there a better way to get the exact window handle for the application opened using createprocess?

=============== =============== =============== =============Co de:

ReDim malngWindowHand les(0) As Long
lngRetVal = EnumWindows(Add ressOf EnumWindowsProc , lngParam)

For lngHandle = 1 To UBound(malngWin dowHandles)
lngRetVal = GetWindowLong(m alngWindowHandl es(lngHandle), GWL_HWNDPARENT)
If lngRetVal = 0 Then
If lngProcessId = GetProcIDFromWH andle(malngWind owHandles(lngHa ndle)) Then
strClassName = Space$(256)
lngClassLength = GetClassName(ma lngWindowHandle s(lngHandle), strClassName, 256)
strClassName = UCase$(Trim$(Le ft$(strClassNam e, lngClassLength) & ""))
strClassName = """" & strClassName & """"
If InStr(strAppCla ssName & ",", strClassName & ",") > 0 Then
GetApplicationH andle = malngWindowHand les(lngHandle): Exit For
End If
End If
End If
Next

=============== =============== =============== =============== =============== =============== ====

Thanks & Regards,
Sasie
May 4 '07 #1
0 2183

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1731
by: andrea.gavana | last post by:
Hello NG, I don't know if this is the right place to post this question, but noting that it is os-related probably someone will have some nice idea. I have built an application using Python+wxPython, and I have compiled it into an exe file using py2exe. In my app, I use a call: self.process = os.spawnl(os.P_NOWAIT, MyCommand) where MyCommand is a call to an external exe file. When I run my
2
6648
by: Bumbrlik | last post by:
When I spawn a console application from a another application of mine using _spawnl(_P_NOWAIT, my_program, ......), it opens a new console window but when it is finished the window is automatically closed. Is there any way I can keep the window open even after the program terminated (I want to be able check the output) ? Thank you.
1
2834
by: RJN | last post by:
Hi In the mainscreen I have a datagrid and from here I open new windows on click of link button. And I'm doing it through RegisterStartupScript Me.RegisterStartupScript("PopUp", _ "<script language='JavaScript'> " & _ "var winOp = window.open('MyScreen.aspx', 'test');" + _ "if (winOp != null) winOp.focus();" + _ "</script>")
3
7819
by: DraguVaso | last post by:
Hi, My application has some interaction with an other application. I sometimes need to put the other application to the front. The problem is that I'm not able to get a nice solution to work in every case. I tryed two ways: one way it disn't maximazi the Windowd when it was Minimized, in the other way it resized the application when it was maximzed. First I take a Handle to the other Window with the...
4
4391
by: Blaine | last post by:
Does anyone know how I can hide a form from the TaskManager? I've set the ShowInTaskbar to False, but when using Alt-TAB to switch between applications, it appears as a blank icon. I can set it as a SizableToolWindow, but then I no longer have the minimize button on the caption. Is there a way to mimic a (FormBorder) sizable tool window (so it doesn't appear in the tasklist) and still show the Min, Max and Close control buttons? (Or...
7
3674
by: anthony.turcotte | last post by:
Hi, I've looked for a solution to this problem on google, read posts in this newsgroup and I still haven't found anything that could help me. Here's the scenario. 1. User accesses pageA.html 2. User clicks on menu link to open popup.html 3. pageA.html checks if popup.html is already open. It is not, open
10
6349
by: Stephany Young | last post by:
When one uses the System.Diagnostics.Process.Start method to launch a common or garden Console application, one can set the WindowStyle property of the StartInfo object to ProcessWindowStyle.Hidden so that the window for the Console application is not visible. However, when using some of the 'advanced' properties of the StartInfo object, like Username, Password and Domain, the WindowsStyle property of the StartInfo object is ignored....
2
596
by: Jonathan Boivin | last post by:
Hi people, Let me introduce to how I get this error. I have a form which load all my bills representation depending upon filters which each bill is a usercontrol of my own having some textboxes containing bill's datas. (I already replaced the labels by painting the text instead.) When I click on my filter button, it clears the current usercontrol bills and load the new ones upon the current chosen filters. The bug happens when
1
1008
by: Wubarrt | last post by:
Hi all, I'm trying to execute a modal application window in a VC++ .NET project. The project is basically a form which is used to launch various word processors in Windows; Notepad, Wordpad etc. I'm having an extremely difficult time trying to find a way to make the Wordpad application window to be modal. (to avoid multiple copies to be opened) Here's a snippet of code which is part of a menu option:
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9996
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5307
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3564
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.