B4J Question Communicating with Windows System

Brian Dean

Well-Known Member
Licensed User
Longtime User
I have a program that I wrote some time ago in Delphi that I am translating into B4J. It is a small utility that modifies filenames. It is easy enough to convert the code except for the following line :
B4X:
  SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0)

I know nothing about Windows System programming - I simply copied this line from the internet without understanding how it works. The code causes any open File Explorer window to be updated, so showing any filename changes.

How can I replicate this action using B4J? I assume that there is no direct equivalent in Java. Would it be possible to invoke a batch file to achieve the same end, in which case how would I run the batch file and what would it contain?

My tentative backup plan is to write a "one-line" Delphi program and try to run that from B4J, although I am not sure how to handle repeat invocations.

Thanks for any advice.
 

Brian Dean

Well-Known Member
Licensed User
Longtime User
Okay - I have downloaded the JNA libraries and I have successfully run an example provided here by @stevel05 , but I don't know enough Java to make progress on my problem.

I have found the following code (language unspecified) that is probably what I need to replicate in B4J -

B4X:
    Private Const HWND_BROADCAST = &HFFFF
    Private Const WM_SETTINGCHANGE = &H1A
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Object) As Long

    Private Sub ExplorerRefresh()
        SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0)
    End Sub

Can anyone move me further forward?
 
Upvote 0
Top