Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with API and Window focus

Status
Not open for further replies.

dazzer123

IS-IT--Management
Nov 24, 2003
128
GB
Hi, I have a vb.net Parent form which contains a child form, on the click of a button on the child Microsoft Excel is opened and, using some API calls and the handle of Excel and the vb.net Parent Form, Excel is then set as a child of the vb.net Parent.

The problem I am having is that when you minimize my application and then click on the taskbar to restore my application it is restored and given focus but remains behind the currently open windows, I suspect it is because I have these two applications (Mine and Excel) 'tied' together and it is having problems restoring both, does anyone have any ideas as to how I can solve this problem.
 

Check out SetWindowPos with an arguement of HWND_TOP or perhaps the SetActiveWindow and another may be the SetForegroundWindow. For more information look in the help files under Window Functions.

Good Luck


 
Hi, sorry for not replying sooner, presumably what your suggesting is that on the VB windows on activate or on focus event I ensure that, by using SetWindowPos or SetForegroundWindow, the excel sheet is the topmost window. I'll give this a go and let you know how I get on.
 
Bit of a late post on this but I have only just had the chance to look at it.

The problem was I wasn't setting the WS_CHILD Style bit before calling SetParent.

The below example uses Microsoft Mappoint and not excel but the theory is still the same.

Code:
        MpOpen = FindWindowNullClassName(0, "Map - Microsoft Mappoint Europe")

        formHandle = Me.Handle.ToInt32
        'Set style bits to be ready for change
        retval = SetWindowLong(MpOpen, GWL_STYLE, WS_CHILD Or WS_VISIBLE)

        'Set Parent window as form
        SetParent(MpOpen, formHandle)
        'Remove blue caption bar
        retval = retval And Not WS_CAPTION
        SetWindowLong(MpOpen, GWL_STYLE, retval)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top