FindWindow, dll and MFC modeless app? 
Author Message
 FindWindow, dll and MFC modeless app?

Hi,
I am trying to use a global mouse hook dll, and it works fine when i use
it on an MFC dialog based application.
But now, I'd want to use it with an MFC modeless application, this
application is hidden in the system tray...
In my dialog based, I sent the messages directly to the app using the
FindWindow command, and using as parameter the name of the active window
of my app...
But how could i do now, as it is a modeless app hidden in the systray,
and which never has the focus...

Here is a exerpt of the global hook i use for my dialog based app:

LRESULT CALLBACK MouseHookCallback( int nCode, WPARAM wParam,LPARAM
lParam )
{
    if (nCode < 0)
        return CallNextHookEx(ghMouseHook, nCode, wParam, lParam);
    if (wParam == WM_MOUSEMOVE || wParam == WM_NCMOUSEMOVE)
    {    LPMOUSEHOOKSTRUCT mhs = (LPMOUSEHOOKSTRUCT) lParam;
        CWnd* poWnd = CWnd::FindWindow(NULL, "MouseHook App");
<<<<<<<<< This line...
        [...]
        return CallNextHookEx(ghMouseHook, nCode, wParam, lParam);
    }

Quote:
}

Any idea on how to modifiy this to be able to use it with my modeless
app?

Best Regards,
D.Excoffier

remove all "_" for a direct answer.



Tue, 02 Jul 2002 03:00:00 GMT  
 FindWindow, dll and MFC modeless app?
Enumerate all the windows using EnumWindows();


Quote:
> Hi,
> I am trying to use a global mouse hook dll, and it works fine when i use
> it on an MFC dialog based application.
> But now, I'd want to use it with an MFC modeless application, this
> application is hidden in the system tray...
> In my dialog based, I sent the messages directly to the app using the
> FindWindow command, and using as parameter the name of the active window
> of my app...
> But how could i do now, as it is a modeless app hidden in the systray,
> and which never has the focus...

[snipped]


Tue, 02 Jul 2002 03:00:00 GMT  
 FindWindow, dll and MFC modeless app?
FindWindow is hazardous; in particular, if you have an app blocked
(legitimately) on pending I/O or a synchronization object, your
FindWindow can hang interminably, blocking your entire system. Also,
doing FindWindow in a mouse hook is outrageously inefficient, since it
requires scanning the entire list of windows on every mouse event. I'm
surprised you actually drag the mouse around.

The usual way this is done is that the app that is receiving the mouse
notifications (your SendMessage target) simply stores its window
handle in a shared, read/write variable in the DLL.

#pragma data_seg(".shr")
HWND WhomToTell = NULL; // initialization critical!
#pragma data_seg()

Then link with /segment:.shr,r,w,s

You can then do ::SendMessage(WhomToTell) from any thread in which the
DLL is executing, and it will get to your application.
                        joe

On Fri, 14 Jan 2000 10:41:05 +0100, David Excoffier

Quote:

>Hi,
>I am trying to use a global mouse hook dll, and it works fine when i use
>it on an MFC dialog based application.
>But now, I'd want to use it with an MFC modeless application, this
>application is hidden in the system tray...
>In my dialog based, I sent the messages directly to the app using the
>FindWindow command, and using as parameter the name of the active window
>of my app...
>But how could i do now, as it is a modeless app hidden in the systray,
>and which never has the focus...

>Here is a exerpt of the global hook i use for my dialog based app:

>LRESULT CALLBACK MouseHookCallback( int nCode, WPARAM wParam,LPARAM
>lParam )
>{
>    if (nCode < 0)
>        return CallNextHookEx(ghMouseHook, nCode, wParam, lParam);
>    if (wParam == WM_MOUSEMOVE || wParam == WM_NCMOUSEMOVE)
>    {    LPMOUSEHOOKSTRUCT mhs = (LPMOUSEHOOKSTRUCT) lParam;
>        CWnd* poWnd = CWnd::FindWindow(NULL, "MouseHook App");
><<<<<<<<< This line...
>        [...]
>        return CallNextHookEx(ghMouseHook, nCode, wParam, lParam);
>    }
>}

>Any idea on how to modifiy this to be able to use it with my modeless
>app?

>Best Regards,
>D.Excoffier

>remove all "_" for a direct answer.

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Tue, 02 Jul 2002 03:00:00 GMT  
 FindWindow, dll and MFC modeless app?
"Joseph M. Newcomer" a crit :

Quote:

> The usual way this is done is that the app that is receiving the mouse
> notifications (your SendMessage target) simply stores its window
> handle in a shared, read/write variable in the DLL.

> #pragma data_seg(".shr")
> HWND WhomToTell = NULL; // initialization critical!
> #pragma data_seg()
> Then link with /segment:.shr,r,w,s
> You can then do ::SendMessage(WhomToTell) from any thread in which the
> DLL is executing, and it will get to your application.
>                         joe

I have a question relative to your answer. My DLL is Sending messages to the
CMainFrame of my modeless Application. Do you know an effective way to get
the handle of my CMainFrame class ???
TIA,
Best Regards,
David.
Quote:

> On Fri, 14 Jan 2000 10:41:05 +0100, David Excoffier

> >Hi,
> >I am trying to use a global mouse hook dll, and it works fine when i use
> >it on an MFC dialog based application.
> >But now, I'd want to use it with an MFC modeless application, this
> >application is hidden in the system tray...
> >In my dialog based, I sent the messages directly to the app using the
> >FindWindow command, and using as parameter the name of the active window
> >of my app...
> >But how could i do now, as it is a modeless app hidden in the systray,
> >and which never has the focus...

> >Here is a exerpt of the global hook i use for my dialog based app:

> >LRESULT CALLBACK MouseHookCallback( int nCode, WPARAM wParam,LPARAM
> >lParam )
> >{
> >    if (nCode < 0)
> >        return CallNextHookEx(ghMouseHook, nCode, wParam, lParam);
> >    if (wParam == WM_MOUSEMOVE || wParam == WM_NCMOUSEMOVE)
> >    {    LPMOUSEHOOKSTRUCT mhs = (LPMOUSEHOOKSTRUCT) lParam;
> >        CWnd* poWnd = CWnd::FindWindow(NULL, "MouseHook App");
> ><<<<<<<<< This line...
> >        [...]
> >        return CallNextHookEx(ghMouseHook, nCode, wParam, lParam);
> >    }
> >}

> >Any idea on how to modifiy this to be able to use it with my modeless
> >app?

> >Best Regards,
> >D.Excoffier

> >remove all "_" for a direct answer.

> Joseph M. Newcomer [MVP]

> Web: http://www3.pgh.net/~newcomer
> MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm



Sat, 06 Jul 2002 03:00:00 GMT  
 FindWindow, dll and MFC modeless app?

Quote:
> I have a question relative to your answer. My DLL is Sending messages to
the
> CMainFrame of my modeless Application. Do you know an effective way to get
> the handle of my CMainFrame class ???
> TIA,
> Best Regards,
> David.

Use AfxGetMainWnd() to get the mainwindow's handle.

--
Ajay Kalra

Microsoft VC++/MFC MVP

Note: Please post all replies to newsgroup only.



Sat, 06 Jul 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. HLP: Kbd Hook dll and MFC modeless app ???

2. FindWindow() fails when an MFC app is specified

3. Show modeless form in VB ActiveX DLL from C++ MFC DLL

4. Modeless dialog based MFC app?

5. PB with modeless app and global DLL keyboard hook

6. Modeless Dialog in DLL, trying to pass calling APP as parent

7. Help w/ app crashing in MFC shared dll but not w\ static MFC using VC6

8. Using non-MFC DLL in MFC app

9. Invoking an Dialog Box from an MFC app to an MFC DLL

10. Calling MFC DLLs from a non-MFC app

11. Memory Allocation using MFC App and DLL with shared MFC library

12. Trying to convert MFC App to MFC DLL

 

 
Powered by phpBB® Forum Software