Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 63749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:40:53+00:00 2026-05-10T18:40:53+00:00

My application is a vb6 executable, but some newer forms in the system are

  • 0

My application is a vb6 executable, but some newer forms in the system are written in C#. I would like to be able to set the C# form’s Owner property using a handle to the main application window, so that the dialogs remain on top when tabbing back and forth between my app and other apps.

I can get the hwnd of the main application window. I’m not sure what I can do from there?


UPDATE Oct 20 ’08 at 17:06:

Scott,

Thanks for the response. I had overlooked that the Show/ShowDialog method parameter was not of type Form – I was looking only at the Owner property.

I slightly modified the code I’m using from the above – we have a component that generically loads our Forms and calls ShowDialog. My code looks like this:

Form launchTarget = FormFactory.GetForm(xxx);  // psuedo-code for generic form loader launchTarget.StartPosition = FormStartPosition.CenterParent; IWin32Window parentWindow = GetWindowFromHwnd(hwnd);  launchTarget.ShowDialog(parentWindow); 

GetWindowFromHwnd is a method-wrapped version of your code:

private IWin32Window GetWindowFromHost(int hwnd) {     IWin32Window window = null;     IntPtr handle = new IntPtr(hwnd);      try     {         NativeWindow nativeWindow = new NativeWindow();         nativeWindow.AssignHandle(handle);         window = nativeWindow;     }     finally     {         handle = IntPtr.Zero;     }      return window; } 

Unfortunately this isn’t doing what I’d hoped. The form does display modally, but it’s not showing up in the correct position nor is it still on top when I tab away and back to the parent window. Our modals do not show a task in the taskbar, so the window seemingly ‘disappears’ (although it is still present in the alt-tab window list). That to me indicates I might not have the right hwnd. If you have any other suggestions though, please reply back. Thanks again.


UPDATE Nov 10 ’08 at 16:25

One follow up remark – If you factor it out into a method call in a try/finally, as in Scott’s 2nd post, the call in the finally block should be:

parentWindow.ReleaseHandle(); 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T18:40:53+00:00Added an answer on May 10, 2026 at 6:40 pm

    So you are calling a C# Windows Form class from VB6, which means you are probably using either Show() or ShowDialog(), correct? Both of those methods also take an IWin32Window parameter, which simply defines an object that returns an IntPtr property named Handle.

    So…you need to add an overloaded constructor (or ShowDialog method) for your Windows Forms classes which take a long as a parameter so you can pass the VB6 hwnd to the form. Once inside the C# code, you need to create an IntPtr from the hwnd and assign it to a NativeWindow object and then pass that as the owner.

    Something like this should work, although it’s untested:

    public DialogResult ShowDialog(long hwnd) {    IntPtr handle = new IntPtr(hwnd);    try    {       NativeWindow nativeWindow = new NativeWindow();        nativeWindow.AssignHandle(handle);       return this.ShowDialog(nativeWindow);    }    finally    {       handle = IntPtr.Zero;    } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 61k
  • Answers 61k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Try something like this: $result = preg_match('/ ^ ([^(]+?) (\s*… May 11, 2026 at 9:43 am
  • added an answer I would say it would be a fairly significant factor.… May 11, 2026 at 9:43 am
  • added an answer Use a label on the outermost loop, and include this… May 11, 2026 at 9:43 am

Related Questions

My application is a vb6 executable, but some newer forms in the system are
Part of my everyday work is maintaining and extending legacy VB6 applications. A common
My application is a viewer for a custom format, a zip file with a
Question says it all, really. My application is a time tracker. It's currently written
My application is preparing a cover-sheet for submitting documents by fax. I identify the
My application is implemented as a service (running under services.exe). I am adding a
In my web application there is a process that queries data from all over
I need to detect whether my application is running within a virtualized OS instance
My application is pretty simple: it starts up with a view controller that holds
Here is a simplified version of my application showing what I'm doing. /* in

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.