{"id":305,"date":"2009-05-12T23:37:44","date_gmt":"2009-05-12T18:07:44","guid":{"rendered":"http:\/\/techtwaddle.net\/?p=305"},"modified":"2011-04-12T23:38:03","modified_gmt":"2011-04-12T18:08:03","slug":"applications-problems-with-painting-dialogbox","status":"publish","type":"post","link":"https:\/\/techtwaddle.co.in\/blog\/2009\/05\/12\/applications-problems-with-painting-dialogbox\/","title":{"rendered":"Applications: Problems with painting DialogBox"},"content":{"rendered":"<div style=\"text-align: justify; font-family: Comic Sans MS;\">Today I was working on an application with a colleague. The application contained many dialogs, well, it was a settings related app which let the user perform and view all sort of settings on the phone. The application was medium sized with the original code very badly written. And we were supposed to clean up the code and change the look and feel of the various Dialogs used in the app. And also make sure that the same code base worked on both Standard and Professional devices, when compiled with different flags of course. We were almost through most of the things but one problem kept bothering us for a long time. One of the dialogs in the app never displayed correctly. And it was strange because it was exactly the same as other dialogs. The DialogProc of the dialog looked something like this:<\/div>\n<p>\n<span style=\"font-family: Courier New; color: rgb(128, 0, 0);\">BOOL CALLBACK DlgProc((HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam)<\/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; BOOL fRet = FALSE;<\/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(uMessage)<\/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 WM_INITDIALOG:<\/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; \/*<\/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 SHInitDialog()<\/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<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 SHCreateMenuBar()<\/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<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; Setup controls in the dialog<\/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<span style=\"font-family: Courier New; color: rgb(128, 0, 0);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return TRUE;<\/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<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 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);\">&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; \/*<\/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; Handle all controls here<\/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<span style=\"font-family: Courier New; color: rgb(128, 0, 0);\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return TRUE;<\/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<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 WM_ACTIVATE:<\/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; \/*<\/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 stuff<\/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<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<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 WM_PAINT:<\/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; hdc = BeginPaint(hDlg, &amp;ps);<\/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; EndPaint(hDlg, &amp;ps);<\/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<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 WM_CLOSE:<\/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; EndDialog(hDlg, uMessage);<\/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<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; fRet = TRUE;<\/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; return fRet;<\/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><\/p>\n<div style=\"text-align: justify; font-family: Comic Sans MS;\">Well, the code was a lot more messy than is shown here. Anyways, we sat wondering why only this dialog was not getting displayed properly. The background of the dialog was not at all drawn and the controls on the dialog appeared shabbily. We thought that a certain sequence of events caused the dialog to be displayed that way, so we tried calling the dialog from different places but the result still the same. We checked and compared the dialog properties of various dialogs with this one. They were insignificantly different but we still tried to make them exactly same, but still no luck yet. After about 2 hours I noticed the return value of the dialog proc and saw that it was always returning true no matter what. And I knew. How in the silly world can I miss such an important thing for this long! The return value of a dialog proc is a really important thing. Returning <span style=\"font-family: Courier New;\">TRUE <\/span>from the function means that you have handled the message and the OS may or may not take further action, mostly it wont. Returning <span style=\"font-family: Courier New;\">FALSE <\/span>would tell the OS that you have not handled the message and the OS would now handle the message and execute the default handling for that message. Why our dialog was not getting displayed correctly was that, we were returning <span style=\"font-family: Courier New;\">TRUE <\/span>for all messages, including <span style=\"font-family: Courier New;\">WM_PAINT<\/span>. So the OS thought that I have handled the paint message it does not need to take any action. And that is why there were problems in painting the dialog. We changed the return value to be <span style=\"font-family: Courier New;\">TRUE <\/span>or <span style=\"font-family: Courier New;\">FALSE <\/span>depending on whether we handled that message or not and it worked.<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I was working on an application with a colleague. The application contained many dialogs, well, it was a settings related app which let the user perform and view all sort of settings on the phone. The application was medium sized with the original code very badly written. And we were supposed to clean up &hellip; <a href=\"https:\/\/techtwaddle.co.in\/blog\/2009\/05\/12\/applications-problems-with-painting-dialogbox\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Applications: Problems with painting DialogBox<\/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-4V","_links":{"self":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/305"}],"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=305"}],"version-history":[{"count":1,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/305\/revisions"}],"predecessor-version":[{"id":306,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/305\/revisions\/306"}],"wp:attachment":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/media?parent=305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/categories?post=305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/tags?post=305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}