Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Calculating window size based on bitmap and titlebar/border?

Calculating window size based on bitmap and titlebar/border?

Scheduled Pinned Locked Moved C / C++ / MFC
helpgraphicsquestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kayembi
    wrote on last edited by
    #1

    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

    M P 2 Replies Last reply
    0
    • K Kayembi

      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

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      Check out AdjustWindowRectEx() --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber #include "witty-quote.h"

      P 1 Reply Last reply
      0
      • K Kayembi

        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

        P Offline
        P Offline
        PJ Arends
        wrote on last edited by
        #3

        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!

        J 1 Reply Last reply
        0
        • M Michael Dunn

          Check out AdjustWindowRectEx() --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber #include "witty-quote.h"

          P Offline
          P Offline
          PJ Arends
          wrote on last edited by
          #4

          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!

          M 1 Reply Last reply
          0
          • P PJ Arends

            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!

            J Offline
            J Offline
            J Dunlap
            wrote on last edited by
            #5

            Actually, Mike's method is better. ;)

            **""It is impossible to rightly govern the world without God and the Bible." -- George Washington

            FLUID UI Toolkit**

            1 Reply Last reply
            0
            • P PJ Arends

              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!

              M Offline
              M Offline
              Michael Dunn
              wrote on last edited by
              #6

              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"

              K 1 Reply Last reply
              0
              • M Michael Dunn

                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"

                K Offline
                K Offline
                Kayembi
                wrote on last edited by
                #7

                Brilliant, thank you! Both suggestions work great, but I've used AdjustWindowRectEx because it requires less code... Thanks again, Keith

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups