基于Win32对话框的无边界窗口,具有位图背景和视觉样式 [英] Win32 dialog based borderless window with bitmap background and visual styles

查看:98
本文介绍了基于Win32对话框的无边界窗口,具有位图背景和视觉样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是StackOverflow的新手,所以请原谅我在帖子中犯的任何愚蠢错误.

i'm new to StackOverflow so forgive me for any stupid mistakes I make on the post.

我在使用Win32 API(无MFC)和基于对话框的应用程序创建具有位图背景的无边界窗口时遇到了问题.我正在使用Visual Studio 2010.

I'm having an issue to create a borderless window with a bitmap background using the Win32 API (no MFC) and a dialog based application. I'm using visual studio 2010.

仅当我使用Windows XP视觉样式(通过将公共控件lib与以下代码段链接)时,才会发生此问题:

The issue only happens if I use the windows XP Visual Styles, by linking the common controls lib with the following snippet:

  #pragma comment(linker, \
  "\"/manifestdependency:type='Win32' "\
  "name='Microsoft.Windows.Common-Controls' "\
  "version='6.0.0.0' "\
  "processorArchitecture='*' "\
  "publicKeyToken='6595b64144ccf1df' "\
  "language='*'\"")

我有一个简单的对话框,在其中有一个带位图图像的PictureControl,它将作为窗口的背景.我希望该图像填充整个窗口,不需要调整大小或拖放,因此我只是将其放在屏幕中央,并在我的RC文件中将对话框和优化校准的尺寸定义为相同,如下所示(两者的尺寸分别为356、210):

I have a simple dialog and inside it a PictureControl with a bitmap image that will be the background of the window. I want this image to fill the entire Window, no resize or drag and drop will be needed, so i just put it centered on screen and defined both the dialog and the Picture Control dimensions to be the same in my RC file as shown below (both with dimensions 356, 210):

//Main Dialog
IDD_DIALOG_MAIN DIALOGEX 0, 0, 356, 210
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
    //Picture Control
    CONTROL         103,IDC_PB_SPLASH,"Static",SS_BITMAP | SS_CENTERIMAGE | SS_REALSIZEIMAGE,0,0,356,210
    DEFPUSHBUTTON   "OK",IDOK,152,169,50,14
END

现在的问题是,当我使用视觉样式时,图像无法填充对话框窗口的整个区域.对话框的两侧都可以看到一个小的空白(如果删除SS_CENTERIMAGE,则在右侧是一个空白).没有视觉样式就不会发生这种情况.下面的图片显示了问题(这里使用的图像只是一个例子,实际的背景图像更加复杂,因此不能仅使用画笔绘画)

Now the issue is, when the I'm using the visual styles, the image doesn't fill the entire area of the dialog Window. A small white space can be seen on both sides of the dialog(if a remove the SS_CENTERIMAGE it's a white space on right side). This doesn't happen without the Visual Styles. The pictures below show the problem (The image used there is just an example, the actual background image is more complex, so just painting with a brush is not an option)

没有视觉样式 http://postimg.org/image/hji8sa6j1/

具有视觉样式 http://postimg.org/image/b733ig3gt/

对不起,这些链接仍然没有足够的声誉来发布图像.

Sorry for the links, still don't have enough reputation to post images.

关于如何使位图在启用了视觉样式的情况下填充整个窗口的任何建议?我通过melak47找到了一个很好的答案 https://stackoverflow.com/a/17713810/3022281 来制作无边界窗口,但是它不是基于对话框的.如果没有其他办法,我想我必须采用该解决方案.

Any suggestions on how to make the bitmap fill the entire window with visual styles enabled? I found this nice answer https://stackoverflow.com/a/17713810/3022281 by melak47 to making a borderless window but it's not dialog based. If nothing else works I guess I'll have to go with that solution.

推荐答案

经过大量的研究,我通过简单地在.RC代码中定义图像尺寸来使它工作,而该尺寸要比Visual Studio对话框编辑器少一点.允许我这么做.

After a lot of fussing around, I got it to work by simply defining the image dimensions in the .RC code a little less than what the Visual Studio Dialog editor allowed me to.

通过使用编辑器,如果将窗口边缘一直拉至图像宽度,或者将"Real Size Image"属性设置为true,则编辑器会得出尺寸(356,210),即启用视觉样式"时保留空白.我只是手动将宽度从356调整到353,空白消失了!因此,只是Visual Studio编辑器在启用视觉样式时计算出错误的尺寸.

By using the editor, if I pulled the Window Edges all the way down to the image width, or if I set the "Real Size Image" property to true, the editor came up with the dimensions (356,210), which was leaving the white space when Visual Styles were enabled. I just manually tuned the width down a little from 356 to 353 and the white space disappeared! So it was just Visual Studio Editor calculating the dimensions wrong for when the visual styles were enabled.

这篇关于基于Win32对话框的无边界窗口,具有位图背景和视觉样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆