Results 1 to 7 of 7

Thread: Detecting title bar clicks

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    UK, Bedfordshire
    Posts
    49

    Question

    hi ppl

    does any one know how to detect clicks in the title bar of a form? i want to write an application that will sense when the user maves it (by the title bar) and when the user click the title bar.

    also does any one know how to change to control icon menu on the left of the title bar? and how to 'force' the colour of the particular application to be a spacific colour, i.e. red instead of the usual blue without changing the colouring setting?

    one way i could do if to creat a label and align it to the top and make that act as the title bar, but this would be difficult and it would make the application look 'funny'.

    thanx.
    p.s. i know i could probably do all of this through API but i want to leave that as a last resort...
    Thanx, for your reply(s)

    Zhang Tian Hao
    Visual Studio Enterprise 6.0 SP 4
    [email protected]

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Sorry but not only do you have to resort to the API you also need to sub class the form. Be carefull when you do this so you don't hit the End button on the VB toolbar. End the application by clicking on the Close button of the form. Otherwise you will get a GPF.
    Ok here we go! Put the following in a BAS code module:
    Code:
    Private Declare Function SetWindowLong _
     Lib "user32" Alias "SetWindowLongA" ( _
     ByVal hWnd As Long, _
     ByVal nIndex As Long, _
     ByVal dwNewLong As Long) As Long
    
    Private Declare Function CallWindowProc _
     Lib "user32" Alias "CallWindowProcA" ( _
     ByVal lpPrevWndFunc As Long, _
     ByVal hWnd As Long, _
     ByVal Msg As Long, _
     ByVal wParam As Long, _
     ByVal lParam As Long) As Long
    
    Private Const GWL_WNDPROC = (-4)
    Private Const WM_NCLBUTTONDOWN = &HA1
    Private Const WM_NCMOUSEMOVE = &HA0
    Private Const HTCAPTION = 2
    
    Private lngHwnd As Long
    Private lngPrevWndProc As Long
    Private frmHocked As Form
    
    Public Sub HookForm(frm As Form)
        lngHwnd = frm.hWnd
        Set frmHocked = frm
        lngPrevWndProc = SetWindowLong(lngHwnd, GWL_WNDPROC, AddressOf WinProc)
    End Sub
    
    Public Sub UnhookForm()
        SetWindowLong lngHwnd, GWL_WNDPROC, lngPrevWndProc
    End Sub
    
    Public Function WinProc( _
    ByVal hw As Long, _
    ByVal uMsg As Long, _
    ByVal wParam As Long, _
    ByVal lParam As Long) As Long
        If wParam = HTCAPTION Then
                Debug.Print WM_NCLBUTTONUP, uMsg
            If uMsg = WM_NCLBUTTONDOWN Then
                'the user starts the drag
                frmHocked.Caption = "Dragging"
            ElseIf uMsg = WM_NCMOUSEMOVE Then
                'no drag
                frmHocked.Caption = "No drag"
            End If
        End If
        WinProc = CallWindowProc(lngPrevWndProc, hw, uMsg, wParam, lParam)
    End Function
    Now add the following code to the form you want to hook:
    Code:
    Private Sub Form_Load()
        HookForm Me
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        UnhookForm
    End Sub
    Good luck!

  3. #3
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Changing the icon at the top left of the form is easy, If you click on the form at design time (while it's not running) and look in the properties window there's a property called Icon, if you double click this you get a file selection window, then use this to select an Icon from your HD that you want up there.
    ,

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    UK, Bedfordshire
    Posts
    49
    Thanx Joacim and Sam,

    Sam i ment changing the menus, not the icon
    Thanx, for your reply(s)

    Zhang Tian Hao
    Visual Studio Enterprise 6.0 SP 4
    [email protected]

  5. #5
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Changing the menu is a bit harder, I can't really explain it all because there's a lot you can do to it. (It's a lot of API work too)

    What exactly do you want to do to the system menu?

  6. #6

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    UK, Bedfordshire
    Posts
    49
    well all i want to do is write an application like mirc. i was woundering could you get the system menu to display a menu created by the VB menu builder? if it's not very easy then i could make the form with no border but with a caption for the titlebar and creat a icon which displayed a popup menu...
    Thanx, for your reply(s)

    Zhang Tian Hao
    Visual Studio Enterprise 6.0 SP 4
    [email protected]

  7. #7
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    You Could Uh....
    Create An Array.
    Then Use Load To Create More And More Menus Until Your Heart Is Content.
    i.e.
    Static ArrayCurrentNumber
    ArrayCurrentNumber = ArrayCurrentNumber + 1
    Load mnuSupaDupaMenuArrayThatICanMakeABunchOfMenusWithAndHaveAReallyCoolApplication(ArrayCurrentNumber)

    or:

    Static CurAry
    CurAry = CurAry + 1
    Load mnuAry(CurAry)

    Or make your own, it's all JELLO!

    Best wishes,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width