Results 1 to 12 of 12

Thread: Button on Top?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    175
    Can anyone please tell me how can I put a picture box on the top of a form say ,next to the close(X) button like Zipmagic
    Mass

  2. #2
    Fanatic Member wildcat_2000's Avatar
    Join Date
    Nov 2000
    Location
    Italy
    Posts
    727
    Hi,

    I'm not sure what it is that you want...
    When your car breaks down,
    close all windows and retry

    => please rate all users posts! <=

  3. #3
    Fanatic Member faisalkm's Avatar
    Join Date
    Oct 2000
    Location
    Germany
    Posts
    752

    Talking

    I don't clearly no waht u achually want. I hope u wants to have a graphical form.I f u want to do this, put the form' border style to fixed dialog. Then put a label on the top so that it aliign top (this is for the caption bar) Then select picture boxes and make it's autosize=true and put the picture u want in it. I'm not sure this is waht u want

    Faisal
    Faisal Muhammed
    Homepage:I Started making it in 1994 ...Still Under Construction
    Using

    Visual Basic 6.0 Enterprise SP5
    Embedded Visual Basic 3.0
    SQL Server 2000
    Windows 2000 Proff
    Delphi 6.0


    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    175
    Sorry guys,
    I try to explain, on the title bar of any standard form you got caption ,Minimize button,Maximize button and Close button. What I want is to put another button next to them for example when you install Zipmagic and you open Mycomputer Zipmagic puts it's own button before the Minimize button.
    I want to do the same and put a button on the title bar. I hope I'm clear enough.

    Thanks
    Mass

  5. #5
    Hyperactive Member dsy5's Avatar
    Join Date
    Jul 2000
    Location
    Lockport, NY
    Posts
    362
    The only thing that I can think of is to make the form borderless, put a label along
    the top of the form to simulate a title bar and then create your own picture boxes for
    the minimize, maximize, close, and your WinZip-like button. You will need to create
    your own routines for the regular buttons in their respective On_Click events.
    Donald Sy - VB (ab)user

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    175
    Thanks,
    I know it can be done that way but I thought if Winzip can do it Why can't we.
    Mass

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    175
    Are you all trying to say we can't do it?
    Mass

  8. #8
    Fanatic Member faisalkm's Avatar
    Join Date
    Oct 2000
    Location
    Germany
    Posts
    752
    I'm trying to get a solution..Try hard guys may be we can make it

    Faisal
    Faisal Muhammed
    Homepage:I Started making it in 1994 ...Still Under Construction
    Using

    Visual Basic 6.0 Enterprise SP5
    Embedded Visual Basic 3.0
    SQL Server 2000
    Windows 2000 Proff
    Delphi 6.0


    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    175
    I admire the effort dear Faisal,I know if we try we can comup with somthing.

    Mass
    Mass

  10. #10
    Addicted Member
    Join Date
    Jul 1999
    Location
    Bergen, Norway
    Posts
    143
    This is how to do it in your own program.
    if you tweak it it might work for evry windows window.

    Module:
    Code:
    Option Explicit
    
    '*********************
    '* API Declarations  *
    '*********************
    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
    
    '*********************
    '* Type Declarations *
    '*********************
    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
    
    '*********************
    '* Consts            *
    '*********************
    Const WM_MOVE = &H3
    Const WM_SETCURSOR = &H20
    Const WM_NCPAINT = &H85
    Const WM_COMMAND = &H111
    
    Const SWP_FRAMECHANGED = &H20
    Const GWL_EXSTYLE = -20
    
    '*********************
    '* Vars              *
    '*********************
    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
    Form:
    Code:
    'This is the procedure that is called when you click the button
    Public Sub cmdInTitlebar_Click()
        MsgBox "This is the result of your clicking!!", vbInformation
    End Sub
    
    Private Sub Form_Load()
        Call Init
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        Call Terminate
    End Sub
    Enjoy :)

    -Lumin

    [Edited by lumin on 11-22-2000 at 06:50 PM]

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    175
    Thanks a lot lumin

    I knew someone would come up with a an answer in our bunch, It's a relief.

    I tried to replace the button with a picturebox and abviously I couldn't. The sad story is I am working with vb4-32 which I think dose not support subclassing.

    Colud you please tell me how to convert it to vb4 and replace the button with a picture box?

    P.S. When I say our bunch I don't mean myself included because obviosly I coulden't do it in the first place but,
    (Your bunch) seperates me from my good friends in this forum.
    Mass

  12. #12
    Guest
    Change this line
    Code:
    ButtonHwnd& = CreateWindowEx(0&, "Button", "i", &H40000000, 50, 50, 14, 14, Form1.hwnd, 0&, App.hInstance, 0&)
    To this line (I changed the classname of button to Static)
    Code:
    ButtonHwnd& = CreateWindowEx(0&, "Static", "i", &H40000000, 50, 50, 14, 14, Form1.hwnd, 0&, App.hInstance, 0&)

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