get a window handle from an Instance handle

get a window handle from an Instance handle

Post by Hu Don » Wed, 14 Jul 2004 08:58:47


Hi,
I got some difficulties in getting a window handle from an instance handle
in Win32 API/C. I used the approach stated in the knowledge base article
242308 -- how to find a window handle from an instance handle, but I found
nothing even though I went through the whole window (TOP level windows)
handles.

I found the instance handle is a 9-digit long integer, and the other
process IDs returned by GetWindowThreadProcessId are only three or four
digits long. Is it normal?

I appreciate your any ideas!

Hu
 
 
 

get a window handle from an Instance handle

Post by Gary Chans » Wed, 14 Jul 2004 10:21:55


The instance handle is not very useful in Win32 except in the few places
it's taken as a parameter. In Win32 it's not unique so you can't do much
with it. What you need is the Thread ID of the main thread in a specific
process.

--
-GJC [MS Windows SDK MVP]
-Software Consultant (Embedded systems and Real Time Controls)
- http://www.yqcomputer.com/
XXXX@XXXXX.COM

 
 
 

get a window handle from an Instance handle

Post by Hu Don » Wed, 14 Jul 2004 11:02:49

Thanks for your reply. Gary.
It is a long story why I need to get a window handle from an instance
handle. I want to call UpdateWindow() in a dialogbox I developed to repaint
a window B which was developed by the third party. What I need is the handle
to that window B. I know nothing about their works but their program calls
my dialog boxes. So what I am trying to do is, to find out the instance to
that program (third party program) by GetModuleHandle(), and then to find
out the handle to that window B through the way stated in the knowledge base
article 242308.

Do you have any comments? Ideas?

Thanks!

Hu
 
 
 

get a window handle from an Instance handle

Post by David Lieb » Wed, 14 Jul 2004 12:50:17

Maybe enumerate all the windows on the system and use
GetWindowThreadProcessId on each and compare it to your process Id?
Presumably, if it's the same process id, it's the window you're looking for?

David Liebtag
 
 
 

get a window handle from an Instance handle

Post by Gary Chans » Wed, 14 Jul 2004 12:55:16


repaint
handle
base

That must be a very old article. GetWindowThreadProcessID doesn't
return an instance handle in Win32. It returns a Process ID and a Thread ID
(the first is returned in the variable pointed to by lpdwProcessId).

It looks like the program does the right thing even though the text uses
obsolete terms. Someone probably did a half-hearted job of modernizing it.
I think if you simply substitute ProcessID for hInstance, it will make more
sense.

--
-GJC [MS Windows SDK MVP]
-Software Consultant (Embedded systems and Real Time Controls)
- http://www.yqcomputer.com/
XXXX@XXXXX.COM
 
 
 

get a window handle from an Instance handle

Post by Hu Don » Wed, 14 Jul 2004 12:59:30

Thanks for your reply. David.
The process ID you are talking about is the instance handle, which can be
gotton from GetModuleHandle(), isn't? It is supposed to work, isn't it?

Thanks!

Hu






for?
 
 
 

get a window handle from an Instance handle

Post by David Lieb » Wed, 14 Jul 2004 23:15:10

I don't know, but I never thought that module handles were the same as
process IDs.

David
 
 
 

get a window handle from an Instance handle

Post by Gary Chans » Thu, 15 Jul 2004 00:37:56


No. A Process ID is a system-wide unique identifier for the process. A
module handle is simply the virtual load address of the module and most
programs have the same value (typically 0x400000).

--
-GJC [MS Windows SDK MVP]
-Software Consultant (Embedded systems and Real Time Controls)
- http://www.yqcomputer.com/
XXXX@XXXXX.COM
 
 
 

get a window handle from an Instance handle

Post by Arkady Fre » Thu, 15 Jul 2004 16:25:41

That the same only in Windows CE not in the big windows
Arkady
 
 
 

get a window handle from an Instance handle

Post by r_z_are » Fri, 16 Jul 2004 02:12:56

On Mon, 12 Jul 2004 19:02:49 -0700, "Hu Dong"



I think Gary Chanson already gave you an answer to your actual
question. But this paragraph makes me think about an alternative
approach: using FindWindow. You can use Spy to determine the window
class for the window. If you're lucky, it will be unique so can use it
in FindWindow to get a handle unambiguously. If you're almost as
lucky, the window has a constant, unique, caption you can use.

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret, eMVP
PenFact, Inc.
500 Harrison Ave., Suite 3R
Boston, MA 02118
www.penfact.com
 
 
 

get a window handle from an Instance handle

Post by Hu Don » Sat, 17 Jul 2004 02:56:41

Thanks! It is a really nice method I never thought before. Actually, I
solved the problem but I believe your suggestion will be very useful in the
near future.

Hu





repaint
handle
calls
please indicate which newsgroup and message).