Cant get GetTitleBarInfo working properly...
-
Hey ppl, I have ported this code from a vb6 example, but can't seem to get it working... Any ideas :confused:
Private Class TitleBarInfo Shared Function GetTitleBarInfo(ByVal hwnd As IntPtr, ByRef pti As TITLEBARINFO) As Boolean End Function Private Const STATE_SYSTEM_FOCUSABLE As Integer = &H100000 Private Const STATE_SYSTEM_INVISIBLE As Short = &H8000S Private Const STATE_SYSTEM_OFFSCREEN As Integer = &H10000 Private Const STATE_SYSTEM_UNAVAILABLE As Short = &H1S Private Const STATE_SYSTEM_PRESSED As Short = &H8S Private Const CCHILDREN_TITLEBAR As Short = 5 Public Structure RECT Public left As Integer Public top As Integer Public right As Integer Public bottom As Integer End Structure Public Structure TITLEBARINFO Public cbSize As Integer Public rcTitleBar As RECT Public rgstate() As Integer Public Sub Initialize() ReDim rgstate(CCHILDREN_TITLEBAR) End Sub End Structure Public Shared Function GetTitleBarInfo(ByVal Handle As IntPtr) As TITLEBARINFO Dim TitleInfo As TITLEBARINFO 'Initialize structure TitleInfo.Initialize() TitleInfo.cbSize = Len(TitleInfo) GetTitleBarInfo(Handle, TitleInfo) return TitleInfo Return TitleInfo End Function End Class
-
Hey ppl, I have ported this code from a vb6 example, but can't seem to get it working... Any ideas :confused:
Private Class TitleBarInfo Shared Function GetTitleBarInfo(ByVal hwnd As IntPtr, ByRef pti As TITLEBARINFO) As Boolean End Function Private Const STATE_SYSTEM_FOCUSABLE As Integer = &H100000 Private Const STATE_SYSTEM_INVISIBLE As Short = &H8000S Private Const STATE_SYSTEM_OFFSCREEN As Integer = &H10000 Private Const STATE_SYSTEM_UNAVAILABLE As Short = &H1S Private Const STATE_SYSTEM_PRESSED As Short = &H8S Private Const CCHILDREN_TITLEBAR As Short = 5 Public Structure RECT Public left As Integer Public top As Integer Public right As Integer Public bottom As Integer End Structure Public Structure TITLEBARINFO Public cbSize As Integer Public rcTitleBar As RECT Public rgstate() As Integer Public Sub Initialize() ReDim rgstate(CCHILDREN_TITLEBAR) End Sub End Structure Public Shared Function GetTitleBarInfo(ByVal Handle As IntPtr) As TITLEBARINFO Dim TitleInfo As TITLEBARINFO 'Initialize structure TitleInfo.Initialize() TitleInfo.cbSize = Len(TitleInfo) GetTitleBarInfo(Handle, TitleInfo) return TitleInfo Return TitleInfo End Function End Class
-
Hey ppl, I have ported this code from a vb6 example, but can't seem to get it working... Any ideas :confused:
Private Class TitleBarInfo Shared Function GetTitleBarInfo(ByVal hwnd As IntPtr, ByRef pti As TITLEBARINFO) As Boolean End Function Private Const STATE_SYSTEM_FOCUSABLE As Integer = &H100000 Private Const STATE_SYSTEM_INVISIBLE As Short = &H8000S Private Const STATE_SYSTEM_OFFSCREEN As Integer = &H10000 Private Const STATE_SYSTEM_UNAVAILABLE As Short = &H1S Private Const STATE_SYSTEM_PRESSED As Short = &H8S Private Const CCHILDREN_TITLEBAR As Short = 5 Public Structure RECT Public left As Integer Public top As Integer Public right As Integer Public bottom As Integer End Structure Public Structure TITLEBARINFO Public cbSize As Integer Public rcTitleBar As RECT Public rgstate() As Integer Public Sub Initialize() ReDim rgstate(CCHILDREN_TITLEBAR) End Sub End Structure Public Shared Function GetTitleBarInfo(ByVal Handle As IntPtr) As TITLEBARINFO Dim TitleInfo As TITLEBARINFO 'Initialize structure TitleInfo.Initialize() TitleInfo.cbSize = Len(TitleInfo) GetTitleBarInfo(Handle, TitleInfo) return TitleInfo Return TitleInfo End Function End Class
Sorry AndrewVos, I sent that last message to fast, I checked it again and I was still getting a error 87, sorry. add this import: Imports System.Runtime.InteropServices and the structure should be more like this: _ Private Structure TITLEBARINFO Dim cbSize As Long Dim rcTitleBar As RECT _ Dim rgstate() As Long Public Sub Initialize() ReDim rgstate(CCHILDREN_TITLEBAR) End Sub End Structure It should return err code 0 now. hope that helps
-
Sorry AndrewVos, I sent that last message to fast, I checked it again and I was still getting a error 87, sorry. add this import: Imports System.Runtime.InteropServices and the structure should be more like this: _ Private Structure TITLEBARINFO Dim cbSize As Long Dim rcTitleBar As RECT _ Dim rgstate() As Long Public Sub Initialize() ReDim rgstate(CCHILDREN_TITLEBAR) End Sub End Structure It should return err code 0 now. hope that helps
Still not working... The elements of rgstate() are all = 0. Consider this code....
Private Class TitleBarInfo Private Shared Function GetTitleBarInfo(ByVal hWnd As IntPtr, ByRef pti As TITLEBARINFO) As Boolean End Function Private Const STATE_SYSTEM_FOCUSABLE As Integer = &H100000 Private Const STATE_SYSTEM_INVISIBLE As Short = &H8000S Private Const STATE_SYSTEM_OFFSCREEN As Integer = &H10000 Private Const STATE_SYSTEM_UNAVAILABLE As Short = &H1S Private Const STATE_SYSTEM_PRESSED As Short = &H8S Private Const CCHILDREN_TITLEBAR As Short = 5 Public Structure RECT Public left As Integer Public top As Integer Public right As Integer Public bottom As Integer End Structure Private Structure TITLEBARINFO Dim cbSize As Integer Dim rcTitleBar As RECT Dim rgstate() As Integer Public Sub Initialize() ReDim rgstate(CCHILDREN_TITLEBAR + 1) End Sub End Structure Private Shared Function GetTitleBarInfo(ByVal Handle As IntPtr) As TITLEBARINFO Dim TitleInfo As TITLEBARINFO 'Initialize structure TitleInfo.Initialize() TitleInfo.cbSize = Len(TitleInfo) ' GetTitleBarInfo(Handle, TitleInfo) GetTitleBarInfo(Handle, TitleInfo) 'Show some of that information Return TitleInfo End Function Public Shared ReadOnly Property CaptionButtonCount(ByVal Handle As IntPtr) As Integer Get Dim count As Integer Dim tbi As TITLEBARINFO tbi = GetTitleBarInfo(Handle) 'Index TitleBar Element '0 The title bar itself. '1 Reserved. '2 Minimize button. '3 Maximize button. '4 Help button. '5 Close button. Dim x As Integer For x = 2 To 5
-
Still not working... The elements of rgstate() are all = 0. Consider this code....
Private Class TitleBarInfo Private Shared Function GetTitleBarInfo(ByVal hWnd As IntPtr, ByRef pti As TITLEBARINFO) As Boolean End Function Private Const STATE_SYSTEM_FOCUSABLE As Integer = &H100000 Private Const STATE_SYSTEM_INVISIBLE As Short = &H8000S Private Const STATE_SYSTEM_OFFSCREEN As Integer = &H10000 Private Const STATE_SYSTEM_UNAVAILABLE As Short = &H1S Private Const STATE_SYSTEM_PRESSED As Short = &H8S Private Const CCHILDREN_TITLEBAR As Short = 5 Public Structure RECT Public left As Integer Public top As Integer Public right As Integer Public bottom As Integer End Structure Private Structure TITLEBARINFO Dim cbSize As Integer Dim rcTitleBar As RECT Dim rgstate() As Integer Public Sub Initialize() ReDim rgstate(CCHILDREN_TITLEBAR + 1) End Sub End Structure Private Shared Function GetTitleBarInfo(ByVal Handle As IntPtr) As TITLEBARINFO Dim TitleInfo As TITLEBARINFO 'Initialize structure TitleInfo.Initialize() TitleInfo.cbSize = Len(TitleInfo) ' GetTitleBarInfo(Handle, TitleInfo) GetTitleBarInfo(Handle, TitleInfo) 'Show some of that information Return TitleInfo End Function Public Shared ReadOnly Property CaptionButtonCount(ByVal Handle As IntPtr) As Integer Get Dim count As Integer Dim tbi As TITLEBARINFO tbi = GetTitleBarInfo(Handle) 'Index TitleBar Element '0 The title bar itself. '1 Reserved. '2 Minimize button. '3 Maximize button. '4 Help button. '5 Close button. Dim x As Integer For x = 2 To 5
-
MSDN on the GetTitleBarInfo function..... "If the function succeeds, the return value is nonzero."
-
Hey ppl, I have ported this code from a vb6 example, but can't seem to get it working... Any ideas :confused:
Private Class TitleBarInfo Shared Function GetTitleBarInfo(ByVal hwnd As IntPtr, ByRef pti As TITLEBARINFO) As Boolean End Function Private Const STATE_SYSTEM_FOCUSABLE As Integer = &H100000 Private Const STATE_SYSTEM_INVISIBLE As Short = &H8000S Private Const STATE_SYSTEM_OFFSCREEN As Integer = &H10000 Private Const STATE_SYSTEM_UNAVAILABLE As Short = &H1S Private Const STATE_SYSTEM_PRESSED As Short = &H8S Private Const CCHILDREN_TITLEBAR As Short = 5 Public Structure RECT Public left As Integer Public top As Integer Public right As Integer Public bottom As Integer End Structure Public Structure TITLEBARINFO Public cbSize As Integer Public rcTitleBar As RECT Public rgstate() As Integer Public Sub Initialize() ReDim rgstate(CCHILDREN_TITLEBAR) End Sub End Structure Public Shared Function GetTitleBarInfo(ByVal Handle As IntPtr) As TITLEBARINFO Dim TitleInfo As TITLEBARINFO 'Initialize structure TitleInfo.Initialize() TitleInfo.cbSize = Len(TitleInfo) GetTitleBarInfo(Handle, TitleInfo) return TitleInfo Return TitleInfo End Function End Class
AndrewVos, Sorry, I was woring on it between other code so it didn't get my full attention or time, I think this solution should work now that I've had time to see what was going on. It works on my end. '---------------------------------------- Imports System.Runtime.InteropServices '---------------------------------------- _ Structure Rect Public rLeft, rTop, rRight, rBottom As Int32 Public Function ToRectangle() As Rectangle Return Rectangle.FromLTRB(rLeft, rTop, rRight, rBottom) End Function Public Overrides Function ToString() As String Return "Rect: " & ToRectangle.ToString End Function End Structure _ Structure TitleBarButtonStates Public TitleBarState As TBBStates Public Reserved As TBBStates Public MinState As TBBStates Public MaxState As TBBStates Public HelpState As TBBStates Public CloseState As TBBStates End Structure Enum TBBStates STATE_SYSTEM_UNAVAILABLE = &H1 STATE_SYSTEM_PRESSED = &H8 STATE_SYSTEM_INVISIBLE = &H8000 STATE_SYSTEM_OFFSCREEN = &H10000 STATE_SYSTEM_FOCUSABLE = &H100000 End Enum _ Public Structure TITLEBARINFO Dim cbSize As Int32 Dim rcTitleBar As Rect Dim rgstate As TitleBarButtonStates End Structure Private Declare Function GetTitleBarInfo Lib "user32.dll" ( _ ByVal hwnd As Int32, ByRef pti As TITLEBARINFO) As Long Public Shared Function GetTitleBarInfo(ByVal Handle As Int32) As TITLEBARINFO Dim TitleInfo As TitleBarInfo 'Initialize structure TitleInfo.cbSize = Len(TitleInfo) GetTitleBarInfo(Handle, TitleInfo) ' *debug* the information we got back With TitleInfo.rcTitleBar System.Diagnostics.Debug.WriteLine(" (" & CStr(.rLeft) & "," & CStr(.rTop) & ")-(" & CStr(.rRight) & "," & CStr(.rBottom) & ")") End With With TitleInfo.rgstate System.Diagnostics.Debug.WriteLine(.TitleBarState) End With 'return with the TitleInfo Return TitleInfo End Function '---------------------------------------------------------- My last test Return was: Last DLL Error:0 (51,33)-(318,59) STATE_SYS
-
AndrewVos, Sorry, I was woring on it between other code so it didn't get my full attention or time, I think this solution should work now that I've had time to see what was going on. It works on my end. '---------------------------------------- Imports System.Runtime.InteropServices '---------------------------------------- _ Structure Rect Public rLeft, rTop, rRight, rBottom As Int32 Public Function ToRectangle() As Rectangle Return Rectangle.FromLTRB(rLeft, rTop, rRight, rBottom) End Function Public Overrides Function ToString() As String Return "Rect: " & ToRectangle.ToString End Function End Structure _ Structure TitleBarButtonStates Public TitleBarState As TBBStates Public Reserved As TBBStates Public MinState As TBBStates Public MaxState As TBBStates Public HelpState As TBBStates Public CloseState As TBBStates End Structure Enum TBBStates STATE_SYSTEM_UNAVAILABLE = &H1 STATE_SYSTEM_PRESSED = &H8 STATE_SYSTEM_INVISIBLE = &H8000 STATE_SYSTEM_OFFSCREEN = &H10000 STATE_SYSTEM_FOCUSABLE = &H100000 End Enum _ Public Structure TITLEBARINFO Dim cbSize As Int32 Dim rcTitleBar As Rect Dim rgstate As TitleBarButtonStates End Structure Private Declare Function GetTitleBarInfo Lib "user32.dll" ( _ ByVal hwnd As Int32, ByRef pti As TITLEBARINFO) As Long Public Shared Function GetTitleBarInfo(ByVal Handle As Int32) As TITLEBARINFO Dim TitleInfo As TitleBarInfo 'Initialize structure TitleInfo.cbSize = Len(TitleInfo) GetTitleBarInfo(Handle, TitleInfo) ' *debug* the information we got back With TitleInfo.rcTitleBar System.Diagnostics.Debug.WriteLine(" (" & CStr(.rLeft) & "," & CStr(.rTop) & ")-(" & CStr(.rRight) & "," & CStr(.rBottom) & ")") End With With TitleInfo.rgstate System.Diagnostics.Debug.WriteLine(.TitleBarState) End With 'return with the TitleInfo Return TitleInfo End Function '---------------------------------------------------------- My last test Return was: Last DLL Error:0 (51,33)-(318,59) STATE_SYS
-
Shweeet. Dunno how u got this working properly, well I havent reviewed it yet properly, but everything seems right. Thanks alot Anonymous! I actually resorted to GetWindowLong to check if the caption buttons r there. Well done, ur a genius :>
-
Wasnt logged in there... Thanks so much for your work, Anonymous, and the last post was mine. Cheers mate