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
Printable View
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
Hi,
I'm not sure what it is that you want...
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
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
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.
Thanks,
I know it can be done that way but I thought if Winzip can do it Why can't we.
Are you all trying to say we can't do it?
I'm trying to get a solution..Try hard guys may be we can make it
Faisal
I admire the effort dear Faisal,I know if we try we can comup with somthing.
Mass
This is how to do it in your own program.
if you tweak it it might work for evry windows window.
Module:
Form: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
Enjoy :)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
-Lumin
[Edited by lumin on 11-22-2000 at 06:50 PM]
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.
Change this line
To this line (I changed the classname of button to Static)Code:ButtonHwnd& = CreateWindowEx(0&, "Button", "i", &H40000000, 50, 50, 14, 14, Form1.hwnd, 0&, App.hInstance, 0&)
Code:ButtonHwnd& = CreateWindowEx(0&, "Static", "i", &H40000000, 50, 50, 14, 14, Form1.hwnd, 0&, App.hInstance, 0&)