Results 1 to 11 of 11

Thread: [RESOLVED] How To: Make a second app act as though it is a modal form to first app

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Resolved [RESOLVED] How To: Make a second app act as though it is a modal form to first app

    Is this possible?

    I would like that App1 Shells App2. App2 has a button. App2 now stays 'on top' of App1 and App1 cannot be used (like a modal form) until user clicks on App2's button


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  2. #2
    Banned
    Join Date
    Nov 2012
    Posts
    1,171

    Re: How To: Make a second app act as though it is a modal form to first app

    just trying to help i done similar

    app1

    button1_click
    call shell app2
    Me.show.
    end sub


    app2

    formload

    Call FormOnTop(form1.hWnd, True)



    module
    Code:
    Public Sub FormOnTop(hWindow As Long, bTopMost As Boolean)
    ' Example: Call FormOnTop(me.hWnd, True)
        Const SWP_NOSIZE = &H1
        Const SWP_NOMOVE = &H2
        Const SWP_NOACTIVATE = &H10
        Const SWP_SHOWWINDOW = &H40
        Const HWND_TOPMOST = -1
        Const HWND_NOTOPMOST = -2
        
        wFlags = SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW Or SWP_NOACTIVATE
        
        Select Case bTopMost
        Case True
            Placement = HWND_TOPMOST
        Case False
            Placement = HWND_NOTOPMOST
        End Select
        
    
        SetWindowPos hWindow, Placement, 0, 0, 0, 0, wFlags
    End Sub
    declaration
    Code:
    Public Declare Sub InitCommonControls Lib "comctl32.dll" ()
        Public 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
        Public Const HWND_TOPMOST = -1
        Public Const HWND_NOTOPMOST = -2
        Public Const SWP_NOMOVE = &H2
        Public Const SWP_NOSIZE = &H1
        Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
    try and set focus on form
    Last edited by ladoo; Feb 14th, 2013 at 03:40 PM.

  3. #3
    Banned
    Join Date
    Nov 2012
    Posts
    1,171

    Re: How To: Make a second app act as though it is a modal form to first app


  4. #4
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: How To: Make a second app act as though it is a modal form to first app

    Will both apps be created by you?
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How To: Make a second app act as though it is a modal form to first app

    Doesn't work, ladoo, it only makes App2 'on top' of App1


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How To: Make a second app act as though it is a modal form to first app

    Quote Originally Posted by Bonnie West View Post
    Will both apps be created by you?
    Yes, both are mine


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  7. #7
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: How To: Make a second app act as though it is a modal form to first app

    What is App2's button going to do?
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How To: Make a second app act as though it is a modal form to first app

    No, not what I am looking for. This only makes one App a parent to another App but doesn't act like Modal to child App. I don't want Child App embedded into Parent App either


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How To: Make a second app act as though it is a modal form to first app

    Quote Originally Posted by Bonnie West View Post
    What is App2's button going to do?
    That I don't know yet but until it is clicked I want App2 to be modal to App1. That's what I need to get first then I'll worry about button click


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  10. #10
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: How To: Make a second app act as though it is a modal form to first app

    I think this is close enough to your goal:

    Code:
    'App1 - Owner.exe
    
    Private Sub Command1_Click()
        Shell "Owned.exe " & hWnd & " " & App.ThreadID, vbNormalFocus
        Enabled = False
    End Sub
    Code:
    'App2 - Owned.exe
    
    Private Sub Form_Load()
        Dim ArgV() As String
    
        On Error GoTo End_Sub
        ArgV = Split(Command$)
        Subclass Me, ArgV(0), ArgV(1)
    End_Sub:
    End Sub
    Code:
    'App2 - Module1.bas
    
    Option Explicit
    
    Private Const WM_ACTIVATEAPP As Long = &H1C
    Private Const WM_DESTROY     As Long = &H2
    
    Private Declare Function AttachThreadInput Lib "user32.dll" (ByVal idAttach As Long, ByVal idAttachTo As Long, ByVal fAttach As Long) As Long
    Private Declare Function EnableWindow Lib "user32.dll" (ByVal hWnd As Long, ByVal bEnable As Long) As Long
    Private Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hWnd As Long) As Long
    Private Declare Function DefSubclassProc Lib "comctl32.dll" Alias "#413" (ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Private Declare Function SetWindowSubclass Lib "comctl32.dll" Alias "#410" (ByVal hWnd As Long, ByVal pfnSubclass As Long, ByVal uIdSubclass As Long, ByVal dwRefData As Long) As Long
    Private Declare Function RemoveWindowSubclass Lib "comctl32.dll" Alias "#412" (ByVal hWnd As Long, ByVal pfnSubclass As Long, ByVal uIdSubclass As Long) As Long
    
    Public Function Subclass(ByRef Frm As Form, ByVal hWndOwner As Long, ByVal ThreadID As Long) As Boolean
        Subclass = SetWindowSubclass(Frm.hWnd, AddressOf SubclassProc, hWndOwner, ThreadID)
    End Function
    
    Private Function SubclassProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long, _
                                  ByVal hWndOwner As Long, ByVal ThreadID As Long) As Long
        Select Case uMsg
            Case WM_ACTIVATEAPP
                If wParam = 0& Then
                    If lParam = ThreadID Then
                        AttachThreadInput App.ThreadID, lParam, 1&
                        SetForegroundWindow hWnd
                        AttachThreadInput App.ThreadID, lParam, 0&
                        Exit Function
                    End If
                End If
    
            Case WM_DESTROY
                EnableWindow hWndOwner, 1&
                RemoveWindowSubclass hWnd, AddressOf Module1.SubclassProc, hWndOwner
        End Select
    
        SubclassProc = DefSubclassProc(hWnd, uMsg, wParam, lParam)
    End Function
    There's just one flaw: clicking the taskbar button of the owner window activates it. I can't think of a workaround yet.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How To: Make a second app act as though it is a modal form to first app

    Great job, Bonnie. I see no problem clicking on taskbar. Thanks a million, that is just the thing I needed. All I have to do is to add Always On Top which I can do.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width