WM 通知、声音和提醒

    技术2022-05-19  21

    windows mobile 中,系统定义了许多通知类型,在不同的事件(来电、新短信等)时会抛出相应的通知。这里的通知是广义的,其效果包括:播放声音、振动、在屏幕上显示信息(从屏幕下方弹出一个消息框)、LED灯闪烁,所有这些都被认为是通知。 主要信息存在注册表 [HKEY_CURRENT_USER/ControlPanel/Notifications/{GUID}] ]下 键/值数据解析:[HKEY_CURRENT_USER/ControlPanel/Notifications/{GUID} ]"Wave"="声音文件具体路径,不用带扩展名,例如Sun CF/Mobile.wav就是Sun CF/Mobile""Duration"=指示灯(LED)闪烁时间[以分钟为时间单位,如果=0为无限制]"Options"=[0为静音],[=1为播放提示声音],[=4为指示灯闪烁,关联到"Duration"REG_DWORD值],[=5即1+4为播放提示声音并带指示灯闪灯][=8在屏幕上显示信息],[=9即1+8,为播放提示声音并在屏幕上显示信息],[=12=4+8],[=13=1+4+8]Default="对应发生事件"=如果没有此字符串,不在设定(控制面板‘声音和提示’)中显示选项,但有其它定义例如[HKEY_CURRENT_USER/ControlPanel/Notifications/{A877D663-239C-47a7-9304-0D347F580408}]"Wave"="lowbatt""Duration"=dword:00000000"Options"=dword:00000009 此处为系统电力不足时候的声音事件[=9即1+8,为播放提示声音并在屏幕上显示信息],如果为了在系统电力不足的时候,不让屏幕上弹出显示信息,又要播放声音得知电力不足的信息,只要将其数值改为1即可,改为0太“危险”[电力不足,而自己仍然做卡上的程序重要操作而没有保存就麻烦了]上面的GUID指定了一类通知的物理效果,可以有不同的通知实例,体现在 SHNOTIFICATIONDATA 中的dwID值不同(有点像窗口类和窗口实例的关系)。 联系下面资料看,增加理解。 SHNotificationAdd

    This function adds a notification (asynchronously) to the notification tray.

    LRESULT SHNotificationAdd( SHNOTIFICATIONDATA * pndAdd);

    Parameters

    pndAdd Reference to the notification to be added.

    Return Values

    ERROR_SUCCESS indicates success.

    Remarks

    This API is called to add a notification to the tray. Notification processing is done asynchronously; that is, this function will return after adding the notification to the tray, and processing will happen on a different thread.(异步方式,添加到通知托盘与显示通知效果是由不同线程处理的)

    To customize the physical behaviour for a notification, create a CLSID for the notification class (passed into SHNotificationAdd), and create the registry key:

    [HKEY_CURRENT_USER/ControlPanel/Notifications/{CLSID}]@="Name" ; this is what appears in Settings - if you don't want to allow user customization, don't add this default value"Options"=dword:1 ; notification flags"Duration"=dword:0 ; duration in minutes of LED flashing"Wave"="wavefile" ; default is in the Windows folder. There is no extension on the file

    The following table lists the possible values for the Options parameter.

    Notification flagValueDescriptionNOTIF_SOUND0x00000001Sound notification.NOTIF_VIBRATE0x00000002Vibrate notification.NOTIF_FLASH0x00000004ROM notification.NOTIF_MESSAGE0x00000008Message notification. 引申的应用:更改低电提示的效果。 注册表找到 [HKEY_CURRENT_USER/ControlPanel/Notifications/{A877D663-239C-47a7-9304-0D347F580408}]项, 将 Default值改成任何名字(只要不为空,空的话在设置里不出现此项),比如“LowBattery”。然后便可以在“设置”--“声音和提醒”--“通知”--“事件”里找到LowBattery项,可以对此类型的通知做更改。比如:播放声音,在屏幕上显示信息(即弹出通知),震动,指示灯闪烁等。注册表里的键与控制面板里的选项是对应的。引申的应用2:弹出一个与低电处理效果类似的通知。 LRESULT SHNotificationAdd( SHNOTIFICATIONDATA * pndAdd);将SHNOTIFICATIONDATA 结构中的clsid项设置成{A877D663-239C-47a7-9304-0D347F580408}对应的GUID值,然后SHNotificationAdd即可。#define Noti_GUID L"{A877D663-239C-47a7-9304-0D347F580408}" GUID myGUID;// Parse the GUIDhr = CLSIDFromString(Noti_GUID, &myGUID);SHNOTIFICATIONDATA sn = {0};sn.cbStruct = sizeof(sn);sn.dwId = SAMPLE_ID_I;sn.clsid = myGUID;sn.npPriority = SHNP_INFORM;sn.csDuration = 5;sn.pszTitle = TEXT("Title");sn.pszHTML = TEXT("Test Notification")sn.grfFlags = SHNF_FORCEMESSAGE;SHNotificationAdd(&sn));其他事件声音和提醒:[HKEY_CURRENT_USER/ControlPanel/Notifications/{F55615D6-D29E-4db8-8C75-98125D1A7253}]"Wave"="Notify""Duration"=dword:00000000"Options"=dword:00000009Default="无线数据交换: 自动接收"[HKEY_CURRENT_USER/ControlPanel/Notifications/{A877D65D-239C-47a7-9304-0D347F580408}]"Wave"="online""Duration"=dword:00000003"Options"=dword:0000000d[HKEY_CURRENT_USER/ControlPanel/Notifications/{A877D659-239C-47a7-9304-0D347F580408}]"Wave"="Infend""Duration"=dword:00000000"Options"=dword:00000001"AvailableOptions"=dword:00000003Default="ActiveSync: 结束同步"[HKEY_CURRENT_USER/ControlPanel/Notifications/{A877D658-239C-47a7-9304-0D347F580408}]"Wave"="infbeg""Duration"=dword:00000000"Options"=dword:00000000"AvailableOptions"=dword:00000003Default="ActiveSync: 开始同步"[HKEY_CURRENT_USER/ControlPanel/Notifications/Reminders]"Wave"="Alarm1""Duration"=dword:0000000a"Options"=dword:4000000dDefault="提醒"[HKEY_CURRENT_USER/ControlPanel/Notifications/{8ddf46e8-56ed-4750-9e58-afc6ce486d03}]"Wave"="infend""Duration"=dword:00000000"Options"=dword:00000000[=1有声音=0无声音]"AvailableOptions"=dword:00000003Default="连接断开"[HKEY_CURRENT_USER/ControlPanel/Notifications/{8ddf46e7-56ed-4750-9e58-afc6ce486d03}]"Wave"="infbeg""Duration"=dword:00000000"Options"=dword:00000008"AvailableOptions"=dword:0000000bDefault="连接成功"[HKEY_CURRENT_USER/ControlPanel/Notifications/{0D3132C4-1298-469c-B2B8-F28CE2D649D0}]"Wave"="infbeg""Duration"=dword:00000000"Options"=dword:00000009[HKEY_CURRENT_USER/ControlPanel/Notifications/{A877D663-239C-47a7-9304-0D347F580408}]"Wave"="lowbatt""Duration"=dword:00000000"Options"=dword:00000009[HKEY_CURRENT_USER/ControlPanel/Notifications/Default]"LedRefCount"=dword:00000000"Wave"="default""Duration"=dword:00000005"Options"=dword:0000000d[HKEY_CURRENT_USER/ControlPanel/Notifications/Sounds]"Repeat"=dword:00000000[HKEY_CURRENT_USER/ControlPanel/Notifications/{A877D65A-239C-47a7-9304-0D347F580408}]"Wave"="notify""Duration"=dword:00000000"Options"=dword:00000009Default="收件箱: 新电子邮件"[HKEY_CURRENT_USER/ControlPanel/Notifications/{A877D65F-239C-47a7-9304-0D347F580408}]"Wave"="type""Duration"=dword:00000000"Options"=dword:00000009Default="MSN Messenger: 新消息"[HKEY_CURRENT_USER/ControlPanel/Notifications/{A877D65E-239C-47a7-9304-0D347F580408}]"Wave"="online""Duration"=dword:00000000"Options"=dword:00000001Default="MSN Messenger: 联系人联机"

    最新回复(0)