Results 1 to 13 of 13

Thread: Add another button next to the minimize,maximize, close buttons

  1. #1

    Thread Starter
    Addicted Member FOOBAR's Avatar
    Join Date
    Aug 2000
    Posts
    172

    Add another button next to the minimize,maximize, close buttons

    is there away to add another button to the left of the minimize butotn in the control bar of my program?? i know theres away, im just tring to figure out how...kinda like how the all api guid program has that lil . that puts it in the tray
    No Comment.

  2. #2

  3. #3
    Addicted Member
    Join Date
    Feb 2001
    Posts
    253
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
    Last edited by smashtheqube; Jan 11th, 2019 at 01:50 AM.

  4. #4

  5. #5
    Lively Member
    Join Date
    Jun 2001
    Location
    Viet Nam
    Posts
    98
    Draw your own title bar, and write some code to process mouse events on it. You can add everything .

  6. #6

    Thread Starter
    Addicted Member FOOBAR's Avatar
    Join Date
    Aug 2000
    Posts
    172
    that sounds like someone by the name of smashthecube is taking credit for somthing he didnt build?

    if not then why dont u just open your source up and look?
    No Comment.

  7. #7
    appi101
    Guest
    HI

    I had asked this question a while ago and this was the reply I had got. I have been able to make only partial sense out of it so far

    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 GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As Rect) As Long
    Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook&, ByVal lpfn&, ByVal hmod&, ByVal dwThreadId&) As Long
    Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook&) As Long
    Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

    Private Type Rect
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
    End Type

    Private Type CWPSTRUCT
    lParam As Long
    wParam As Long
    Message As Long
    hwnd As Long
    End Type

    Const WM_MOVE = &H3
    Const WM_SETCURSOR = &H20
    Const WM_NCPAINT = &H85
    Const WM_COMMAND = &H111

    Const SWP_FRAMECHANGED = &H20
    Const GWL_EXSTYLE = -20

    Private WHook&
    Private ButtonHwnd As Long

    Public Sub Init()
    'Create the button that is going to be placed in the Titlebar
    ButtonHwnd& = CreateWindowEx(0&, "Button", "i", &H40000000, 50, 50, 14, 14, Form1.hwnd, 0&, App.hInstance, 0&)
    'Show the button cause it´s invisible
    Call ShowWindow(ButtonHwnd&, 1)
    'Initialize the window hooking for the button
    WHook = SetWindowsHookEx(4, AddressOf HookProc, 0, App.ThreadID)
    Call SetWindowLong(ButtonHwnd&, GWL_EXSTYLE, &H80)
    Call SetParent(ButtonHwnd&, GetParent(Form1.hwnd))
    End Sub

    Public Sub Terminate()
    'Terminate the window hooking
    Call UnhookWindowsHookEx(WHook)
    Call SetParent(ButtonHwnd&, Form1.hwnd)
    End Sub

    Public Function HookProc&(ByVal nCode&, ByVal wParam&, Inf As CWPSTRUCT)
    Dim FormRect As Rect
    Static LastParam&
    If Inf.hwnd = GetParent(ButtonHwnd&) Then
    If Inf.Message = WM_COMMAND Then
    Select Case LastParam
    'If the LastParam is cmdInTitlebar call the Click-Procedure
    'of the button
    Case ButtonHwnd&: Call Form1.cmdInTitlebar_Click
    End Select
    ElseIf Inf.Message = WM_SETCURSOR Then
    LastParam = Inf.wParam
    End If
    ElseIf Inf.hwnd = Form1.hwnd Then
    If Inf.Message = WM_NCPAINT Or Inf.Message = WM_MOVE Then
    'Get the size of the Form
    Call GetWindowRect(Form1.hwnd, FormRect)
    'Place the button int the Titlebar
    Call SetWindowPos(ButtonHwnd&, 0, FormRect.Right - 75, FormRect.Top + 6, 17, 14, SWP_FRAMECHANGED)
    End If
    End If
    End Function
    --------------------------------------------------------------------------------


    And put this in the Form's module:


    code:--------------------------------------------------------------------------------
    Public Sub cmdInTitlebar_Click()
    Me.WindowState = 1 'minimizes the form
    End Sub

    Private Sub Form_Load()
    Call Init
    End Sub

    Private Sub Form_Unload(Cancel As Integer)
    Call Terminate
    End Sub


    To minimize the form to the system tray you can use a Systemicon control and on the button's click event set the form;s windowstate to be minimized anf add an icon to the system tray.

    Appi

  8. #8

    Thread Starter
    Addicted Member FOOBAR's Avatar
    Join Date
    Aug 2000
    Posts
    172
    if i wanted to draw my own bar then i would, other wise i wouldnt post a freaking message here.....so instead of telling me others ways to do it, either keep yoru moth shut, or say,, um im not sure....ok huyak?

    and btw i know there is away, if u have ever used apiguid u will notice they have one that looks exactly like the other buttons except with a caption of .
    No Comment.

  9. #9

    Thread Starter
    Addicted Member FOOBAR's Avatar
    Join Date
    Aug 2000
    Posts
    172
    thanx, ill try that code out
    No Comment.

  10. #10
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    If the above code doesn't work, (can't tell at a glance and too tired to test it), then this will, at least give you a good starting point:

    In a Module:
    VB Code:
    1. Private Type RECT
    2.         Left As Long
    3.         Top As Long
    4.         Right As Long
    5.         Bottom As Long
    6. End Type
    7.  
    8. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    9. 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
    10. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    11.  
    12. Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
    13. Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
    14. Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
    15. Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    16. Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
    17. Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    18. Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    19. Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
    20.  
    21. Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
    22. Private Declare Function ReleaseCapture Lib "user32" () As Long
    23.  
    24. Private Const SRCCOPY = &HCC0020
    25.  
    26. Private Const GWL_WNDPROC = (-4)
    27.  
    28. Private Const WM_NCACTIVATE = &H86
    29. Private Const WM_NCCALCSIZE = &H83
    30. Private Const WM_NCCREATE = &H81
    31. Private Const WM_NCDESTROY = &H82
    32. Private Const WM_NCHITTEST = &H84
    33. Private Const WM_NCLBUTTONDBLCLK = &HA3
    34. Private Const WM_NCLBUTTONDOWN = &HA1
    35. Private Const WM_NCLBUTTONUP = &HA2
    36. Private Const WM_NCMBUTTONDBLCLK = &HA9
    37. Private Const WM_NCMBUTTONDOWN = &HA7
    38. Private Const WM_NCMBUTTONUP = &HA8
    39. Private Const WM_NCMOUSEMOVE = &HA0
    40. Private Const WM_NCPAINT = &H85
    41. Private Const WM_NCRBUTTONDBLCLK = &HA6
    42. Private Const WM_NCRBUTTONDOWN = &HA4
    43. Private Const WM_NCRBUTTONUP = &HA5
    44. Private Const WM_COMMAND = &H111
    45.  
    46. Private Const HTBORDER = 18
    47. Private Const HTBOTTOM = 15
    48. Private Const HTBOTTOMLEFT = 16
    49. Private Const HTCAPTION = 2
    50. Private Const HTBOTTOMRIGHT = 17
    51. Private Const HTCLIENT = 1
    52. Private Const HTERROR = (-2)
    53. Private Const HTGROWBOX = 4
    54. Private Const HTHSCROLL = 6
    55. Private Const HTLEFT = 10
    56. Private Const HTMAXBUTTON = 9
    57. Private Const HTMENU = 5
    58. Private Const HTMINBUTTON = 8
    59. Private Const HTNOWHERE = 0
    60. Private Const HTREDUCE = HTMINBUTTON
    61. Private Const HTRIGHT = 11
    62. Private Const HTSIZE = HTGROWBOX
    63. Private Const HTSIZEFIRST = HTLEFT
    64. Private Const HTSIZELAST = HTBOTTOMRIGHT
    65. Private Const HTSYSMENU = 3
    66. Private Const HTTOP = 12
    67. Private Const HTTOPLEFT = 13
    68. Private Const HTTOPRIGHT = 14
    69. Private Const HTTRANSPARENT = (-1)
    70. Private Const HTVSCROLL = 7
    71. Private Const HTZOOM = HTMAXBUTTON
    72.  
    73. Private lWindowProc As Long
    74. Private lWindowHandle As Long
    75. Private lButtonDC As Long
    76. Private lButtonDownDC As Long
    77.  
    78. Private tRECT As RECT, lWidth, lHeight
    79.  
    80. Private bDrawnDown As Boolean
    81.  
    82. Public Sub SubclassWindow(ByVal hwnd As Long)
    83.     Dim lDC As Long
    84.    
    85.     ' Get the Forms Device Context (DC)
    86.     lDC = GetDC(hwnd)
    87.     ' Create 2 compatible DC's for the Up and Down button images
    88.     lButtonDC = CreateCompatibleDC(lDC)
    89.     lButtonDownDC = CreateCompatibleDC(lDC)
    90.     ' Load the Up and Down button images into each DC respectively
    91.     ' Images are 16x14 16 colors
    92.     Call SelectObject(lButtonDC, LoadPicture("C:\Media\Images\Happy.bmp"))
    93.     Call SelectObject(lButtonDownDC, LoadPicture("C:\Media\Images\HappyDN.bmp"))
    94.     ' Release the forms DC
    95.     Call ReleaseDC(hwnd, lDC)
    96.     ' Subclass the Form
    97.     lWindowProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf SubWindowProc)
    98.     ' Store the forms hWnd for processing later
    99.     lWindowHandle = hwnd
    100. End Sub
    101.  
    102. Public Sub StopSubclass()
    103.     ' Remove the Forms subclassing
    104.     Call SetWindowLong(lWindowHandle, GWL_WNDPROC, lWindowProc)
    105.     ' Delete to 2 button image DC's
    106.     Call DeleteDC(lButtonDC)
    107.     Call DeleteDC(lButtonDownDC)
    108. End Sub
    109.  
    110. Private Function SubWindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    111.     ' Capture ALL messages going to the Form before they are processed
    112.     Static bDepressed As Boolean
    113.    
    114.     Dim lDC As Long
    115.        
    116.     ' Call the default behaviour as normally we'll want to adjust it after the fact
    117.     SubWindowProc = CallWindowProc(lWindowProc, hwnd, Msg, wParam, lParam)
    118.    
    119.     ' Get the Forms current dimensions
    120.     Call GetWindowRect(hwnd, tRECT)
    121.    
    122.     ' Calculate the Forms Width and Height
    123.     lWidth = tRECT.Right - tRECT.Left
    124.     lHeight = tRECT.Bottom - tRECT.Top
    125.            
    126.     Select Case Msg
    127.     Case WM_NCHITTEST
    128.         ' See if the cursor is over our custom button
    129.         If IsOverButton(lParam) Then
    130.             ' If it is, set the Capture to this window, allowing us to receive
    131.             ' Input events as they happen instead of "after the fact"
    132.             SetCapture hwnd
    133.             ' Tell the form our button is just the Caption bar (I don't know of a custom button HT Const)
    134.             SubWindowProc = HTCAPTION
    135.         End If
    136.        
    137.     Case WM_NCLBUTTONDOWN
    138.         ' If the left mouse button is pressed over our button, show a sunken image
    139.         If IsOverButton(lParam) Then
    140.             ' Keep a flag so we know it's being pressed, (lets us to the fancy raise and sink
    141.             ' as the mouse moves in and out of the button without letting the mouse button up.)
    142.             bDepressed = True
    143.             ' Draw the sunken image of our button
    144.             PaintButton lButtonDownDC
    145.             ' Tell the default Window handler we've processed this message
    146.             SubWindowProc = 0
    147.         End If
    148.  
    149.     Case WM_NCLBUTTONUP
    150.         ' If the left button is up, our button can no longer be being pressed
    151.         ' so flag it and no longer depressed.
    152.         bDepressed = False
    153.         ' If the mouse is over our button...
    154.         If IsOverButton(lParam) Then
    155.             ' Draw the raised image
    156.             PaintButton lButtonDC
    157.             ' Release sole capture of the Input messages
    158.             ReleaseCapture
    159.             ' Tell the default handler, we've processed this message
    160.             SubWindowProc = 0
    161.             ' Trigger our Click event
    162.             ButtonClickEvent
    163.         End If
    164.        
    165.     Case WM_NCMOUSEMOVE
    166.         ' If the mouse moves over our button and the left button is pressed..
    167.         If IsOverButton(lParam) And bDepressed Then
    168.             ' Draw the sunken button image
    169.             PaintButton lButtonDownDC
    170.         Else
    171.             ' Otherwise, if the image is currently sunken, raise it
    172.             If bDrawnDown Then
    173.                 PaintButton lButtonDC
    174.             End If
    175.             ' and release capture
    176.             ReleaseCapture
    177.         End If
    178.        
    179.     Case WM_NCPAINT, WM_NCACTIVATE
    180.         ' Redraw the button on PAINT and ACTIVATE events
    181.         PaintButton lButtonDC
    182.        
    183.     End Select
    184.        
    185. End Function
    186.  
    187. Private Function LoWord(ByVal lValue As Long) As Long
    188.     LoWord = lValue And &HFFFF&
    189. End Function
    190.  
    191. Private Function HiWord(ByVal lValue As Long) As Long
    192.     HiWord = (lValue / &H10000) And &HFFFF&
    193. End Function
    194.  
    195. Private Function IsOverButton(ByVal lPos As Long)
    196.     ' Determine if the specified Coords are within our custom button
    197.     Dim lX As Long, lY As Long
    198.     lX = (LoWord(lPos) - tRECT.Left)
    199.     lY = (HiWord(lPos) - tRECT.Top)
    200.     IsOverButton = (lX >= (lWidth - 75)) And (lX <= (lWidth - 61)) And (lY >= 6 And lY <= 22)
    201. End Function
    202.  
    203. Private Function PaintButton(ByVal lImageDC As Long)
    204.     ' Draw the specified image
    205.     Dim lDC As Long
    206.     ' Track whether the button is currently drawn up or down.
    207.     bDrawnDown = (lImageDC = lButtonDownDC)
    208.     lDC = GetWindowDC(lWindowHandle)
    209.     BitBlt lDC, lWidth - 75, 6, 16, 14, lImageDC, 0, 0, SRCCOPY
    210.     Call ReleaseDC(lWindowHandle, lDC)
    211. End Function
    212.  
    213. Private Sub ButtonClickEvent()
    214.     ' Custom Button Event Code goes Here!
    215.     MsgBox "Smile!!"
    216. End Sub
    In a Form:
    VB Code:
    1. Private Sub Form_Initialize()
    2.     SubclassWindow hwnd
    3. End Sub
    4.  
    5. Private Sub Form_Unload(Cancel As Integer)
    6.     StopSubclass
    7. End Sub
    Or if you prefer I've attached my project files.
    Attached Files Attached Files

  11. #11
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530

    Thumbs up

    Aaron, that is the first subclassing example I have seen that works on NT4, nice. Will this also work on win 9x?


    FOOBAR:

    if i wanted to draw my own bar then i would, other wise i wouldnt post a freaking message here.....so instead of telling me others ways to do it, either keep yoru moth shut, or say,, um im not sure....ok huyak?
    Chill out man, it was a valid suggestion and much easier than doing it with API calls. Out of interest, how old are you?

  12. #12
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    It should, I'm using WinME, there shouldn't be anything O/S speicifc in the code.

  13. #13
    Frenzied Member Skitchen8's Avatar
    Join Date
    Feb 2001
    Location
    Binghamotn, NY
    Posts
    1,943
    Originally posted by Nucleus
    Aaron, that is the first subclassing example I have seen that works on NT4, nice. Will this also work on win 9x?


    FOOBAR:



    Chill out man, it was a valid suggestion and much easier than doing it with API calls. Out of interest, how old are you?
    yeah man chill out, he was trying to help you
    Government is another way to say better…than…you.
    It’s like ice but no pick, a murder charge that won’t stick,
    it’s like a whole other world where you can smell the food,
    but you can’t touch the silverware.
    Huh, what luck. Fascism you can vote for.
    Humph, isn’t that sweet?
    And we’re all gonna die some day, because that’s the American way
    -Stone Sour

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