B4J Question Problem with setting the NotePad ++ application window

T201016

Active Member
Licensed User
Longtime User
Hello everyone,

I would like the invisible windows of both applications "Notepad ++. exe" or "Notepad.exe" to set visible on top in both cases when :
- the window is minimized to the taskbar;
- the window is only invisible on the desktop.


1. An example works on the "Notepad++.exe" application when its window is not minimized to the taskbar.
2. It does not work at all for a system notebook

What can I improve in my code ?
Thank you.

Required:
#AdditionalJar: jna-5.17.0
#AdditionalJar: jna-platform-5.17.0
 

Attachments

  • Example.zip
    2.5 KB · Views: 25
Solution
I went down the rabbit hole with inline java, but then found the correct methods.

Try this:

B4X:
Sub Button1_Click
   
    Dim FindTitle As String = "D:\TMP\Q.txt - Notepad++"
'    Dim FindTitle As String = "Q.txt - Notepad"
   
    Dim windowUtils As JavaObject
    windowUtils.InitializeStatic("com.sun.jna.platform.WindowUtils")
    Dim Jo1 As JavaObject
    Dim Instance As JavaObject = Jo1.InitializeStatic("com.sun.jna.platform.win32.User32").GetField("INSTANCE")
    Dim L As List = windowUtils.RunMethod("getAllWindows",Array(False))
    Dim Found As Boolean
    For Each Window As JavaObject In L
        Dim Title As String = Window.RunMethod("getTitle",Null)
       
        'Just to see the title formats
        If...

stevel05

Expert
Licensed User
Longtime User
I went down the rabbit hole with inline java, but then found the correct methods.

Try this:

B4X:
Sub Button1_Click
   
    Dim FindTitle As String = "D:\TMP\Q.txt - Notepad++"
'    Dim FindTitle As String = "Q.txt - Notepad"
   
    Dim windowUtils As JavaObject
    windowUtils.InitializeStatic("com.sun.jna.platform.WindowUtils")
    Dim Jo1 As JavaObject
    Dim Instance As JavaObject = Jo1.InitializeStatic("com.sun.jna.platform.win32.User32").GetField("INSTANCE")
    Dim L As List = windowUtils.RunMethod("getAllWindows",Array(False))
    Dim Found As Boolean
    For Each Window As JavaObject In L
        Dim Title As String = Window.RunMethod("getTitle",Null)
       
        'Just to see the title formats
        If Title.Contains("Q.txt") Then Log(Title)
       
       
        If Title = FindTitle Then
            Found = True
            Dim Hwnd As JavaObject = Window.RunMethod("getHWND",Null)
            If Initialized(Hwnd) Then
                Instance.RunMethod("ShowWindow",Array(Hwnd,Instance.GetField("SW_RESTORE")))
                Instance.RunMethod("SetForegroundWindow",Array(Hwnd))
            End If
        End If
    Next
    If Not(Found) Then Log($"Window ${FindTitle} not found"$)
   
End Sub
 
Last edited:
Upvote 0
Solution
Top