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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB 6 / VB.Net/ WinAPI Issues

Status
Not open for further replies.

hawkdernacht

Programmer
Mar 10, 2005
15
US
For those of you in other forums, please forgive the cross-post but this does touch multiple topics.

I am a VB.Net developer, creating a vb.net application that "hooks" into a VB6 application. When the VB6 application starts up it calls my dll via COM, and my code opens up a form. That is all well and good, but I want my form to act as a child of the VB6 app. My goal is to have a floating tool window similar to the Find window in Visual Studio. The simple thing to do would be to set my form's TopMost property to true, but I don't want it to be on top of every form, just on top of the VB6 app.

I have tried using the SetParent Win32 API call. Here is an example of the pseudo code I have used:

Dim hVb6App as IntPtr = win32.FindWindow(IntPtr.Zero, IntPtr.Zero, strClassName, strApplicationName)

dim hDotNetForm as IntPtr = myForm.Handle

SetWindowLong(hDotNetForm, GWL_STYLE, WS_CHILD Or WS_VISIBLE)

SetParent(hDotNetForm, hVb6App)

This seems to successfully set my form to be a child, as my form no longer shows up in the Task Bar or Task Switcher (Alt Tab), but all I see is a brief flash of my form and then it is hidden.

I have played around with every combination of setting on the .net form and/or win api calls that I can think of, so I leave it to you my excellent peers, to tell me what I am doing wrong.

I thank you all in advance for any help you can offer. Please let me know if there is anything else I can elaborate on to make my situation more clear.

Regaurds

The Nighthawk,
"Don't try to reinvent the wheel, unless you can make it better.
 
From the help files...

WS_VISIBLE Creates a window that is initially visible.

With help running, type in WS_CHILD using the index tab. This should take you to Window Styles where you can read the various settings.

Then you might want to consider this API...
[tt]
Private Const HWND_NOTOPMOST = -2
Private Const HWND_TOPMOST = -1
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
[/tt]
called (vb6 example to set window top most)...
[tt]
SetWindowPos Me.hwnd, HWND_TOPMOST, 100, 100, (Me.Width / Screen.TwipsPerPixelX), (Me.Height / Screen.TwipsPerPixelY), 0
[/tt]

you may want to use SWP_SHOWWINDOW as the last parameter instead of 0.

And more information from the help files about the SetWindowLong API...

Remarks
The SetWindowLong function fails if the window specified by the hWnd parameter does not belong to the same process as the calling thread.

Certain window data is cached, so changes you make using SetWindowLong will not take effect until you call the SetWindowPos function.

Good Luck

 
vb5prgrmr, thanks for your help. I have implemented SetWindowsPos, trying both HWND_TOPMOST and HWND_TOP as well as the SWP_SHOWWINDOW parameter. The behavior as just as before. If I comment out the call to SetParent, I can see that SetWindowsPos is working, and it does return a non-zero value indicating a successful call to the function.

Any more thoughts?

Regaurds

The Nighthawk,
"Don't try to reinvent the wheel, unless you can make it better.
 
One other thought, don't know if this changes anything or not, but I am not looking for a MDI parent-child relationship. I am looking for a top level window parent-child relationship.

Regaurds

The Nighthawk,
"Don't try to reinvent the wheel, unless you can make it better.
 
Just a thought, reverse the order of long and parent i.e. putting parent first and test. Then again I could be trying to talk from left field... :)
 
Again, thanks for the suggestion, but no joy over here.

Regaurds

The Nighthawk,
"Don't try to reinvent the wheel, unless you can make it better.
 
vb5prgrmr, thanks again for all your help, unfortunately this has not solved my problems.

Regaurds

The Nighthawk,
"Don't try to reinvent the wheel, unless you can make it better.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top