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. Visual Basic
  4. Cant get GetTitleBarInfo working properly...

Cant get GetTitleBarInfo working properly...

Scheduled Pinned Locked Moved Visual Basic
tutorial
10 Posts 2 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.
  • A Offline
    A Offline
    AndrewVos
    wrote on last edited by
    #1

    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

    A 3 Replies Last reply
    0
    • A AndrewVos

      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

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      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 and GetTitleBarInfo(Me.Handle.ToInt32, TitleInfo) hope this helps

      1 Reply Last reply
      0
      • A AndrewVos

        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

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        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

        A 1 Reply Last reply
        0
        • A Anonymous

          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

          A Offline
          A Offline
          AndrewVos
          wrote on last edited by
          #4

          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

          A 1 Reply Last reply
          0
          • A AndrewVos

            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

            A Offline
            A Offline
            AndrewVos
            wrote on last edited by
            #5

            MSDN on the GetTitleBarInfo function..... "If the function succeeds, the return value is nonzero."

            A 1 Reply Last reply
            0
            • A AndrewVos

              MSDN on the GetTitleBarInfo function..... "If the function succeeds, the return value is nonzero."

              A Offline
              A Offline
              AndrewVos
              wrote on last edited by
              #6

              Yeah, I been tweaking the code for a while now with no luck, anyone with a good understanding of interop, please comment, thanks.

              1 Reply Last reply
              0
              • A AndrewVos

                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

                A Offline
                A Offline
                Anonymous
                wrote on last edited by
                #7

                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

                A 1 Reply Last reply
                0
                • A Anonymous

                  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

                  A Offline
                  A Offline
                  Anonymous
                  wrote on last edited by
                  #8

                  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 :>

                  A 1 Reply Last reply
                  0
                  • A Anonymous

                    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 :>

                    A Offline
                    A Offline
                    AndrewVos
                    wrote on last edited by
                    #9

                    Wasnt logged in there... Thanks so much for your work, Anonymous, and the last post was mine. Cheers mate

                    A 1 Reply Last reply
                    0
                    • A AndrewVos

                      Wasnt logged in there... Thanks so much for your work, Anonymous, and the last post was mine. Cheers mate

                      A Offline
                      A Offline
                      Anonymous
                      wrote on last edited by
                      #10

                      AndrewVos, Thanks, it was interesting, and no problem, I don't log in a lot of times either. progload

                      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