🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
7 messages
7 total messages Started by poojo hackma Fri, 16 Feb 2007 20:25
How do I get HWND?
#2582
Author: poojo hackma
Date: Fri, 16 Feb 2007 20:25
7 lines
1160 bytes
I have a thread running in a non-VCL app.

I want to post a WM_PAINT message to the main window from this thread, but I 
need to know the HWND for UpdateWindow(HWND hWnd).

How do I get that from the main window? Once I have it, I can make it 
available to the thread. 
Re: How do I get HWND?
#2583
Author: poojo hackma
Date: Fri, 16 Feb 2007 21:02
45 lines
2150 bytes
A search pulled up the code below, but that seems like a lot of work just to 
get the HWND.

Isn't there something basic?

Code:
// -----------------------------------------
HWND  g_hwnd;
int  g_nFound;

BOOL CALLBACK FindHwndFromPID( HWND hwnd, LPARAM lParam) :

HWND GetHwndFromPID ( DWORD dwProcessId)
{
 g_hwnd = NULL;
 g_nFound = 0;
 EnumWindows (  FindHwndFromPID,    ( LPARAM) dwProcessId));
 if ( g_hwnd)  // we found one...
      return ( g_hwnd);
 // nothing found :-(
 return (NULL);
}

BOOL CALLBACK FindHwndFromPID( HWND hwnd, LPARAM lParam)
{
    DWORD   dwPID2Find  =   ( DWORD) lParam;
    DWORD   dwPID       =   0;
    if  (   GetWindowThreadProcessId    (   hwnd,   &dwPID))
        {
            if  (   dwPID   ==  dwPID2Find)
                {
                    g_hwnd  =   hwnd;
                    return  (   FALSE);
                }
        }
    return  (   TRUE);
}

And call 'GetHwndFromPID()' like

Usage:
// -----------------------------------------
HWND hwnd = GetHwndFromPID(GetCurrentProcessId());

which will retrieve the top-level window handle for your app. 
Re: How do I get HWND?
#2584
Author: Thomas Maeder [TeamB]
Date: Fri, 16 Feb 2007 22:37
9 lines
1387 bytes
"poojo hackma" <poojo.com/mail> writes:

> A search pulled up the code below, but that seems like a lot of work
> just to get the HWND.
>
> Isn't there something basic?

I have no idea, but I wouldn't trust the programmer's competence too
much since he unnecesarily used global variables.
Re: How do I get HWND?
#2441
Author: DreamChaser
Date: Sat, 17 Feb 2007 02:42
14 lines
1450 bytes
Isn't HWnd a property of the form? I have also seen a lot things that 
indicated that Form->Handle was the HWnd. Just a thought :)
jk

Thomas Maeder [TeamB] wrote:
> "poojo hackma" <poojo.com/mail> writes:
> 
>> A search pulled up the code below, but that seems like a lot of work
>> just to get the HWND.
>>
>> Isn't there something basic?
> 
> I have no idea, but I wouldn't trust the programmer's competence too
> much since he unnecesarily used global variables.
Re: How do I get HWND?
#2443
Author: Ron Sawyer
Date: Sat, 17 Feb 2007 18:24
8 lines
1355 bytes
Did poojo say it was a non-vcl app?

"DreamChaser" <jkofsky@bellsouth.net> wrote in message
news:45d66b86$1@newsgroups.borland.com...
> Isn't HWnd a property of the form? I have also seen a lot things that
> indicated that Form->Handle was the HWnd. Just a thought :)
> jk
>
Re: How do I get HWND?
#2446
Author: Bob Gonder
Date: Sun, 18 Feb 2007 16:52
8 lines
1207 bytes
poojo hackma wrote:

>How do I get that from the main window? Once I have it, I can make it 
>available to the thread.

I use a global.
When WinMain creates the window,  the handle is returned which I then
store in gHWnd.
Re: How do I get HWND?
#2466
Author: poojo hackma
Date: Tue, 20 Feb 2007 15:58
10 lines
1428 bytes
Yes, it is a non-VCL app, so I can't use Form->Handle. Thanks for the 
though, though.

"Ron Sawyer" wrote
> Did poojo say it was a non-vcl app?
>
> "DreamChaser" wrote
>> Isn't HWnd a property of the form? I have also seen a lot things that
>> indicated that Form->Handle was the HWnd. Just a thought :)
>> jk
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads