{"id":239,"date":"2009-09-12T23:17:18","date_gmt":"2009-09-12T17:47:18","guid":{"rendered":"http:\/\/techtwaddle.net\/?p=239"},"modified":"2011-04-12T23:17:42","modified_gmt":"2011-04-12T17:47:42","slug":"applications-running-an-application-when-a-specified-event-occurs","status":"publish","type":"post","link":"https:\/\/techtwaddle.co.in\/blog\/2009\/09\/12\/applications-running-an-application-when-a-specified-event-occurs\/","title":{"rendered":"Applications: Running an application when a specified event occurs"},"content":{"rendered":"<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\">Recently, I saw a video by Jim Wilson on running applications at specific events. He used <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms908102.aspx\"><span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">CeRunAppAtEvent()<\/span><\/a> native api, from managed code, to register an application to run when the device wakes up. Lets look at the API,<\/span><\/div>\n<p><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">BOOL CeRunAppAtEvent(TCHAR *pwszAppName, LONG lWhichEvent);<\/span><\/p>\n<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\"><span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">pwszAppName<\/span>: string which specifies the name of the application to be started. This string can also specify a named event. In <\/span><span style=\"font-family: Comic Sans MS;\">case of a named event, the event will be opened and signaled. The named event should be of the format:<\/span><\/div>\n<p><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&quot;\\\\\\\\.\\\\Notofications\\\\NamedEvents\\\\Event Name&quot;<\/span><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Comic Sans MS;\">&quot;<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">Event Name<\/span>&quot; is the application defined event name<\/span><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Comic Sans MS;\"><span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">lWhichEvent<\/span>: Specifies the event at which the application has to be started, it can take the following values,<\/span><\/p>\n<table cellspacing=\"0\" cellpadding=\"0\" border=\"1\" style=\"background-color: rgb(204, 204, 204); width: 722px; height: 677px;\">\n<tbody>\n<tr>\n<td>\n<p>NOTIFICATION_EVENT_DEVICE_CHANGE<\/p>\n<\/td>\n<td>\n<p>&nbsp;A PC Card device changed.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>NOTIFICATION_EVENT_INTERNET_PROXY_CHANGE<\/p>\n<\/td>\n<td>\n<p>&nbsp;The Internet Proxy used by the device has changed.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>NOTIFICATION_EVENT_IR_DISCOVERED<\/p>\n<\/td>\n<td>\n<p>&nbsp;The device discovered a server by using infrared  communications.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>NOTIFICATION_EVENT_NET_CONNECT<\/p>\n<\/td>\n<td>\n<p>&nbsp;The device connected to a network.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>NOTIFICATION_EVENT_NET_DISCONNECT<\/p>\n<\/td>\n<td>\n<p>&nbsp;The device disconnected from a network.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>NOTIFICATION_EVENT_NONE<\/p>\n<\/td>\n<td>\n<p>&nbsp;No events occurred. Remove all event registrations for this  application.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>NOTIFICATION_EVENT_OFF_AC_POWER<\/p>\n<\/td>\n<td>\n<p>&nbsp;The user turned the alternating current (AC) power off.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>NOTIFICATION_EVENT_ON_AC_POWER<\/p>\n<\/td>\n<td>\n<p>&nbsp;The user turned the AC power on.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>NOTIFICATION_EVENT_RESTORE_END<\/p>\n<\/td>\n<td>\n<p>&nbsp;A full device data restore completed.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>NOTIFICATION_EVENT_RNDIS_FN_DETECTED<\/p>\n<\/td>\n<td>\n<p>&nbsp;RNDISFN interface is instantiated.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>NOTIFICATION_EVENT_RS232_DETECTED<\/p>\n<\/td>\n<td>\n<p>&nbsp;An RS232 connection was made.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>NOTIFICATION_EVENT_SYNC_END<\/p>\n<\/td>\n<td>\n<p>&nbsp;Data synchronization finished.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>NOTIFICATION_EVENT_TIME_CHANGE<\/p>\n<\/td>\n<td>\n<p>&nbsp;The system time changed.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>NOTIFICATION_EVENT_TZ_CHANGE<\/p>\n<\/td>\n<td>\n<p>&nbsp;The time zone changed.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>NOTIFICATION_EVENT_WAKEUP<\/p>\n<\/td>\n<td>\n<p>&nbsp;The device woke up.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\"><span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">NOTIFICATION_EVENT_NONE<\/span> unregisters all the events associated with that application.<\/span><\/div>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\">I have the following two functions,<\/span><\/div>\n<p><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">void RegisterApp()<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">{<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; BOOL ret;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; ret = CeRunAppAtEvent(TEXT(&quot;\\\\Windows\\\\BubbleBreaker.exe&quot;), NOTIFICATION_EVENT_WAKEUP);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; if(!ret)<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; {<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;RegisterApp:CeRunAppAtEvent failed, err:0x%x\\r\\n&quot;, GetLastError());<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; }<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">}<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">void UnRegisterApp()<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">{<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; BOOL ret;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; ret = CeRunAppAtEvent(TEXT(&quot;\\\\Windows\\\\BubbleBreaker.exe&quot;), NOTIFICATION_EVENT_NONE);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; if(!ret)<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; {<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;UnRegisterApp:CeRunAppAtEvent failed, err:0x%x\\r\\n&quot;, GetLastError());<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; }<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">}<\/span><br style=\"font-family: Comic Sans MS;\" \/>\n<\/p>\n<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\">So, whenever the device wakes up from sleep, the BubbleBreaker game will start. To simulate a device sleep and wake up on the emulator, select <span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">File -&gt; Save State and Exit<\/span> from the Emulator menu. To wake the device up, select <span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">Tools -&gt; Connect to Device&#8230;<\/span> from Visual Studio (2005).<\/span><\/p>\n<p><span style=\"font-family: Comic Sans MS;\">Here&#8217;s a video for you folks,<\/span><\/p>\n<p><object width=\"560\" height=\"340\"><param name=\"movie\" value=\"http:\/\/www.youtube.com\/v\/X3spP-nKT2k&amp;hl=en&amp;fs=1&amp;\" \/><param name=\"allowFullScreen\" value=\"true\" \/><param name=\"allowscriptaccess\" value=\"always\" \/><\/object> \n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Recently, I saw a video by Jim Wilson on running applications at specific events. He used CeRunAppAtEvent() native api, from managed code, to register an application to run when the device wakes up. Lets look at the API, BOOL CeRunAppAtEvent(TCHAR *pwszAppName, LONG lWhichEvent); pwszAppName: string which specifies the name of the application to be started. &hellip; <a href=\"https:\/\/techtwaddle.co.in\/blog\/2009\/09\/12\/applications-running-an-application-when-a-specified-event-occurs\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Applications: Running an application when a specified event occurs<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[1],"tags":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1ktFF-3R","_links":{"self":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/239"}],"collection":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/comments?post=239"}],"version-history":[{"count":1,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/239\/revisions"}],"predecessor-version":[{"id":240,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/239\/revisions\/240"}],"wp:attachment":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/media?parent=239"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/categories?post=239"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/tags?post=239"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}