Tuesday, December 22, 2009

ViruZ update 1

Well, I don't know if I'm going to post frequently about it, but well.. yesterday I moved the stuff into my Window-class completely.

There is a more elegant solution to my messagepump-function, instead of using a fake singleton.
Of course, other people have had this problem, too. I googled and quickly found an article on GameDev about it. Using Set/GetWindowLong with GWL_USERDATA lets you store a pointer, which will be associated with a window. I'd explain it, but it's probably easier if you just read this. If you wanna use it, you'll have to modify it a bit. Check for GetWindowLong to return NULL, because the first message is not WM_NCCREATE, but WM_GETMINMAXINFO, which does not have the lpCreateParams.
I ran into some fun invalid pointers with this :)

I then fiddled around with getting my program to close when you hit alt+F4 or click the close-button. I also ran into some invalid pointers by destroying the window on WM_CLOSE, but still running the messagepump-loop.
Fixed that by not destroying the window and calling PostQuitMessage on WM_CLOSE and WM_DESTROY. I'm gonna make WM_DESTROY check, if WM_CLOSE got called before at some point.

That only half-way fixed the problem though. There are problems when the window is closed in specific points in code. WaitMessage waits for new events only, not unhanded ones. So if I call WaitMessage after the user has pressed the close-button it would not close. I actually have no idea where that event went though.. but it just seemed to disappear then.
I fixed that just a minute ago by putting my redraw-hack in a thread, rather than in the messagepump-loop.

No, I didn't fix it. Strange stuff, it does not work at all. It only works after you've moved the window o_O
After you've done that, it works like it should]

The only problem left is slight flickering. I just have to double-buffer it by hand, then it won't flicker I bet :)

note: that screenshot was shot yesterday

No comments: