Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Registered Window Message TaskbarButtonCreated not received

I am wanting to start looking at the Windows 7 TaskBar API. I have created a basic MFC Dialog Project but after registering the TaskbarButtonCreated message, it never gets sent to my WindowProc. Here is what I have:

LRESULT CTaskBarAPITestDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
    if(message == g_wmTBC)
    {
        AfxMessageBox(_T("Hit the message"));
        //This is never hit
    }
    return CDialogEx::WindowProc(message, wParam, lParam);
}

int CTaskBarAPITestDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CDialogEx::OnCreate(lpCreateStruct) == -1)
        return -1;

    g_wmTBC = RegisterWindowMessage(_T("TaskbarButtonCreated"));
    //This works fine

    return 0;
}

The AfxMessageBox never gets hit. I have also tried adding a ON_REGISTERED_MESSAGE to my MESSAGE_MAP but that method doesn't get called either. Any suggestions?

like image 377
Shane Haw Avatar asked May 14 '26 09:05

Shane Haw


1 Answers

Turns out I needed the following:

ChangeWindowMessageFilterEx(AfxGetMainWnd()->GetSafeHwnd(), g_wmTBC, MSGFLT_ALLOW, NULL);
ChangeWindowMessageFilterEx(AfxGetMainWnd()->GetSafeHwnd(), WM_COMMAND, MSGFLT_ALLOW, NULL);

in my OnInitDialog.

EDIT:

This is because I was running the application with elevated privileges and so by default messages will not be received from a lower-privileged process unless you use ChangeWindowMessageFilterEx. More info: ChangeWindowMessageFilterEx Documentation.

Microsoft also have some example code doing the same thing here on github

like image 169
Shane Haw Avatar answered May 17 '26 10:05

Shane Haw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!