Page 1 of 1

Ensuring a Window does not have the focus

Posted: Fri Oct 17, 2008 8:35 am
by RichardL
I'm embarrassed by not knowing the answer to this simple question :-(

I need to guarantee that a window does not have the focus prior to using HideWindow(MyWindow,0) to reveal it. In other words I need to ensure that the title bar is grey; just like I have clicked on the desk top.

I can open another window first and use SetActiveWindow(ANOther) but that is a silly solution!

If the user clicks on my window it receives the focus as usual, thats what I want; but when I un-hide it it must not interrupt what he is doing in another application.

How can I ensure that the window does NOT have the focus?

Posted: Fri Oct 17, 2008 8:39 am
by Mistrel
I'm not sure what it is you're asking. Can you try rephrasing your question? Maybe provide example code?

You can identify and set the active window using the Win32 API commands GetActiveWindow_() and SetActiveWindow(). I hope this helps.

Posted: Fri Oct 17, 2008 8:43 am
by ts-soft

Code: Select all

OpenWindow(0, #PB_Ignore, #PB_Ignore, 640, 480, "bla")
DisableWindow(0, #True)

While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend

Posted: Fri Oct 17, 2008 10:13 am
by RichardL
Here is a skeleton of the code I'm writing...

Code: Select all

  MyWindow.l = OpenWindow(#PB_Any,0,0,200,100,"Test",#PB_Window_ScreenCentered)
  AddKeyboardShortcut(MyWindow.l, #PB_Shortcut_Escape, 100)    ; ESC hot key for exit
  StickyWindow(MyWindow.l,1)
  
  While 1
    
    HideWindow(MyWindow,1)     ; Hide the window
    Delay(2000)                ; Wait (Usually about 30 minutes)
    Beep_(1000,10)             ; Attract user's attention
    HideWindow(MyWindow,0)     ; Un-hide the window
    DisableWindow(MyWindow.l,#True)
    
    ; Skeleton of my code that handles user input, timing and comms.
    WaitTime = ElapsedMilliseconds() + 2000 ; Wait duration for user input (Usually 1 minute)
    While WaitTime  > ElapsedMilliseconds() 
      Delay(1)
      Select WindowEvent()
        Case #PB_Event_Menu 
          Select EventMenu()
            Case 100 : Break 2
              
              
              
          EndSelect
          
      EndSelect
      ; Async Comms here
      
    Wend
    
  Wend
How to see my problem...

Open another application that accepts keyboard input (eg: MS Word)
Run my code
Click in the Test window when visible (Test's title bar becomes active)
Wait for Test window to hide
Click on MS Word
Note how Word title bar toggles on/off and keys become inactive when Test window is visible

Wait for Test window to appear and immediately click on desktop.
Test window now toggles on / off but does not have focus.
MS Word title no longer toggles.

How can I ensure that the Test window does NOT have the focus?

Posted: Fri Oct 17, 2008 10:27 am
by Kaeru Gaman
I see your problem.

it occured to me e.g. when I write a posting in FiFo and a download is finished,
the "download ready" popup steals the focus from my text edit element.

I don't know an answer yet, but I think there could be an API way to solve it.
if you have the nerve, search the MSDN (ok, sounds like kidding)
for e.g. "unhiding window without retrieving the focus" or such.

Posted: Fri Oct 17, 2008 10:41 am
by PB
Try:

Code: Select all

ShowWindow_(WindowID(#num),#SW_SHOWNOACTIVATE)

Posted: Fri Oct 17, 2008 10:55 am
by Kaeru Gaman
PB wrote:Try:

Code: Select all

ShowWindow_(WindowID(#num),#SW_SHOWNOACTIVATE)
cool, works fine here! Image

Posted: Fri Oct 17, 2008 10:57 am
by RichardL
Hi PB,

That appears to do the trick! :D :D :D
Here is the modification to my example code...

Code: Select all

    HideWindow(MyWindow,1)     ; Hide the window
    Delay(2000)                ; Wait (Usually about 30 minutes)
    Beep_(1000,10)             ; Attract user's attention
    ;HideWindow(MyWindow,0)     ; Un-hide the window
    ;DisableWindow(MyWindow.l,#True)
    ShowWindow_(WindowID(MyWindow),#SW_SHOWNOACTIVATE)
Thanks to all,
RichardL