Show a window

This is not just showing a window but showing one that's inside an MDI form. I can get the handle of the window without a problem, but using the SetForeGroundWindow or the ShowWindow API will not actually set the desired window to the forefront inside the MDI. I will also like to use the other constants such as SHOWMINIMIZED and SHOWMAXIMIZED. Anyone have any ideas?
microfleetAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Erick37Commented:
This is not your application, but an external MDI application, correct?
0
Erick37Commented:
Option Explicit
Const SW_MAXIMIZE = 3
Const SW_MINIMIZE = 6
Const SW_NORMAL = 1
Const SW_RESTORE = 9
Private Declare Function BringWindowToTop Lib "user32" _
    (ByVal hwnd As Long) As Long
Private Declare Function ShowWindow Lib "user32" _
    (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

Private Sub Command1_Click()
Dim lhWnd As Long
'Grab the MDI child window handle you want
lhWnd = &HCC8
'Maximize the window
Call MyShowWindow(lhWnd, SW_MAXIMIZE)
End Sub

Function MyShowWindow(ByVal lhWnd As Long, _
        Optional ByVal cmdShow As Long = SW_RESTORE) As Long
    Dim lRet As Long
    lRet = ShowWindow(lhWnd, cmdShow)
    MyShowWindow = lRet
    lRet = BringWindowToTop(lhWnd)
End Function
0
microfleetAuthor Commented:
Erick37, I realized earlier that it was an internal error: I was grabbing the EDIT box handle by mistake, but I do like the BringWindowToTop API. I never heard of that one. I will give you the points just because anyone who looks at the question will get a good answer, but I would like to add one thing to my question: Do you have any idea why, after the window is "on top," the SendKeys function sends text only to the window that was previously at the forefront?

It doesnt matter if you know why, I'll still give the points.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ozcustomCommented:
The BringWindowToTop call is a good API to call to merely show the window but it doesn't transfer the focus to that window...

A better way to show a target window - inside the MDI form is to use the SetWindowPos API call using the HWND_TOPMOST constant  (Page 243 of the Visual Basic Programmers Guide to the Win32 API)  - another way to show the desired window is to use the SetActiveWindow however this doesn't set the focus so really a combination of the two API functions

SetWindowPos

and

SetFocusAPI

will ensure that the window you want is on top AND that it has the focus
0
Erick37Commented:
SetFocusAPI will not work on windows outside of the calling process.

If you have been able to use this API to set the focus on an external program's window, I would love to see your code.  This point has been raised before in another question.
0
Erick37Commented:
If you want to activate the MDI child window and give it focus, use this code.  Please note that the question is still locked by ozcustom.

Option Explicit

Const SW_MAXIMIZE = 3
Const SW_MINIMIZE = 6
Const SW_NORMAL = 1
Const SW_RESTORE = 9
Private Declare Function SetActiveWindow Lib "user32" _
    (ByVal hwnd As Long) As Long
Private Declare Function ShowWindow Lib "user32" _
    (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" _
    (ByVal hwnd As Long) As Long

Private Sub Command1_Click()
Dim lhWnd As Long
'Grab the MDI child window handle you want
lhWnd = &HE54
'Maximize the window
Call MyShowWindow(lhWnd, SW_RESTORE)
End Sub

Function MyShowWindow(ByVal lhWnd As Long, _
        Optional ByVal cmdShow As Long = SW_RESTORE) As Long
    Dim lRet As Long
    lRet = ShowWindow(lhWnd, cmdShow)
    MyShowWindow = lRet
    lRet = SetActiveWindow(lhWnd)
    lRet = SetForegroundWindow(lhWnd)
End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
microfleetAuthor Commented:
sorry ozcustom but as I said before I already figured out the trouble and because Erick gave a good answer I was giving the points to him. I wish you would have just left a comment so I wouldnt have to reject your answer but sorry
0
microfleetAuthor Commented:
thanks again
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.