{"id":113,"date":"2010-04-15T15:00:55","date_gmt":"2010-04-15T09:30:55","guid":{"rendered":"http:\/\/techtwaddle.net\/?p=113"},"modified":"2011-01-26T15:01:14","modified_gmt":"2011-01-26T09:31:14","slug":"how-to-show-wait-cursor-in-managed-and-native-code","status":"publish","type":"post","link":"https:\/\/techtwaddle.co.in\/blog\/2010\/04\/15\/how-to-show-wait-cursor-in-managed-and-native-code\/","title":{"rendered":"How to: Show wait cursor in managed and native code"},"content":{"rendered":"<p align=\"justify\"><img decoding=\"async\" loading=\"lazy\" width=\"36\" height=\"36\" border=\"0\" src=\"http:\/\/geekswithblogs.net\/images\/geekswithblogs_net\/TechTwaddle\/WindowsLiveWriter\/HowtoShowwaitcursorinmanagedandnativecod_11333\/WaitCursor_3.jpg\" alt=\"WaitCursor\" title=\"WaitCursor\" style=\"border: 0px none; display: inline;\" \/>&nbsp; Someone on the MSDN forum <a href=\"http:\/\/social.msdn.microsoft.com\/Forums\/en-US\/windowsmobiledev\/thread\/b63a1f9a-0535-4b59-b92e-f43f5143b498\">asked about<\/a> how to show a wait cursor, like when your application is loading or performing some (background) task. It&rsquo;s pretty simple to show the wait cursor in both managed and native code, and in this post we will see just how.     \n<\/p>\n<p><strong>Managed Code (C#)<\/strong><\/p>\n<p align=\"justify\">Set <font color=\"#000080\">Cursor.Current<\/font> to <font color=\"#000080\">Cursors.WaitCursor<\/font>, and call <font color=\"#000080\">Cursor.Show()<\/font>. And to come back to normal cursor, set <font color=\"#000080\">Cursor.Current<\/font> to <font color=\"#000080\">Cursors.Default<\/font> and call <font color=\"#000080\">Show()<\/font> again. Below is a button handler for a sample app that I made, (watch the video below)<\/p>\n<p><font color=\"#000080\">private void button1_Click(object sender, EventArgs e)      <br \/>\n{       <br \/>\n&nbsp;&nbsp;&nbsp; lblProgress.Text = &quot;Downloading ether&#8230;&quot;;       <br \/>\n&nbsp;&nbsp;&nbsp; lblProgress.Update(); <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp; Cursor.Current = Cursors.WaitCursor;      <br \/>\n&nbsp;&nbsp;&nbsp; Cursor.Show(); <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp; \/\/do some processing      <br \/>\n&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; 50; i++)       <br \/>\n&nbsp;&nbsp;&nbsp; {       <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; progressBar1.Value = 2 * (i + 1);       <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thread.Sleep(100);       <br \/>\n&nbsp;&nbsp;&nbsp; } <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp; Cursor.Current = Cursors.Default;      <br \/>\n&nbsp;&nbsp;&nbsp; Cursor.Show(); <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp; lblProgress.Text = &quot;Download complete.&quot;;      <br \/>\n&nbsp;&nbsp;&nbsp; lblProgress.Update();       <br \/>\n} <\/font><\/p>\n<p>\n<strong>Native Code<\/strong><\/p>\n<p align=\"justify\">In native code, call <font color=\"#000080\">SetCursor(LoadCursor(NULL, IDC_WAIT));<\/font> to show the wait cursor; and <font color=\"#000080\">SetCursor(LoadCursor(NULL, IDC_ARROW));<\/font> to come back to normal. The same button handler for native version of the app is below,<\/p>\n<p><font color=\"#000080\">case IDC_BUTTON_DOWNLOAD:      <br \/>\n&nbsp;&nbsp;&nbsp; {       <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HWND temp; <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; temp = GetDlgItem(hDlg, IDC_STATIC_PROGRESS);      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetWindowText(temp, L&quot;Downloading ether&#8230;&quot;);       <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UpdateWindow(temp); <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetCursor(LoadCursor(NULL, IDC_WAIT)); <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; temp = GetDlgItem(hDlg, IDC_PROGRESSBAR);      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i=0; i&lt;50; i++)       <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {       <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SendMessage(temp, PBM_SETPOS, (i+1)*2, 0);       <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sleep(100);       <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetCursor(LoadCursor(NULL, IDC_ARROW)); <\/font><\/p>\n<p><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; temp = GetDlgItem(hDlg, IDC_STATIC_PROGRESS);      <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetWindowText(temp, L&quot;Download Complete.&quot;);       <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UpdateWindow(temp);       <br \/>\n&nbsp;&nbsp;&nbsp; }       <br \/>\n&nbsp;&nbsp;&nbsp; break; <\/font><\/p>\n<p align=\"justify\">\nHere is a video of the sample app running. First the managed version is deployed and the native version next,     <\/p>\n<div class=\"wlWriterEditableSmartContent\" id=\"scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:dee19148-96e7-4f54-8e0f-57476da8c8d0\" style=\"padding: 0px; margin: 0px; display: inline; float: none;\">\n<div style=\"margin: 0px; padding: 0px; display: inline;\" id=\"82ffda29-9b9a-4781-a4f8-fcc008ba2353\">\n<div><a target=\"_new\" href=\"http:\/\/www.youtube.com\/watch?v=y83d_STxlA0&amp;hl=en_US&amp;fs=1&amp;color1=0x3a3a3a&amp;color2=0x999999\"><img decoding=\"async\" alt=\"\" onload=\"var downlevelDiv = document.getElementById('82ffda29-9b9a-4781-a4f8-fcc008ba2353'); downlevelDiv.innerHTML = &quot;&lt;div&gt;&lt;object width=\\&quot;425\\&quot; height=\\&quot;355\\&quot;&gt;&lt;param name=\\&quot;movie\\&quot; value=\\&quot;http:\/\/www.youtube.com\/v\/y83d_STxlA0&amp;hl=en_US&amp;fs=1&amp;color1=0x3a3a3a&amp;color2=0x999999&amp;hl=en\\&quot;&gt;&lt;\\\/param&gt;&lt;embed src=\\&quot;http:\/\/www.youtube.com\/v\/y83d_STxlA0&amp;hl=en_US&amp;fs=1&amp;color1=0x3a3a3a&amp;color2=0x999999&amp;hl=en\\&quot; type=\\&quot;application\/x-shockwave-flash\\&quot; width=\\&quot;425\\&quot; height=\\&quot;355\\&quot;&gt;&lt;\\\/embed&gt;&lt;\\\/object&gt;&lt;\\\/div&gt;&quot;;\" galleryimg=\"no\" style=\"border-style: none;\" src=\"http:\/\/geekswithblogs.net\/images\/geekswithblogs_net\/TechTwaddle\/WindowsLiveWriter\/HowtoShowwaitcursorinmanagedandnativecod_11333\/video4e99a1af8013.jpg\" \/><\/a><\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Someone on the MSDN forum asked about how to show a wait cursor, like when your application is loading or performing some (background) task. It&rsquo;s pretty simple to show the wait cursor in both managed and native code, and in this post we will see just how. Managed Code (C#) Set Cursor.Current to Cursors.WaitCursor, &hellip; <a href=\"https:\/\/techtwaddle.co.in\/blog\/2010\/04\/15\/how-to-show-wait-cursor-in-managed-and-native-code\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">How to: Show wait cursor in managed and native code<\/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-1P","_links":{"self":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/113"}],"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=113"}],"version-history":[{"count":1,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/113\/revisions"}],"predecessor-version":[{"id":114,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/113\/revisions\/114"}],"wp:attachment":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/media?parent=113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/categories?post=113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/tags?post=113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}