|
-
Sep 28th, 2006, 11:39 AM
#1
Thread Starter
Addicted Member
form above form
hey guys, i need some basic help. i've the main form and when i click a buttom a small form is displayed. But when i accidently click on the main form the smallest form hides behind the main. My main form is fixed and not moveble, because i want it like that. How can i do to set the small form above the main form until i press cancel button.???
-
Sep 28th, 2006, 11:51 AM
#2
Re: form above form
show the small form modally:
-
Sep 28th, 2006, 12:05 PM
#3
Thread Starter
Addicted Member
Re: form above form
One problem.. the small form is mdichild....
-
Sep 28th, 2006, 12:06 PM
#4
Thread Starter
Addicted Member
Re: form above form
solved, i set it to not show in taskbar and remove MDIChild
thks alot
-
Sep 28th, 2006, 12:08 PM
#5
Re: form above form
no probs, an alternative would have been to use the SetParent API, and place the small form inside the "main" form (i presume that is also a MDIChild)
-
Sep 28th, 2006, 12:53 PM
#6
Fanatic Member
Re: form above form
This is exactly what I want but can someone explain to me what I need to do to get it happening? I would like a form to be restricted to (or is inside) the main form so that when I press the minimise button the child form goes with it?
-
Sep 28th, 2006, 12:55 PM
#7
Re: form above form
VB Code:
Private Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Sub Command1_Click()
SetParent frmChild.hWnd, frmMain.hWnd
End Sub
-
Sep 28th, 2006, 01:17 PM
#8
Fanatic Member
-
Sep 28th, 2006, 01:21 PM
#9
Fanatic Member
Re: form above form
If you use the SetParent API, the forms will not high-light properly when selected. If you want to fix this, you have to sub-class out the forms. I can provide the code, however I will also warn you that if you do so, you can no longer debug the program while using the VB IDE, or you will almost always lock-up VB. This means you can not use the pause or step buttons or breakpoints once you begin the sub-classing. All debugging MUST be done though logs (and I would recommend that you compile to an EXE and execute the EXE instead of using the VB run command to make sure you don't accidently pause the program).
-
Sep 28th, 2006, 01:49 PM
#10
Re: form above form
here's a class from vbAccelerator which (in collaboration with the SSubTmr6.dll) can sort out the active titlebar thing
-
Sep 28th, 2006, 01:59 PM
#11
Fanatic Member
Re: form above form
Or you can just use this code:
VB Code:
Option Explicit
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 Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private mdiChildren As New Collection
Private Const WM_ACTIVATE = &H6
Private Const GWL_WNDPROC = (-4)
Private lngMasterWindowProc As Long
Private lngMasterWindowHWnd As Long
Public Function WindowProc_Child(ByVal hWnd As Long, ByVal MSG As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'Handle the messages that Windows sends
Select Case MSG
Case WM_ACTIVATE
'When Windows tells us the window is activated, notify the parent window of the activation
CallWindowProc lngMasterWindowProc, hWnd, MSG, wParam, lParam
End Select
'Call the standard Windows procedure of the child
WindowProc_Child = CallWindowProc(mdiChildren.Item("x" & hWnd), hWnd, MSG, wParam, lParam)
End Function
Public Sub InitializeSubclassing(MasterWindowHWnd As Long)
'Get the Windows Proc of the master window
lngMasterWindowProc = GetWindowLong(MasterWindowHWnd, GWL_WNDPROC)
'Store the HWND for our usage later
lngMasterWindowHWnd = MasterWindowHWnd
End Sub
Public Sub MakeMDIChild(ChildWindowHWnd As Long)
'Record the old windows proc for the MDI child.
mdiChildren.Add GetWindowLong(ChildWindowHWnd, GWL_WNDPROC), ("x" & ChildWindowHWnd)
'Begin subclassing the new child window
SetWindowLong ChildWindowHWnd, GWL_WNDPROC, AddressOf WindowProc_Child
'Set the parent of the child, making it a MDI child window
SetParent ChildWindowHWnd, lngMasterWindowHWnd
End Sub
Public Sub RemoveMDIChild(ChildWindowHWnd As Long)
'Reset the child window's windows proc to its default, removing our subclassing
SetWindowLong ChildWindowHWnd, GWL_WNDPROC, mdiChildren.Item(("x" & ChildWindowHWnd))
'Remove the record of the MDI child
mdiChildren.Remove ("x" & ChildWindowHWnd)
End Sub
It must be placed into a non-class module (although it could be adapted to a class module, if you wanted to).
The first call should be to the InitializeSubclassing function. Once that is called, any number of calls may be made to the MakeMDIChild and RemoveMDIChild functions. The forms must be loaded prior to the calls, and the forms must be unloaded after a call to the RemoveMDIChild function.
I could continue to improve the code, but the main program I am using it in has a ton of other functions required for the calls anyways.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|