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

Re: get a window handle from an Instance handle by Gary

Gary
Mon Jul 12 20:21:55 CDT 2004


"Hu Dong" <hdong@ucdavis.edu.INVALID> wrote in message
news:%23raAtwGaEHA.2016@TK2MSFTNGP09.phx.gbl...
> 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!

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.mvps.org/ArcaneIncantations/consulting.htm
-gchanson@mvps.org


Re: get a window handle from an Instance handle by Hu

Hu
Mon Jul 12 21:02:49 CDT 2004

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


"Hu Dong" <hdong@ucdavis.edu.INVALID> wrote in message
news:%23raAtwGaEHA.2016@TK2MSFTNGP09.phx.gbl...
> 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
>
>
>



Re: get a window handle from an Instance handle by David

David
Mon Jul 12 22:50:17 CDT 2004

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



Re: get a window handle from an Instance handle by Gary

Gary
Mon Jul 12 22:55:16 CDT 2004


"Hu Dong" <hdong@ucdavis.edu.INVALID> wrote in message
news:eaGGB2HaEHA.3012@tk2msftngp13.phx.gbl...
> 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?

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.mvps.org/ArcaneIncantations/consulting.htm
-gchanson@mvps.org


Re: get a window handle from an Instance handle by Hu

Hu
Mon Jul 12 22:59:30 CDT 2004

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




"David Liebtag" <DavidLiebtag@vermontel.net> wrote in message
news:1089690616.942163@vader.vermontel.net...
> 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
>
>



Re: get a window handle from an Instance handle by David

David
Tue Jul 13 09:15:10 CDT 2004

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

David



Re: get a window handle from an Instance handle by Gary

Gary
Tue Jul 13 10:37:56 CDT 2004


"David Liebtag" <DavidLiebtag@vermontel.net> wrote in message
news:1089730848.321224@jabba.vermontel.net...
> I don't know, but I never thought that module handles were the same as
> process IDs.

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.mvps.org/ArcaneIncantations/consulting.htm
-gchanson@mvps.org


Re: get a window handle from an Instance handle by Arkady

Arkady
Wed Jul 14 02:25:41 CDT 2004

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

"Hu Dong" <hdong@ucdavis.edu.INVALID> wrote in message
news:eB$uO3IaEHA.2944@TK2MSFTNGP11.phx.gbl...
> 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
>
>
>
>
> "David Liebtag" <DavidLiebtag@vermontel.net> wrote in message
> news:1089690616.942163@vader.vermontel.net...
> > 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
> >
> >
>
>



Re: get a window handle from an Instance handle by r_z_aret

r_z_aret
Wed Jul 14 12:12:56 CDT 2004

On Mon, 12 Jul 2004 19:02:49 -0700, "Hu Dong"
<hdong@ucdavis.edu.INVALID> wrote:

>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

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

Re: get a window handle from an Instance handle by Hu

Hu
Thu Jul 15 12:56:41 CDT 2004

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


<r_z_aret@pen_fact.com> wrote in message
news:mhhaf0tl9mf3bebiq8ilvnvtju061ss45n@4ax.com...
> On Mon, 12 Jul 2004 19:02:49 -0700, "Hu Dong"
> <hdong@ucdavis.edu.INVALID> wrote:
>
> >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
>
> 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