问题
i'm new to StackOverflow so forgive me for any stupid mistakes I make on the post.
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.
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='*'\"")
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
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)
Without Visual Styles http://postimg.org/image/hji8sa6j1/
With Visual Styles http://postimg.org/image/b733ig3gt/
Sorry for the links, still don't have enough reputation to post images.
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.
回答1:
Dont use a picture control. Draw directly on the dialog:
BOOL CALLBACK DialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam){
HDC hdc;
RECT rt;
switch (message){
case WM_PAINT:
GetWindowRect(hDlg, &rt);
hdc = GetWindowDC(hDlg);
StretchBlt(hdc, 0, 0, rt.right, rt.bottom, hdcMemBitmap, 0, 0, width, height, SRCCOPY);
ReleaseDc(hDlg, hdc);
break;
default: //for messages that we don't deal with
return false;
}
return false;
}
width
and height
are for the bitmaps width and height
.
valter
回答2:
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.
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.
来源:https://stackoverflow.com/questions/21940575/win32-dialog-based-borderless-window-with-bitmap-background-and-visual-styles