1

I have used StackOverFLow a few times to steal snippets. This time I have a question since my thievery skills seem to have diminished. I'm using VB.NET.

I have a NoteButton in MyApp. The first time NoteButton is clicked Notepad starts with a particular text file. On subsequent clicks of NoteButton - if NotePad and the file are open then activate Notepad.

If NotePad has been minimized how do I change the WindowState / AppWinstyle to "normal" and bring it to the foreground?

Here is what I have...


    On Error GoTo EHandler
    Dim TheDirectory = MyApp.My.Application.Info.DirectoryPath
    If IsRunningExe("notepad.exe") Then  'Check if notepad is already running
        On Error Resume Next
        AppActivate("MyList.txt - Notepad")
        If Err.Number <> 0 Then
            Err.Clear()
            Process.Start("notepad.exe", TheDirectory & "\MyList.txt")
        End If
                    'I need to restore a minimized Notepad to "Normal" state and in the foreground 
                     here.
        Exit Sub
    End If
    Process.Start("notepad.exe", TheDirectory & "\MyList.txt")
    Exit Sub
    EHandler:
    MsgBox("There was an error opening the text file.", vbOKOnly + vbInformation)

Thanks for your time,

Greg

5
  • Google "vb.net ui automation restore window". Sample hit. Commented Nov 24, 2020 at 20:45
  • This SO question should be able to help you out: Restore a minimized window of another application. It's in C# but you should be able translate it easy enough
    – JayV
    Commented Nov 24, 2020 at 20:47
  • You can use IsIconic()...example here.
    – Idle_Mind
    Commented Nov 24, 2020 at 21:16
  • 1
    In .net, please don't use On Error GoTo.... We have Exception and Try...Catch...Finally...End Try
    – Mary
    Commented Nov 25, 2020 at 0:04
  • Thanks to all for the help. I did get it working but to avoid any embarrassment on my side - I won't post my code here. Mary - I learned VBA when the Excel 4.0 macro language was abandoned and I was forced to port my add-in app over from the macro language to VBA. It wasn't easy. That was in about 1996. My first dip into vb.Net is this app. It does what I need and want (it talks to my 3D printer). It's good enough and nobody else will have to come behind me and straighten out my spaghetti. Commented Nov 28, 2020 at 1:10

0

Browse other questions tagged or ask your own question.