Calculating window size based on bitmap and titlebar/border?
-
Hi, I have a program that generates a window depending on user settings. The window contains a bitmap that the user selects, and can have various border types (dialog, client edge, no border), and may or may not have a title bar. The window is supposed to be the size of the bitmap that is selected. However, I have just realised that my window size does not take account of the titlebar or border of the window. For instance, I calculate my window position and size like this currently:
BITMAP BMPSize; HBITMAP SizeCheckBMP; .... GetObject(SizeCheckBMP,sizeof(BMPSize), &BMPSize); .... //center window in screen: xpos = (GetSystemMetrics(SM_CXSCREEN)/2)-(BMPSize.bmWidth/2); ypos = (GetSystemMetrics(SM_CYSCREEN)/2)-(BMPSize.bmHeight/2); //calculate dimensions: width = BMPSize.bmWidth; height = BMPSize.bmHeight; .... myWnd = CreateWindowEx( WS_EX_TOOLWINDOW, "my_win_class", WS_DLGFRAME, NULL, xpos, ypos, width, height, NULL, NULL, hInst NULL);
The problem here is, suppose the bitmap is 640x480 pixels in size - the window created by this code will be exactly that size too, which doesn't work if there is a title bar and border, as these will be included in these dimensions. So the bottom of the bitmap will be cut off by the exact number of pixels that the titlebar takes up, or the right and bottom of the bitmap will be cut off by the number of pixels that the dialog frame border takes up. I hope that makes sense. Could someone please suggest a better way of calculating my window size so that it sizes itself to exactly fit whole of the bitmap, plus the title bar and border? Many thanks for any help, KB -
Hi, I have a program that generates a window depending on user settings. The window contains a bitmap that the user selects, and can have various border types (dialog, client edge, no border), and may or may not have a title bar. The window is supposed to be the size of the bitmap that is selected. However, I have just realised that my window size does not take account of the titlebar or border of the window. For instance, I calculate my window position and size like this currently:
BITMAP BMPSize; HBITMAP SizeCheckBMP; .... GetObject(SizeCheckBMP,sizeof(BMPSize), &BMPSize); .... //center window in screen: xpos = (GetSystemMetrics(SM_CXSCREEN)/2)-(BMPSize.bmWidth/2); ypos = (GetSystemMetrics(SM_CYSCREEN)/2)-(BMPSize.bmHeight/2); //calculate dimensions: width = BMPSize.bmWidth; height = BMPSize.bmHeight; .... myWnd = CreateWindowEx( WS_EX_TOOLWINDOW, "my_win_class", WS_DLGFRAME, NULL, xpos, ypos, width, height, NULL, NULL, hInst NULL);
The problem here is, suppose the bitmap is 640x480 pixels in size - the window created by this code will be exactly that size too, which doesn't work if there is a title bar and border, as these will be included in these dimensions. So the bottom of the bitmap will be cut off by the exact number of pixels that the titlebar takes up, or the right and bottom of the bitmap will be cut off by the number of pixels that the dialog frame border takes up. I hope that makes sense. Could someone please suggest a better way of calculating my window size so that it sizes itself to exactly fit whole of the bitmap, plus the title bar and border? Many thanks for any help, KBCheck out
AdjustWindowRectEx()
--Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber #include "witty-quote.h" -
Hi, I have a program that generates a window depending on user settings. The window contains a bitmap that the user selects, and can have various border types (dialog, client edge, no border), and may or may not have a title bar. The window is supposed to be the size of the bitmap that is selected. However, I have just realised that my window size does not take account of the titlebar or border of the window. For instance, I calculate my window position and size like this currently:
BITMAP BMPSize; HBITMAP SizeCheckBMP; .... GetObject(SizeCheckBMP,sizeof(BMPSize), &BMPSize); .... //center window in screen: xpos = (GetSystemMetrics(SM_CXSCREEN)/2)-(BMPSize.bmWidth/2); ypos = (GetSystemMetrics(SM_CYSCREEN)/2)-(BMPSize.bmHeight/2); //calculate dimensions: width = BMPSize.bmWidth; height = BMPSize.bmHeight; .... myWnd = CreateWindowEx( WS_EX_TOOLWINDOW, "my_win_class", WS_DLGFRAME, NULL, xpos, ypos, width, height, NULL, NULL, hInst NULL);
The problem here is, suppose the bitmap is 640x480 pixels in size - the window created by this code will be exactly that size too, which doesn't work if there is a title bar and border, as these will be included in these dimensions. So the bottom of the bitmap will be cut off by the exact number of pixels that the titlebar takes up, or the right and bottom of the bitmap will be cut off by the number of pixels that the dialog frame border takes up. I hope that makes sense. Could someone please suggest a better way of calculating my window size so that it sizes itself to exactly fit whole of the bitmap, plus the title bar and border? Many thanks for any help, KBUse
GetSystemMetrics
to get the height and/or width of the various window components, and add them to your dimension calculations.
[
](http://www.canucks.com)Sonork 100.11743 Chicken Little "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 Within you lies the power for good - Use it!
-
Check out
AdjustWindowRectEx()
--Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber #include "witty-quote.h" -
Use
GetSystemMetrics
to get the height and/or width of the various window components, and add them to your dimension calculations.
[
](http://www.canucks.com)Sonork 100.11743 Chicken Little "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 Within you lies the power for good - Use it!
Actually, Mike's method is better. ;)
**""It is impossible to rightly govern the world without God and the Bible." -- George Washington
-
Hey, I'll have to remember that one!:-D
[
](http://www.canucks.com)Sonork 100.11743 Chicken Little "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 Within you lies the power for good - Use it!
Here's some more info[^] on that API from RaymondC's blog[^] --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber #include "witty-quote.h"
-
Here's some more info[^] on that API from RaymondC's blog[^] --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber #include "witty-quote.h"