{"id":287,"date":"2008-07-23T00:11:49","date_gmt":"2008-07-23T00:11:49","guid":{"rendered":"http:\/\/dalelane.co.uk\/blog\/?p=287"},"modified":"2008-07-23T00:18:26","modified_gmt":"2008-07-23T00:18:26","slug":"improving-twittoday-more-today-screen-coding","status":"publish","type":"post","link":"https:\/\/dalelane.co.uk\/blog\/?p=287","title":{"rendered":"Improving TwitToday &#8211; more Today Screen coding"},"content":{"rendered":"<p><a href=\"http:\/\/www.flickr.com\/photos\/dalelane\/2387728775\/\" title=\"Twitter client for Windows Mobile by dalelane, on Flickr\"><img loading=\"lazy\" decoding=\"async\" hspace=\"10\" vspace=\"10\" align=\"left\" src=\"http:\/\/farm3.static.flickr.com\/2088\/2387728775_9ab57ee5fa_m.jpg\" width=\"155\" height=\"240\" alt=\"Twitter client for Windows Mobile\" \/><\/a>Apart from <a href=\"http:\/\/dalelane.co.uk\/blog\/?p=261\">adding the ability to initiate an internet connection<\/a>, my <a href=\"http:\/\/dalelane.co.uk\/blog\/?p=244\">Twitter widget for Windows Mobile<\/a> Today screens is still virtually the same code as I wrote in a few hours overnight at the <a target=\"_blank\" href=\"http:\/\/overtheair.org\/blog\/\">Over The Air<\/a> hackday.<\/p>\n<p>Which isn&#8217;t great &#8211; as I know there have been a bunch of people waiting for me to make some fixes and add some basic features. <\/p>\n<p>Tonight I had a bit of time to spare, so I finally dug out the code to start making a few improvements:<\/p>\n<ul>\n<li><strong>Background worker thread<\/strong><br \/>\nToday screen widgets are compiled into DLLs. They aren&#8217;t a separate executable, and are run by the Today Screen in the Today screen&#8217;s (i.e. explorer.exe&#8217;s) flow of execution. When the code tries to post to twitter.com, explorer can&#8217;t do anything else until that&#8217;s finished. <\/p>\n<p>That might even be tolerable with most websites, but with twitter &#8211; which is known to fall over from time to time! &#8211; it means TwitToday could effectively hang your phone for ages until the HTTP post timed-out. <\/p>\n<p>Not good. Now it does all the HTTP work in a background thread, so you can get on with other stuff while it tries to send your tweet.\n<\/li>\n<li><strong>SIP support<\/strong><br \/>\nThis was asked for a lot. The Today screen doesn&#8217;t include the button to show\/hide the on-screen stylus\/finger keyboard. So if your mobile doesn&#8217;t have a keyboard, TwitToday wasn&#8217;t much use.<\/p>\n<p>I&#8217;ve added a setting now that lets you programmatically show the SIP keyboard when you tap on the text box.\n<\/li>\n<\/ul>\n<p>If you want to try the new version, you can <a href=\"http:\/\/dalelane.co.uk\/files\/TwitToday.CAB\">download it from here<\/a>. If you want to see how I did it, read on. <\/p>\n<p><!--more--><strong>Background<\/strong><br \/>\n<a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb202727.aspx\" target=\"_blank\">This is easy<\/a>&#8230;<\/p>\n<pre style=\"font-size: 0.9em; border: thin solid silver; background-color: #eeeeee; padding: 0.8em\"><code>g_hThread = CreateThread(NULL,\r\n                         0,\r\n                         (LPTHREAD_START_ROUTINE)SubmitTweetThread,\r\n                         NULL,\r\n                         0,\r\n                         &dwID[0]);<\/code><\/pre>\n<p><strong>Showing the SIP<\/strong><br \/>\n<a target=\"_blank\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms838341.aspx\">Showing and hiding the SIP<\/a> is straightforward &#8211; just leaving some work to figure out the right time to do it. <\/p>\n<p>This gives us:<\/p>\n<pre style=\"font-size: 0.9em; border: thin solid silver; background-color: #eeeeee; padding: 0.8em\"><code>case WM_COMMAND: \r\n    switch(HIWORD(wParam))\r\n    {\r\n        case BN_CLICKED:\r\n            if (LOWORD(wParam) == ID_MYBUTTON)\r\n            {\r\n                DWORD dwID[1];\r\n                DWORD dwRetVal = 0;\r\n                \r\n                if (g_hThread != NULL)\r\n                {\r\n                    CloseHandle(g_hThread);\r\n                }\r\n\r\n                g_hThread = CreateThread(NULL,\r\n                                         0,\r\n                                         (LPTHREAD_START_ROUTINE)\r\n                                              SubmitTweetThread,\r\n                                         NULL,\r\n                                         0,\r\n                                         &dwID[0]);\r\n\r\n                if (g_bNeedsSIP)\r\n                {\r\n                    SipShowIM(SIPF_OFF);\r\n                }\r\n            }\r\n            break;\r\n        case WM_KEYDOWN:\r\n            if (g_bNeedsSIP && (LOWORD(wParam) == ID_MYTEXTBOX))\r\n            {\t\t\t\t\t\r\n                SipShowIM(SIPF_ON);\r\n            }\r\n            break;\r\n    }\r\n    break;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Apart from adding the ability to initiate an internet connection, my Twitter widget for Windows Mobile Today screens is still virtually the same code as I wrote in a few hours overnight at the Over The Air hackday. Which isn&#8217;t great &#8211; as I know there have been a bunch of people waiting for me [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[244,146,245,151,243,19,43],"class_list":["post-287","post","type-post","status-publish","format-standard","hentry","category-code","tag-createthread","tag-overtheair","tag-sip","tag-twitter","tag-twittoday","tag-windows-mobile","tag-windowsmobile"],"_links":{"self":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/287","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=287"}],"version-history":[{"count":0,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/287\/revisions"}],"wp:attachment":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}