 |
jahsen Level: Professor
 Registered: 08-01-2005 Posts: 72
|
MDI child always on top of another MDI child
i need a MDI child to be always on top of another MDI child is this possible?
|
|
27-01-2005 at 07:28 PM |
|
|
humberto Level: VB Lord
 Registered: 13-01-2005 Posts: 246
|
Re: MDI child always on top of another MDI child
Use the WIN32 API called SetWindowPos as follows
res = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or
SWP_NOSIZE)
hwnd is the handle to your form
HWND_TOPMOST is a const with value -1
for the other parameters see the MSDN to see what fits you most.
However this method will keep your form on top of every window even if
you switch to another Application.
To deal with this you need to subclass the form and to catch the
WM_ACTIVATEAPP
message and if wParam is 0 then change the window pos back like this
res = SetWindowPos(hwnd, HWND_NOTTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or
SWP_NOSIZE)
if wParam is 1 then make it TOPMOST again with the first call.
this will cause your form to disappear when another App is activated,
and reappear as TOPMOST window when your App is activated again.
Hope this helps.
|
|
27-01-2005 at 07:31 PM |
|
|
jahsen Level: Professor
 Registered: 08-01-2005 Posts: 72
|
Re: MDI child always on top of another MDI child
sounds intresting although forgive me but i am a newbie in VB
where do i get this?
Use the WIN32 API called SetWindowPos as follows
is it in the project components?
|
|
28-01-2005 at 07:31 PM |
|
|
Goran Level: Moderator
 Registered: 16-05-2002 Posts: 1681
|
Re: MDI child always on top of another MDI child
Widows API's are located in Windows dll's. For instance, this particular function SetWindowsPos is located in user32.dll. In order to use it, you need to declare it. Here are the declarations of constants and API that Humberto adviced you to use. You can paste this code in form.
Const HWND_TOPMOST = -1
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1
Private Declare Sub 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)
Private Sub Form_Load()
SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End Sub |
____________________________
If you find the answer helpful, please mark this topic as solved.
|
|
28-01-2005 at 08:21 PM |
|
|
Goran Level: Moderator
 Registered: 16-05-2002 Posts: 1681
|
Re: MDI child always on top of another MDI child
... hmm.. you could uncheck option in windows "keep the taskbar on top of other windows", it will allow all windows (not just yours) to be over task bar. Right click on taskbar, select properties and there you will find the option,
Or you can try finding the key in regostry for Kepping taskbar on top and to change it through code.
Another way is to set forms borderstyle to anything but sizable, and maximize it.
Or you can try messing with API's. For instance, you can hide TaskBar while your app is working, and set forms width/height to screen's width/height (not maximized). If the form is closed (or minimized), you can show taskbar again, etc etc. But still. If you maximise the form, it will show empty space where taskbar used to be, since workarea doesnt include taskbar space (if "keep taskbar option on top" is checked"). To work around this, you would then need to use SystemParametersInfo API to set workarea to screen size. And you would need to deal with many kinds of problems that will arise if app was not closed properly, so Windows settings were not returned in their previous state.... If I were you, I would diregard this method.
____________________________
If you find the answer helpful, please mark this topic as solved.
|
|
30-01-2005 at 07:28 PM |
|
|
pavane Level: VB Lord
 Registered: 26-04-2004 Posts: 179
|
Re: MDI child always on top of another MDI child
Hi,
I used this example in my program, but have had complaints from users that it stays on top of EVERYTHING.
Is there any way to make it stay on top of all forms in this program but not on top of other programs?
|
|
14-02-2005 at 08:30 AM |
|
|
sandeepnitin Level: Trainee
 Registered: 22-07-2005 Posts: 1
|
Re: MDI child always on top of another MDI child
Hi Goran,
You have written sample code for the MDI Child to stay on top.
-------------------------------
Const HWND_TOPMOST = -1
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1
Private Declare Sub 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)
Private Sub Form_Load()
SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End Sub
----------------------------------
But it does not work when i move focus on another child. it doesn not stay on top.
Can u have any idea to make a mdi child to stay on top even if any other mdi child gets activated.
|
|
22-07-2005 at 01:24 AM |
|
|
Dhananjayan Level: Trainee
 Registered: 08-09-2005 Posts: 2
|
Problem in using SetWindowPos()
I have a probelm regarding to use the SetWindowPos(). The widow does not became active when I use this. I use SetActiveWindow() for activating it. But still it is not working as well. My problem is that in setting the window to the Top of the Z-Order. So pls help me.
Dhana
____________________________
Dhana
|
|
08-09-2005 at 01:25 PM |
|
|
|
|
 |
 |