Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hey all,

I'm getting some strange behaviour when using SHnotificationAdd the code i'm using to add the notification is as follows.

char * szFunc = __FUNCTION__;
BUError(E_STANDARDPARAMS, L"CNOInt_Beep_notification start");

BU_TRY
{
    //init structure if not already
    if(pMsgBeepAlertData == NULL)
    {
        pMsgBeepAlertData = (SHNOTIFICATIONDATA*)BULocalAlloc(LMEM_ZEROINIT,sizeof(SHNOTIFICATIONDATA));
        if(pMsgBeepAlertData == NULL)
        {
            BUWinError(WE_STANDARDPARAMS,L"%hs : failed to alloc memory",szFunc);
            return FALSE;
        }
    }
    //Remove existing notification for class
    SHNOTIFICATIONDATA oldNotifyData = {0};
    oldNotifyData.cbStruct = sizeof(SHNOTIFICATIONDATA);
    LRESULT lres = SHNotificationGetData(&IID_NewMsg,ICON_ID_MESSAGEBEEP,&oldNotifyData );
    if (ERROR_SUCCESS == lres)
    {
        if (oldNotifyData.pszHTML) free((void *) oldNotifyData.pszHTML);
        if (oldNotifyData.pszTitle) free((void *) oldNotifyData.pszTitle);


        SetLastError(0);
        LRESULT lres = SHNotificationRemove(&IID_NewMsg, ICON_ID_MESSAGEBEEP);
        BUError(E_STANDARDPARAMS, L"SHNotificationRemove just called prior to add, lres=%u LastError=%u",lres,GetLastError());
    }
    else
    {
        BUError(E_STANDARDPARAMS, L"SHNotificationRemove NOT called - as notification dosn't exist lres=%u LastError=%u",lres,GetLastError());
    }

    //Set up structure
    pMsgBeepAlertData->cbStruct      = sizeof(SHNOTIFICATIONDATA);
    pMsgBeepAlertData->dwID          = ICON_ID_MESSAGEBEEP;
    pMsgBeepAlertData->npPriority    = SHNP_ICONIC;
    pMsgBeepAlertData->csDuration    = 5;
    pMsgBeepAlertData->hicon     = NULL;
    pMsgBeepAlertData->grfFlags      = SHNF_STRAIGHTTOTRAY | SHNF_CRITICAL;
    pMsgBeepAlertData->clsid     = IID_NewMsg;
    pMsgBeepAlertData->hwndSink      = NULL;
    pMsgBeepAlertData->pszHTML       = L"";
    pMsgBeepAlertData->pszTitle      = L"New Message";
    pMsgBeepAlertData->lParam       = ICON_ID_MESSAGEBEEP;

    //Add notification
    SetLastError(0);
    lres = SHNotificationAdd(pMsgBeepAlertData);
    if (ERROR_SUCCESS != lres)
    {
        BUError(E_STANDARDPARAMS, L"SHNotificationAdd Failed, lres=%u LastError=%u",lres,GetLastError());
        return FALSE;
    }

    BUError(E_STANDARDPARAMS, L"CNOInt_Beep_notification return true ,LastError=%u",GetLastError());
}
BU_CATCH_AND_LOG_ALL
return TRUE;


Trouble is that once it goes off, I get a second message beep afterwards.

Anyone have any idea why this occurs ???
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900