Results 1 to 5 of 5

Thread: Trying to open a form if minimized and close a child

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2016
    Posts
    97

    Trying to open a form if minimized and close a child

    Hoping I explain this properly.

    I have a form that opens a menu. With this menu I can open any one of 4 other 'sub programs' within.

    The menu Program is called PETS CONSOLE

    If I click on the MAIN PROGRAM button on the PETS CONSOLE form it properly opens the MAIN PROGRAM (sub program) parent form with the set default child form preloaded and I can then navigate within the program fine.

    If I click DATA ENTRY button on the PETS CONSOLE it opens the Data Entry form (sub program) fine and I can do as I wish... close the Data Entry program and the Main Menu then pops back to the forefront.

    My issue is once the MAIN PROGRAM loads I cannot exit and have the Menu program reload. I want to be able to exit the MAIN program and reload the minimized menu form upon closing as I can do with the Data Entry form.

    I want to be able to click the "X" on the Parent closing the child and the Parent then check to see if the menu program is minimized and if so, bring it back active otherwise reload the menu form (if someone accidentally closed it for whatever reason). Currently clicking the 'X" (Close) on the main program closes the child fine, closes the parent fine then gives me a 'A new guard page for the stack cannot be created' error and never brings the menu form back from it's minimized state but closes the entire program including the MENU form.

    The code I am trying is as follows (the code below is for a 'close button' on the parent form... not the EXIT/CLOSE button as unsure if can use the same code in the FormClosing event.)

    Code:
        Private Sub NavCloseBtnLoad_Click(sender As Object, e As EventArgs) Handles NavCloseBtnLoad.Click
            NavCloseBtnLoad.BackgroundImage = My.Resources.ButtonClk_Red_Trans
            Dim Console As Process = Process.GetProcessesByName("PETS Console").FirstOrDefault
    
            If Console IsNot Nothing Then
                If IsIconic(Console.MainWindowHandle) Then 'check if the window is minimized. If it is not, then you don't want to restore it, you only need to activate it.
                    SendMessageW(Console.MainWindowHandle, WM_SYSCOMMAND, SC_RESTORE, 0) 'restore the window from it's minimized state.
                Else
                    AppActivate(Console.Id) 'activate it to bring it to the front of all other windows
                End If
            Else
                Process.GetProcesses("C:\MY PROPER PATH\PETS Console.exe")
            End If
    
            Menu1.Close()
        End Sub
    Please feel free to ask for further and specific clarification if required. I did my best to explain it. Any guidance would be greatly appreciated.
    Last edited by K3JAE; May 17th, 2021 at 11:51 AM.

Tags for this Thread

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