Finding the upper left coordinate of minimize button on the caption bar

Posted on 2005-04-21
Last Modified: 2010-04-05
How do I find the upper left coordinate of minimize button on the caption bar?
How can I determine the width of the bottom too?
Question by:jclobocar
    LVL 3

    Expert Comment

    you mean you have a form that is minimized and want to know where the X for closing it is?

    could you explain why you need it. maybe there is a workaround for solving your problem.
    LVL 1

    Author Comment

    I have a code to draw a "minimize to tray" button on caption bar, but depending on resolution or applied XP theme there is a overlap.
    If I knew where is the upper, left corner of the leftmost caption button (minimize), my button would be drawn in the correct place.
    LVL 11

    Expert Comment

    I think you may be able to use getsystemmetrics with the SM_CXSIZE, SM_CYSIZE settings which return the Width and height of a button in a window's caption or title bar, in pixels.

    i.e. GetSystemMetrics(SM_CXSIZE) should return the width of the minimize button

    you would then need to do the math to calculate which buttons are visible and multiply it by thre previous figure.

    Min andmax buttons are next to each other so just add 2 widths, the close button is I think 2 pixels gap form the min and max buttons so add that and another width for that button. then subtract that from the Total Form Width.


    LVL 26

    Accepted Solution

    The following calculations should give you what you are after (sample code follows the function code). I take no credit for the original code, as it comes from here:

    I only translated it from C-> Delphi


    function GetSysBtnPos(Handle: HWND): TPoint;
    var  dwStyle:       Integer;
         dwBtn:         Integer;
         dwSysBtn:      Integer;
         dwExStyle:     Integer;
         rcClient:      TRect;

         function CalcTopEdge(Style: Integer): Integer;
                if ((Style and WS_THICKFRAME) = WS_THICKFRAME) then

         function CalcRightEdge(Style: Integer): Integer;
                if ((Style and WS_THICKFRAME) = WS_THICKFRAME) then

         EDGE_SIZE       =  2;


      // Get window style and extended style
      dwStyle:=GetWindowLong(Handle, GWL_STYLE);
      dwExStyle:=GetWindowLong(Handle, GWL_EXSTYLE);

      // Get client rect for window
      GetClientRect(Handle, rcClient);

      // Set defaults

      // Calc top position

      // Check for tool window style
          if ((dwExStyle and WS_EX_TOOLWINDOW) = WS_EX_TOOLWINDOW) then
         dwSysBtn:=GetSystemMetrics(SM_CXSMSIZE) - EDGE_SIZE;
         if ((dwStyle and WS_SYSMENU) = WS_SYSMENU) then Inc(dwBtn, dwSysBtn + EDGE_SIZE);
                // Window has Close [X] button. This button has a 2-pixel border on either size
                if ((dwStyle and WS_SYSMENU) = WS_SYSMENU) then Inc(dwBtn, dwSysBtn + EDGE_SIZE);
                // If either of the minimize or maximize buttons are shown, then both will
         // appear (but may be disabled). This button pair has a 2 pixel border on the left
                if ((dwStyle and WS_MINIMIZEBOX) = WS_MINIMIZEBOX) or ((dwStyle and WS_MAXIMIZEBOX) = WS_MAXIMIZEBOX) then
            Inc(dwBtn, EDGE_SIZE + dwSysBtn * 2)
         else if ((dwStyle and WS_SYSMENU) = WS_SYSMENU) and ((dwExStyle and WS_EX_CONTEXTHELP) = WS_EX_CONTEXTHELP) then
                   // A window can have a question-mark button, but only if it doesn't have the
            // min / max buttons
                      Inc(dwBtn, EDGE_SIZE + dwSysBtn);

          // Now calculate the size of the border


    // Called from form1's button click
    procedure TForm1.Button1Click(Sender: TObject);
    var  ptSysBtn:      TPoint;
         hdcSelf:       HDC;

      SetPixel(hdcSelf, ptSysBtn.x, ptSysBtn.y, clBlack);


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
    Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now