Bring Dialog to Front and give "general focus"

Started by User_McUser, November 09, 2023, 01:34:10 PM

Previous topic - Next topic

User_McUser

I want to have a tool-bar like script that runs without a Taskbar icon but instead has a System Tray icon. When the tray icon is clicked, I want the dialog to be brought to the front and for it to get focus. Using the below code in my dialog call-back does half of what I want:

Code (winbatch) Select

theClick = IntControl(1007,0,0,0,0)
if theClick == 1 then
   WinActivate("")
   WinHide("") ;Hide the "WinBatch Running" Window
endif


With this code when I click on the tray icon it brings the window to the top of the stack as expected BUT the title bar of the dialog remains "inactive" and keyboard input gets sent to the Taskbar/Start Menu instead of to the WinBatch dialog. (FWIW, I'm using IntControl(1007,1,1,"ToolTip Text Placeholder","") to create the tray icon.)

How do I take focus "generally?" Like without having to pick one of the controls in my Dialog and call DialogControlState?

If it matters, the above click code lives inside the MSG_TIMER block in the callback function.

Thanks!  :)

PS: I'll also note that once I invoke WinActivate("") the WinHide("") function does NOT hide the "WinBatch Running" window but I don't know why.

td

Out of curiosity, why do you have the script snippet you posted inside a dialog callback? Why not just launch the dialog when the icon is clicked? The dialog should then have the focus when it starts.

WinActivate is a complicated function. It has several approaches depending on the target window's current state and the current IntControl 61 settings. It also has some system-imposed time delays between when the function issues a command and when it is received by the target window. But that begs another question. Why call WinActivate on a window and then immediately call WinHide? If you intend to activate the dialog window you need to specify the dialog title or the dialog window ID as the parameter to the WinActivate function. Activating the WinBatch parent window is not the same as activating the dialog window in most cases.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

You could peek at the "popmenu.mnw" menu file that is part of PopMenu. It can launch a dialog-based script by starting another instance of WinBatch.exe.

Here is a Tech DB article that illustrates how to make a homegrown PopMenu-like application:

https://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/FileMenu~and~PopMenu/PopMenu+Create~your~own~Popmenu~like~WinBatch~script.txt
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

User_McUser

Quote from: td on November 09, 2023, 02:45:07 PM
Out of curiosity, why do you have the script snippet you posted inside a dialog callback? Why not just launch the dialog when the icon is clicked? The dialog should then have the focus when it starts.

The dialog is already "open" (just buried in the Z-order) when the tray icon is being clicked so not sure what launching the dialog again would do? I didn't want to invoke a second instance of it? I am not 100% sure how dialogs work in this situation...

I'm also uncertain where in the script I would add the handler for tray icon clicks. I'm using a timer in the dialog callback to monitor a pipe for incoming data (which may not be the best way? I've never done a script like this before), so I just stuck it in there because I know it'll get checked every 250ms. So far it seems to work as the script responds to both piped data and user clicks on both the dialog buttons and the tray icon.

QuoteWinActivate is a complicated function. It has several approaches depending on the target window's current state and the current IntControl 61 settings. It also has some system-imposed time delays between when the function issues a command and when it is received by the target window. But that begs another question. Why call WinActivate on a window and then immediately call WinHide? If you intend to activate the dialog window you need to specify the dialog title or the dialog window ID as the parameter to the WinActivate function. Activating the WinBatch parent window is not the same as activating the dialog window in most cases.

My intent was to show my dialog but hide the "Winbatch is running" window and taskbar icon that WinActivate was unhiding.

Using WinActivate with the dialog title does exactly what I wanted - I didn't think about it being a separate window that I could call by name, but of course it is.  ;D

Thank you!  :)