WM_QueryEndSession use WndProc not DefWndProc
Well this could become the most emberrasing thing this month I think. I added a handler for the WM_QUERYENDSESSION message. I override the DefWndProc method and the WM_QUERYENDSESSION message was never received. I thought it had something to do with the window not being the top window so I tried to hunt down the 'evil' code. The problem was there wasn't bad code at all.
After a few hours and removing/commenting out code the only executing code remaining was my message loop override and I still was amazed that I didn't get the WM_QUERYENDSESSION message. So I decided to create a new test project and added an override for WndProc and all worked as it should. Then I compared both source files and *finally* saw that I had overriden DefWndProc. I really don't know why I did that.. I think it is because I used intellisense, scrolled down and when I read DefWndProc I just smashed the tab key.
So watch out that you override WndProc and not DefWndProc when intercepting system messages!
Please leave a comment that I'm a complete dickhead. Thank you!