Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

How to obtain the title bar handle??


  • Please log in to reply
8 replies to this topic
TitleBarHandle
  • Guests
  • Last active:
  • Joined: --
Hi there,
The Win32API function GetTitleBarInfo() needs:

A handle to the title bar whose information is to be retrieved.

I've searched everywhere but cannot find any documents pertaining to a method of obtain its handle.
I also tried the active windows handle using WinExist("A"),
but I always return 0 for all the Rect members offsets in the TITLEBARINFO struct ( Rect struct offsets ).
I also debugged this in Hex view and all offsets are empty at the pointer.

In the struct I pre-set the cbSize member by StrLen() of the windows title as instructed.

Any ideas of how or where to get the Titlebar hwnd?

Thanks in advance.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
A title bar is a feature of a window, not itself a window. Just pass the HWND (window handle) of the window whose title bar you want information about. WinActive("A") works if you get the structure right.

In the struct I pre-set the cbSize member by StrLen() of the windows title as instructed.

cbSize must be set to "The size, in bytes, of the structure", which has nothing to do with the window's title. Here's a break-down of the structure:
typedef struct tagTITLEBARINFO {
  DWORD cbSize;  [color=green]; uint: 4 bytes[/color]
  RECT  rcTitleBar;  [color=green]; int, int, int, int: 4*4 (=16) bytes[/color]
  DWORD rgstate[CCHILDREN_TITLEBAR+1];  [color=green]; array of 6 uint: 6*4 (=24) bytes[/color]
} TITLEBARINFO, *PTITLEBARINFO, *LPTITLEBARINFO;
[color=green]; Total: 44 bytes[/color]


TitleBarHandle
  • Guests
  • Last active:
  • Joined: --
Appreciate the reply Lexikos.
Unfortunately I'm still ending up with empty members.
Here's a few:
VarSetCapacity( tbInf, 44, 0 )
DllCall( "GetTitleBarInfo", uInt, WinActive( "A" ), uInt, &tbInf ) [color=#008000]; WinExist( "A" ) returns the same hwnd based on A[/color]
Msgbox % NumGet( &tbInf, 0 ) " " NumGet( &tbInf, 4 ) " "
		 . NumGet( &tbInf, 8 ) " " NumGet( &tbInf, 12 ) " "
		 . NumGet( &tbInf, 16 ) " " NumGet( &tbInf, 20 ) " "
		 . NumGet( &tbInf, 24 ) " " NumGet( &tbInf, 28 )
I wasn't insinuating that the TitleBar was a window.
Just not sure why MS would not just simply ask for the window handle as in other API, if this was the case.

Any other ideas as to why its returning 0?
Thanks again

TitleBarHandle
  • Guests
  • Last active:
  • Joined: --
Still no luck with this.
Can someone please confirm that it does/doesn't work please?
Ty

  • Guests
  • Last active:
  • Joined: --
VarSetCapacity( tbInf, 44, 0 )

[color=red]NumPut(44, tbInf, 0, "Int" )[/color]

; ...


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

I wasn't insinuating that the TitleBar was a window.

No, but the function's first parameter is documented as type HWND, which means window handle. I was merely trying to show how one could reach the right conclusion from the somewhat misleading documentation.

guest3456
  • Members
  • 1704 posts
  • Last active: Nov 19 2015 11:58 AM
  • Joined: 10 Mar 2011

I wasn't insinuating that the TitleBar was a window.

No, but the function's first parameter is documented as type HWND, which means window handle. I was merely trying to show how one could reach the right conclusion from the somewhat misleading documentation.


msdn docs sometimes use HWND to mean more than just handles to full windows. when i was doing some z-order testing with GetWindow, GetNextWindow, etc, the functions would return HWNDs to the next "window" in the z-order but sometimes it would be handles to the buttons within the window

TitleBarHandle
  • Guests
  • Last active:
  • Joined: --

..the function's first parameter is documented as type HWND, which means window handle. I was merely trying to show how one could reach the right conclusion from the somewhat misleading documentation.

That makes sense, and yes MS definitely made this misleading :roll: Thnx for clarifying :).

[color=red]NumPut(44, tbInf, 0, "Int" )[/color]
; ...

Ah yes I had tried placing the appropriate array index in my tests but my whole struct wasn't the right size.
The function call is now returning the appropriate data :mrgreen:.
Now I know how to set the correct byte sizes, add array members and choose the index for next time.

Thank you both this has helped me immensely.

TitleBarHandle
  • Guests
  • Last active:
  • Joined: --

..HWNDs to the next "window" in the z-order.. sometimes.. would be handles to the buttons within the window

Perhaps this be because a Control is also interpreted as a window ?