March 28, 2024, 07:20:39 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Setting the focus back to your program

Started by Andy, November 23, 2018, 03:57:14 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

A normal process of using a program, then minimising it or opening another program for example means your program loses focus.

In the constants search program version 5 (and below - link here):
https://www.ionicwind.com/forums/index.php?topic=6245.msg45852;topicseen#msg45852

You will see that when you click on a constant in the list view and then select "Search the Internet" your browser will open and show you the search results, okay no problem there.

But when you return to your program (in this case the constants search program), the program itself has lost focus. So trying to use the Up and Down keyboard keys to navigate the list view does not work.

Now wouldn't it be nice if when you return to viewing the program, the focus would automatically return to it and you could use those Up / Down keys again without having to click the list view?

Here is a simple way to do it......

Add these variables to the program.

int NoFocus = 0
int hwndx,hwndy


Just before the WAITUNTIL command in your program add this:


hwndx = GetForegroundWindow()    '<------- this line
WAITUNTIL win = 0
end


In a timer section of the window's handler add this:


hwndy = GetForegroundWindow()

'The program is not the one in focus
if hwndx <> hwndy
   NoFocus = 1
endif

'The prgram is now back in focus
if NoFocus = 1 and hwndx = hwndy
   NoFocus = 0
   setfocus win,ListView
endif
 

So now when you minimise the program, do something else, and then restore your program back to view it, it now has the focus back on the list view and you can use those Up / Down arrow keys again without having to click the list view.

Just thought it might help someone - and of course, I'm sure there are other ways to do this.

Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.