{"id":307,"date":"2009-05-12T23:38:11","date_gmt":"2009-05-12T18:08:11","guid":{"rendered":"http:\/\/techtwaddle.net\/?p=307"},"modified":"2011-04-12T23:38:28","modified_gmt":"2011-04-12T18:08:28","slug":"applications-problems-with-static-text-control","status":"publish","type":"post","link":"https:\/\/techtwaddle.co.in\/blog\/2009\/05\/12\/applications-problems-with-static-text-control\/","title":{"rendered":"Applications: Problems with static text control"},"content":{"rendered":"<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\">Today at work, I was working on a small application with my colleague. We had dialog box with a button, an edit control and a static control. What we wanted to do was show the status of the program on the static control once the button was pressed. And the code looked something like this:<\/span><\/div>\n<p>\n<span style=\"font-family: Courier New; color: rgb(128, 0, 0);\">case WM_COMMAND:<\/span><br style=\"font-family: Courier New; color: rgb(128, 0, 0);\" \/><br \/>\n<span style=\"font-family: Courier New; color: rgb(128, 0, 0);\">{<\/span><br style=\"font-family: Courier New; color: rgb(128, 0, 0);\" \/><br \/>\n<span style=\"font-family: Courier New; color: rgb(128, 0, 0);\">&nbsp;&nbsp;&nbsp; wmID = LOWORD(wParam);<\/span><br style=\"font-family: Courier New; color: rgb(128, 0, 0);\" \/><br \/>\n<span style=\"font-family: Courier New; color: rgb(128, 0, 0);\">&nbsp;&nbsp;&nbsp; wmEvent = HIWORD(wParam);<\/span><br style=\"font-family: Courier New; color: rgb(128, 0, 0);\" \/><br \/>\n<span style=\"font-family: Courier New; color: rgb(128, 0, 0);\">&nbsp;&nbsp;&nbsp; switch(wmID)<\/span><br style=\"font-family: Courier New; color: rgb(128, 0, 0);\" \/><br \/>\n<span style=\"font-family: Courier New; color: rgb(128, 0, 0);\">&nbsp;&nbsp;&nbsp; {<\/span><br style=\"font-family: Courier New; color: rgb(128, 0, 0);\" \/><br \/>\n<span style=\"font-family: Courier New; color: rgb(128, 0, 0);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case IDM_BUTTON_GMC:<\/span><br style=\"font-family: Courier New; color: rgb(128, 0, 0);\" \/><br \/>\n<span style=\"font-family: Courier New; color: rgb(128, 0, 0);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<\/span><br style=\"font-family: Courier New; color: rgb(128, 0, 0);\" \/><br \/>\n<span style=\"font-family: Courier New; color: rgb(128, 0, 0);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetWindowText(GetDlgItem(hDlg, IDC_STATIC_STATUS), L&quot;In progress..&quot;);<\/span><br style=\"font-family: Courier New; color: rgb(128, 0, 0);\" \/><br \/>\n<br style=\"font-family: Courier New; color: rgb(128, 0, 0);\" \/><br \/>\n<span style=\"font-family: Courier New; color: rgb(128, 0, 0);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/*<\/span><br style=\"font-family: Courier New; color: rgb(128, 0, 0);\" \/><br \/>\n<span style=\"font-family: Courier New; color: rgb(128, 0, 0);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Do some work<\/span><br style=\"font-family: Courier New; color: rgb(128, 0, 0);\" \/><br \/>\n<span style=\"font-family: Courier New; color: rgb(128, 0, 0);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *\/<\/span><br style=\"font-family: Courier New; color: rgb(128, 0, 0);\" \/><br \/>\n<br style=\"font-family: Courier New; color: rgb(128, 0, 0);\" \/><br \/>\n<span style=\"font-family: Courier New; color: rgb(128, 0, 0);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetWindowText(GetDlgItem(hDlg, IDC_STATIC_STATUS), L&quot;Done.&quot;);<\/span><br style=\"font-family: Courier New; color: rgb(128, 0, 0);\" \/><br \/>\n<span style=\"font-family: Courier New; color: rgb(128, 0, 0);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/span><br style=\"font-family: Courier New; color: rgb(128, 0, 0);\" \/><br \/>\n<span style=\"font-family: Courier New; color: rgb(128, 0, 0);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<\/span><br style=\"font-family: Courier New; color: rgb(128, 0, 0);\" \/><br \/>\n<span style=\"font-family: Courier New; color: rgb(128, 0, 0);\">&nbsp;&nbsp;&nbsp; }<\/span><br style=\"font-family: Courier New; color: rgb(128, 0, 0);\" \/><br \/>\n<span style=\"font-family: Courier New; color: rgb(128, 0, 0);\">&nbsp;&nbsp;&nbsp; .<\/span><br style=\"font-family: Courier New; color: rgb(128, 0, 0);\" \/><br \/>\n<span style=\"font-family: Courier New; color: rgb(128, 0, 0);\">&nbsp;&nbsp;&nbsp; .<\/span><br style=\"font-family: Courier New; color: rgb(128, 0, 0);\" \/><br \/>\n<span style=\"font-family: Courier New; color: rgb(128, 0, 0);\">&nbsp;&nbsp;&nbsp; .<\/span><br style=\"font-family: Courier New; color: rgb(128, 0, 0);\" \/><br \/>\n<span style=\"font-family: Courier New; color: rgb(128, 0, 0);\">}<\/span><br style=\"color: rgb(128, 0, 0);\" \/><br \/>\n<span style=\"font-family: Courier New; color: rgb(128, 0, 0);\">break;<\/span><\/p>\n<div style=\"text-align: justify; font-family: Comic Sans MS;\">The default text on the static control was blank. When I ran the program we noticed that the static control never displayed &quot;In Progress..&quot;. After finishing the actual meat of the job, the static control displayed &quot;Done&quot;. We wondered whether it was because the actual work was happening too fast, and we put a sleep of 1 second after the first <span style=\"font-family: Courier New;\">SetWindowText()<\/span> call, but it didn&#8217;t solve the problem. We sat wondering about why this was happening. We checked the return value of the first <span style=\"font-family: Courier New;\">SetWindowText <\/span>call and it was non-zero which meant the call was successful. Another colleague of ours walked by and we explained the problem to her briefly, and she stared for a moment and said, <span style=\"font-family: Courier New;\">UpdateWindow<\/span>. And we all went &quot;Aww&#8230;&quot;. So we put <span style=\"font-family: Courier New;\">UpdateWindow(GetDlgItem(hDlg, IDC_STATIC_STATUS));<\/span> after both the calls and it worked, as expected. Painting is one of the most costliest operation and runs at a very low priority. So no wonder the calls before weren&#8217;t updating the text immediately. Sometimes we are all so occupied with bigger things that we miss out on the small ones.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Today at work, I was working on a small application with my colleague. We had dialog box with a button, an edit control and a static control. What we wanted to do was show the status of the program on the static control once the button was pressed. And the code looked something like this: &hellip; <a href=\"https:\/\/techtwaddle.co.in\/blog\/2009\/05\/12\/applications-problems-with-static-text-control\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Applications: Problems with static text control<\/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-4X","_links":{"self":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/307"}],"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=307"}],"version-history":[{"count":1,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/307\/revisions"}],"predecessor-version":[{"id":308,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/307\/revisions\/308"}],"wp:attachment":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/media?parent=307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/categories?post=307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/tags?post=307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}