简体   繁体   中英

WinAPI: Can't completely get rid of window frame

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.

If you handle background painting yourself, you need to return 1 from your WM_ERASEBKGND handler. Something like this:

return 1L; // if in window procedure

or

return (INT_PTR)TRUE; // if in dialog box procedure

I also don't like the way you remove border. Try this instead.

It seems to me that you need splash screen but I haven't done that yet. Still this MSDN article could be exactly what you need.

If all fails, here are some other that can help you:

http://www.codeproject.com/Articles/15523/Own-thread-Win-splash-screen

http://www.codeproject.com/Articles/7658/CSplash-A-Splash-Window-Class

Quickest way to implement a C++ Win32 Splash Screen

http://code.logos.com/blog/2008/09/displaying_a_splash_screen_with_c_introduction.html

http://www.codeguru.com/cpp/wd/dislog/splashscreens/article.php/c5029/Adding-a-Splash-Screen-to-Your-Applications.htm

Hopefully this helps. Best regards and good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM