Solved

Getting size of window caption buttons

Posted on 1997-10-13
13
724 Views
Last Modified: 2013-11-20
How to get size of the caption Minimixe, Maximize/Restore and Close button and space between Close and Restore buttons?
0
Comment
Question by:galkin
  • 5
  • 4
  • 2
  • +2
13 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1308060
Take a look at GetSystemMetrics()

SM_CXSMICON,
SM_CYSMICON
 Recommended dimensions, in pixels, of a small icon. Small icons typically appear in window captions and in small icon view.
 
SM_CXSMSIZE
SM_CYSMSIZE
 Dimensions, in pixels, of small caption buttons.
 

0
 
LVL 7

Author Comment

by:galkin
ID: 1308061
Yes GetSystemMetric() with SM_CXSMSIZE and SM_CYSMSIZE enables to get width and height of the caption buttons. But how to get extra space between close and restore button as well as between window right edge and close button. I guess this values are fixed but what they are?
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1308062
Capture the image and count the pixels.

A lot of UI specs are not part of the system metrics, but are part of the UI guidelines that have been put into code and dialog design.


0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1308063
My answer is not as silly as it sounds. Paul Dilascia had the same problem when doing his gradient filled shaded caption/title.  He could get the button size, but there was nowhere to get the gap from.  So he counted pixels.

As I said, not everything about windows is nice and parameterized - there are actually some hardcoded numbers buried inside windows.  Eve MFC is not immune - which is why vertical toolbars look screwy under IE4 - MFC ASSUMED an 8 pixel seperator between groups of toolbar buttons.

0
 
LVL 7

Author Comment

by:galkin
ID: 1308064
Yes I also came to such a conclusion but I must check it in different modes and platforms. If these values are fixed I will accept your answer.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1308065
bit late to accept now - you just rejected it :-(

0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Expert Comment

by:jasiek
ID: 1308066
There is no other way than suggested by thui or RONSLOW, windows is not an easy game ).
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1308067
Use GetSystemMetrics to retrieve the caption size - GetSystemMetrics with BorderWidth - 1 : this will be the buttons size
0
 
LVL 7

Author Comment

by:galkin
ID: 1308068
First of all no parameters of GetSystemMetrics enables to retreive caption button size. In addition there is no way to get size between close and restore buttons. I suppose these values are fixed but I still have to check this.
0
 
LVL 8

Accepted Solution

by:
MikeP090797 earned 50 total points
ID: 1308069
You can open the Screen properties dialog using SendMessage, switch to Appiriance using sendkeys, select the 'Caption Buttons' Item from list, and use EnumWindows and GetWindowText to retreive the value.
What the heck do you need the buttons size anyway?
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1308070
That just gives you the same result as GetSystemMetrics - only a very complicated way to do it :-)

Here is what the MS KB says about all this -- you should be able to work out sizes from this (if you like this answer, reject the last one (which looks like it was a joke answer anyway) and let me answer please.

How to Draw a Custom Window Caption
Article ID: Q99046
Creation Date: 20-MAY-1993
Revision Date: 02-NOV-1995
The information in this article applies to:
Microsoft Windows Software Development Kit (SDK) versions 3.1
Microsoft Win32 Application Programming Interface (API) included with:
    - Microsoft Windows NT versions 3.5 and 3.51
    - Microsoft Windows 95 version 4.0

SUMMARY

Microsoft Windows draws captions in the caption bar (or title bar) for all eligible windows in the system. Applications need to specify only the WS_CAPTION style to take advantage of this facility. The current version of Microsoft Windows, however, imposes three significant restrictions on the captions. An application that does not want to be tied by any of these restrictions may want to draw its own caption. This article lists the restrictions and the steps required to draw a window caption.

These restrictions also apply to Windows NT, but there are a few differences for Windows 95.

It is important to note that an application should not draw its own caption unless it has very good reasons to do so. A window caption is a user interface object, and rendering it in ways different from other windows in the system may obstruct the user's conceptual grasp of the Microsoft Windows user interface.

MORE INFORMATION

Windows and Windows NT

The three important restrictions imposed by Microsoft Windows version 3.1 and Microsoft Windows NT on the caption for a window are:

- It consists of text only; graphics are not allowed. - All text is centered and drawn with the system font. - The length of the displayed caption is limited to 78 characters even when there is space on the caption bar to accommodate extra characters.

An application can essentially render its own caption consisting of any graphic and text with the standard graphics and text primitives by painting on the nonclient area of the window. The application should draw in response to the WM_NCPAINT, WM_NCACTIVATE, WM_SETTEXT, and WM_SYSCOMMAND messages. When processing these messages, an application should first pass on the message to DefWindowProc() for default processing, then render its caption before returning from the message. This ensures that Microsoft Windows can properly draw the nonclient area. Because drawing the caption is part of DefWindowProc()'s nonclient area processing, an application should specify an empty window title to avoid any Windows-initiated drawing in the caption bar. The following steps indicate the computations needed to determine the caption drawing area:

Get the current window's rectangle using GetWindowRect(). This includes client plus nonclient areas and is in screen coordinates.

1) Get a device context (DC) to the window using GetWindowDC().

2) Compute the origin and dimensions of the caption bar. One needs to account for the window decorations (frame, border) and window bitmaps (min/max/system boxes). Remember that different window styles will result in different decorations and a different number of min/max/system boxes. Use GetSystemMetrics() to compute the dimensions of the frame, border, and the system bitmap dimensions.

3) Render the caption within the boundaries of the rectangle computed in step 3. Remember that the user can change the caption bar color any time by using the Control Panel. Some components of the caption, particularly text backgrounds, may need to be changed based on the current caption bar color. Use GetSysColor to determine the current color.

The following code sample draws a left-justified caption for a window (the code sample applies only to the case where the window is active):

Sample Code

   case WM_NCACTIVATE:
      if ((BOOL)wParam == FALSE)
      {
         DefWindowProc( hWnd, message, wParam, lParam );
      // Add code here to draw caption when window is inactive.
         return TRUE;
      }
      // Fall through if wParam == TRUE, i.e., window is active.
      case WM_NCPAINT:
      // Let Windows do what it usually does. Let the window caption
      // be empty to avoid any Windows-initiated caption bar drawing
         DefWindowProc( hWnd, message, wParam, lParam );
         hDC = GetWindowDC( hWnd );
         GetWindowRect( hWnd, (LPRECT)&rc2 );
      // Compute the caption bar's origin. This window has a system box
      // a minimize box, a maximize box, and has a resizeable frame
         x = GetSystemMetrics( SM_CXSIZE ) +
             GetSystemMetrics( SM_CXBORDER ) +
             GetSystemMetrics( SM_CXFRAME );
         y = GetSystemMetrics( SM_CYFRAME );
         rc1.left = x;
         rc1.top = y;
      // 2*x gives twice the bitmap+border+frame size. Since there are
      // only two bitmaps, two borders, and one frame at the end of the
      // caption bar, subtract a frame to account for this.
         rc1.right = rc2.right - rc2.left - 2*x -
                     GetSystemMetrics( SM_CXFRAME );
         rc1.bottom = GetSystemMetrics( SM_CYSIZE );
      // Render the caption. Use the active caption color as the text
      // background.
         SetBkColor( hDC, GetSysColor(COLOR_ACTIVECAPTION) );
         DrawText( hDC, (LPSTR)"Left Justified Caption", -1,
                 (LPRECT)&rc1, DT_LEFT );
        ReleaseDC( hWnd, hDC );
        break;

Windows 95

On Windows 95, the text is not centered and the user can choose the Font. In addition, your application might want to monitor the WM_WININICHANGED message, because the user can change titlebar widths, and so forth, dynamically. When this happens, the application should take the new system metrics into account, and force a window redraw.

--------------------------------------------------------------------------------

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.
)1997 Microsoft Corporation. All rights reserved. Legal Notices.


Additional reference words: 3.00 3.10 3.50 4.00 minimum maximum
KbCategory: kbui kbcode
KbSubCategory: UsrPnt

0
 
LVL 7

Author Comment

by:galkin
ID: 1308071
Thank you , I read this article. It doesn't answer the question but As I realized these values are fixed. So I accept your answer.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1308072
Hey - you accepted the wrong answer!! :-(

I'm the one that answered and told you about fixed sizes etc.

Can you post again so I can answer it and get the credit?

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
not able to insert into temp table 68 150
List out all word 7 224
Thin secure Windows 10 5 48
how to split multiple lines delimiter : 8 54
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

757 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

21 Experts available now in Live!

Get 1:1 Help Now