Debugging WM_PAINT messages
It’s always irritating to debug paint messages and sometimes expensive too. I’ve tried different methods to try debug painting issues, always ended up disappointed.
Why is it such a pain to debug WM_PAINT messages?
Main reason is, we are not in control. Paint messages comes via a window framework. Painting is done whenever a window gains focus or is activated this means our application will never get focus if we set a breakpoint in an OnPaint function because as soon as our application comes to focus it again sends a repaint request which again breaks into the OnPaint function.
It’s can be expensive too because we’ll need some kind of a dual monitor setup. So that our application runs on one monitor and the debugger on the other. For professional game/UI developers it’s ok because that’s their job and they will always need such a setup. But guys like me cannot affort such a setup.
Yes, that’s the good news. Windows explorer has a cute feature called “Tile Horizontally” and “Tile Vertically”. It also has another feature to select taskbar items using control key.
So this is how a standar taskbar looks, as you already know that at a time, in windows, only one window can be active.
The tab having a dark shade is the one that’s active, and if you right click on this tab you’ll get a context menu which will correspond to the active application’s system menu.
Now here is the interesting part use ‘Ctrl’ key to select multiple tabs. Press ‘Ctrl’ and then use your mouse to click on tabs you wanna select and then right click on any of these selected tabs and see what you get! Here is a screenshot of what I get…
These menu items are interesting, most windows users are unaware of this option, it’s a quick way to arrange your windows. You can try them one by one. Note that there is an option to close a group too. 🙂
So returning back to our original discussion, we now apply this trick to our application. We are going to select visual studio and an application that’s being debugged. I’ve set a break point in the OnPaint function.
So we select both applications in the taskbar using ‘Ctrl’ key and mouse and then right click and select ‘Tile vertically’ or ‘Tile Horizontally’. I would select ‘Tile vertically’ as it would give me enough vertical space but you can decide what’s best for you. Eventually what I get is a screen like this with two windows that doesn’t overlap each other. One of them is visual studio and the other one is my application that’s being debugged, also note that I’ve set a breakpoint in OnPaint function. Both applications behave independently without interfering with each other.
Now my desktop acts like a dual monitor setup. 😉 It’s kinda cool for debugging purpose and yeah I agree this is not the ultimate solution but it’s quite useful. Hope this helps you. 🙂
The Old Rugged Cross
Copyright and Disclaimer
Disclaimer: These postings are provided "AS IS" with no warranties, and confer no rights.
- .net (4)
- Announcements (3)
- ATL (2)
- C Programming (9)
- C++, VC++ (71)
- STL (5)
- CodeProject (1)
- COM (15)
- Debugging (7)
- Development Tools (5)
- General (10)
- HTML (1)
- MFC (51)
- My thoughts (3)
- Networking (1)
- Polls (2)
- Strange bugs (5)
- Undocumented WinAPI (5)
- Visual studio (20)
- Windows (8)
- Windows API (175)