简体   繁体   English

WinAPI:无法完全摆脱窗口框架

[英]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. 我为此使用GDI +。 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函数将其禁用,摆脱了任何样式使其具有框架,如下所示:

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. 我尝试处理WM_PAINT消息, WM_ERASEBKGND消息,甚至是WM_NCPAINT (尽管处理不多),但是由于某种原因,总会残留一些边框,或者至少看起来像这样。 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. drawer变量是指向Gdiplus::Graphics类对象的指针, image是指向Gdiplus::Bitmap对象的指针。 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. 永远不要编码熬夜的win32应用程序。

EDIT: apparently the problem was in drawer variable after all. 编辑:显然问题出在毕竟drawer变量中。 I figured that creating a Gdiplus::Graphics object once and associate it with window handle would be a good idea. 我认为一次创建一个Gdiplus::Graphics对象并将其与窗口句柄相关联将是一个好主意。 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. 如果您自己处理背景画,则需要从WM_ERASEBKGND处理程序返回1 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. 仍然这篇MSDN文章可能正是您所需要的。

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/15523/Own-thread-Win-splash-screen

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

Quickest way to implement a C++ Win32 Splash Screen 实现C ++ Win32启动画面的最快方法

http://code.logos.com/blog/2008/09/displaying_a_splash_screen_with_c_introduction.html 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 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! 顺祝商祺!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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