I want to make an application where I'd paint on the entire window. I use GDI+ for that purpose. Since I don't need it to have any border, I disabled it with SetWindowLong function, getting rid of any styles that would make it have a frame, like this:
SetWindowLong(hwnd, GWL_STYLE, 0);
It works fine as long as I don't try to actually paint something on that window myself. I tried processing WM_PAINT
messages, WM_ERASEBKGND
messages, even WM_NCPAINT
(it doesn't do much though), but for some reason there's always some remaining of a border, or at least it looks like it. Something like this:
As you can see, there is a black rectangle with some kind of the frame at its bottom and right sides. It looks like the border was not completely drawn here, though it shouldn't be painted at all. The image here is just a blank black bitmap, but the problem is the same for normal pictures as well. It doesn't look the same for all messages I tried to process, but the result is pretty much identical - it ends up drawing some additional rubbish, as if it tires to draw damn frame no matter what.
This is how I process messages:
case WM_ERASEBKGND:
{
drawer->DrawImage(image, 0, 0, width, height);
return 0;
}
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint( hwnd, & ps );
drawer->DrawImage(image, 0, 0, width, height);
EndPaint(hwnd, &ps);
return 0;
}
A drawer
variable is a pointer to Gdiplus::Graphics
class object, image
is a pointer to Gdiplus::Bitmap
object. I do believe these objects are valid since normal pictures loaded from files are shown properly (except for that damn frame).
It works fine if I enable styles that enable drawing window's frame, but I don't want to do that. I run out of ideas though and don't really know what to do. Never coding win32 apps staying up so late in the night.
EDIT: apparently the problem was in drawer
variable after all. I figured that creating a Gdiplus::Graphics
object once and associate it with window handle would be a good idea. But for some reason it looks like it doesn't get a new device context from associated window when it needs to (propably it just gets it once and then doesn't bother about it). So I tried creating a new object every time I want to paint something on the window and the rubbish's gone!
Anyway thanks for everyone who commented and tried to help, I really appreciate it.