Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MessagePumpHook not receiving messages from NotifyIcon (NOTIFYICONDATA) #54

Open
manjarooo opened this issue Nov 4, 2024 · 2 comments

Comments

@manjarooo
Copy link

manjarooo commented Nov 4, 2024

Hello,
I am trying to write an app with a NotifyIcon (system tray icon) with WinFBE/FreeBASIC.

So far, I was able to create a NotifyIcon and show it in the system tray.
But now I am trying to react on events, create a popup menu etc., but the MessagePumpHook function of the frmForm doesn't receive any events from the NotifyIcon.

The MessagePumpHook is, if I did understand it right, some kind of "replacement" for the WinProc callback function you would normaly use when you create your window/form by code with CreateWindow(), while you get the hWnd from CreateWindow(), right? So I activated the event in the WinFBE Designer, and took some code in its function body.
Then I did set the NOTIFYICONDATAs hWnd variable to frmForm.hWindow, which the manual says is the hWnd of the frmForm, while I created the NotifyIcon in the frmForm_Load() function, to "connect" both, the frmForm and the NotifyIcon, and successfully created it with
Shell_NotifyIcon( NIM_ADD, @SystrayIcon )

I have put a PRINT statement in my MessagePumpHook to log all messages cuming in, and while I use the normal frmForm with my mouse, I can see a lot of messages going through. But when I hover the NotifyIcon with the mouse, nothing happens. When I click on the Icon with the left or right mouse button, nothing happens.

It seems like the NotifyIcon and the frmForm are not "connected" correctly. The MessagePumpHook receives messages from the main app frmForm, but the created NotifyIcon is not able to send its messages to the given hWindow message queue of the frmForm. Maybe the hWnd/hWindow of the frmForm is wrong at all? Is there any other handle I have to use?

I have tried different WinFBE versions (2+3) and different FreeBASIC compiler versions (1.07.2 and 1.10.x), always with the same result.

Here are some snippets from my code.
Did I oversee or misunderstood something? Depending MessagePumpHook and WinProc?
Am I doing something wrong here? Or is it a bug in WinFBE?

Hope that somebody can help or point me to the right direction... :-)

My OS is Windows 10 Pro 64bit, and I am using WinFBE 2.2.0 with FreeBASIC 1.07.2 (using the 64bit compiler)

Greetings!

** resource.rc **

1 24 ".\manifest.xml"
101 ICON ".\MyIcon.ico"

** main.bas **

#define WIN_INCLUDEALL
#include "windows.bi"
#define IDI_MYICON 101
#define WM_MYTRAYICON WM_APP+10

Application.Run(frmForm)

** frmForm.inc **

Dim Shared SystrayIcon As NOTIFYICONDATA
'...
Function frmForm_Load( ByRef sender As wfxForm, ByRef e As EventArgs ) As LRESULT
    Dim hIcon As hIcon
    hIcon = LoadIcon (getmodulehandle(0), MAKEINTRESOURCE(IDI_MYICON) )
	
    With SystrayIcon
        .cbSize = Len(SystrayIcon)
        .hWnd = frmForm.hWindow
        .uId = IDI_MYICON
        .uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP
        .uCallbackMessage = WM_MYTRAYICON
        .hIcon = hIcon
        .szTip = "NotifyIcon Test" +Chr(0)
    End With
    Shell_NotifyIcon( NIM_ADD, @SystrayIcon )
    Function = 0
End Function
'...
Function frmForm_MessagePumpHook( byval lpMSG as MSG ptr ) as boolean
    Dim lpClickPoint As POINT

    Print lpMSG->message	'for console log!

    Select Case lpMSG->message
        Case WM_MYTRAYICON
            Print "WM_MYTRAYICON"
            Select Case lpMSG->lParam
                Case WM_RBUTTONDOWN
                    'GetCursorPos(@lpClickPoint)
                    Print "WM_RBUTTONDOWN"
            End Select
        Case WM_DESTROY
            PostQuitMessage(0)
    End Select
    Function = 0
End Function
@PaulSquires
Copy link
Owner

Hi, instead of using MessagePumpHook, try using AllEvents handler instead. I created a sample project based on the code that you posted and using AllEvents, I was able to get the WM_MYTRAYICON message notifications.

Function frmForm_AllEvents( ByRef sender As wfxForm, ByRef e As EventArgs ) As LRESULT
    Select Case e.Message
        Case WM_MYTRAYICON
            Print "WM_MYTRAYICON"
            Select Case e.lParam
                Case WM_RBUTTONDOWN
                    'GetCursorPos(@lpClickPoint)
                    Print "WM_RBUTTONDOWN"
            End Select
    End Select

   Function = 0
End Function

@manjarooo
Copy link
Author

Oh wow! Thank you for that quick reply...
I have just tested your suggestion, moved my code into the AllEvents() function, and now everything is working as expected! Great! :-D

What is the intended difference between AllEvents() and MessagePumpHook() then?
Or, why is MessagePumpHook() "limited"? Is there a reason?

Again, a very big "thank you"! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants