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 7899781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:47:52+00:00 2026-06-03T08:47:52+00:00

I’m working on a multithreaded TDI UI (using C1 DockingTabs if you are interested).

  • 0

I’m working on a multithreaded TDI UI (using C1 DockingTabs if you are interested). So far, I’ve managed to get each window to open in a separate thread and to use the SetParent Win32 API to put it inside the appropriate tab. I’ve also managed to get modal dialogs to show within the tab as well and not block the other tabs from working (by adding a handler on the Shown event on the dialog form to call SetParent again – some fiddling involved with turning on and off TopLevel on the form within the tab, but it works).

Now, what is happening which is a little annoying is that the dialog is opening, which removes focus from the TDI parent form and then focus is immediately being put back. If I call SetParent before showing it, I just get an exception because you can’t have a modal dialog on a form which has a parent. I’ve managed to get around the window animation slide/fade in and out by giving it a size of 0,0 until it is inside the tab, but I can’t work out how to stop the focus flicking off and back on the main parent form.

I imagine that there are 2 possible approaches:

  1. disable the window effect which makes it look like it has lost the focus (blocking Window messages maybe?)
  2. actually really stopping it losing the focus

I appreciate that this is a bit of an unusual query, so really glad for any help!


EDIT:

To clarify the point in the exercise – I’ve got a tabbed based UI where each tab is effectively independent. I have had a complaint from the end users that each time something calls ShowDialog, it blocks the entire app instead of just that one tab. The only way that I can see to get around that (short of multi-process like Google Chrome), is to give each tab a separate UI thread and load the dialog inside the tab so that users can still access other tabs. I’ve managed to remove some of the hackiness to some degree and to fix most of the problems now (just been playing some more). I’ve actually managed to fix the question that I asked by blocking the WM_NCACTIVATE message on the main form, although that is a bit messy since now it never shows as deactivated. I guess I’ll have to detect whether the activated form is a dialog child of this one to decide whether to activate or not. I’ve also got some flickering to try to resolve, but it is looking a lot better. I would post code, but there are 3 forms involved so short of uploading the project it would be a bit messy. I’ll see if I can reduce it if anyone is curious?

I’m currently just playing with it as a proof of concept – if I get this working then I need to retrofit it to my existing application, which is where the real fun starts! I have got a framework for controlling the TDI aspects though, so it should be reasonably straightforward from that respect. The real nightmare is going to be auditing the entire thing to work out possible synchronisation issues across the different threads since there are some shared resources that aren’t inherently thread safe.

  • 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. Editorial Team
    Editorial Team
    2026-06-03T08:47:54+00:00Added an answer on June 3, 2026 at 8:47 am
    Friend NotInheritable Class Win32
      Public Const WM_NCACTIVATE = &H86
      Public Const WM_SDLG_ACTIVATE = &H8000
    
      <DllImport("user32.dll")> Public Shared Function GetForegroundWindow() As IntPtr
      End Function
    
      <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
      Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
      End Function
    End Class
    

    To stop the main form appearing to lose the focus when in the dialog – in the main form: –

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    
        Select Case m.Msg
            Case Win32.WM_NCACTIVATE
                Dim m2 As New System.Windows.Forms.Message()
                m2.HWnd = m.HWnd
                m2.Msg = m.Msg
                m2.LParam = m.LParam
    
                Dim fgwh = Win32.GetForegroundWindow()
    
                m2.WParam = If(fgwh = Handle, 1, 0) 'title bar state - TRUE for active
                m.Result = 1 'TRUE to do default processing, FALSE to block
                MyBase.WndProc(m2)
                Exit Sub
    
            Case Win32.WM_SDLG_ACTIVATE
                Dim m2 As New System.Windows.Forms.Message()
                m2.HWnd = m.HWnd
                m2.Msg = Win32.WM_NCACTIVATE
                m2.LParam = m.LParam
    
                Dim fgwh = Win32.GetForegroundWindow()
    
                If m.WParam = 0 Then
                    m2.WParam = If(fgwh = Handle, 1, 0) 'title bar state - TRUE for active
                Else
                    m2.WParam = 1
                End If
    
                m.Result = 1 'TRUE to do default processing, FALSE to block
                MyBase.WndProc(m2)
                Exit Sub
    
    
        End Select
    
        MyBase.WndProc(m)
    End Sub
    

    And in the sub-form: –

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If m.Msg = Win32.WM_NCACTIVATE Then
    
            Dim fgwh = Win32.GetForegroundWindow()
            Dim wParam As IntPtr
            If fgwh = Me.Handle OrElse fgwh = MainForm.Instance.Handle Then
                wParam = 1
            Else
                wParam = 0
            End If
    
            Win32.SendMessage(MainForm.Instance.Handle, Win32.WM_SDLG_ACTIVATE, wParam, m.LParam)
        End If
    
        MyBase.WndProc(m)
    End Sub
    

    To stop the main form being deactivated and to get , in the dialog form class: –

    Protected Overrides ReadOnly Property ShowWithoutActivation As Boolean
        Get
            Return True
        End Get
    End Property
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to

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.