Focus Handle of Multiwin Output Window

Discussions about the BBC BASIC language, with particular reference to BB4W and BBCSDL
MattC
Posts: 57
Joined: Mon 16 Apr 2018, 06:17

Focus Handle of Multiwin Output Window

Post by MattC »

Hi (again).

The program I'm writing uses multiple output windows using the MULTIWIN library. The function FN_createwin returns the handle of the created window. I am using a mouse to access items on the output screen but I need to know that the output window is selected. All the 'window focus' routines only return the main output window, returning @hwnd% . As much as this is, to some extent, useful, it would be good to have the current child window's handle, to guarantee the focus. Is there a routine available.

I tried using either:

Code: Select all

      SYS "GetForegroundWindow" TO hwnd%
and

Code: Select all

      DEF FN_getfocus(hwnd%)
      LOCAL H%, O%, W%
      SYS "GetWindowThreadProcessId", hwnd%, 0 TO W%
      SYS "GetCurrentThreadId" TO O%
      SYS "AttachThreadInput", O%, W%, TRUE
      SYS "GetFocus" TO H%
      SYS "AttachThreadInput", O%, W%, FALSE
      = H%
Neither of which gives me the current child output window's handle.

(Not sure where I got the second one from, but I've been using it on and off for ages.)

Thanks

Matt

KenDown
Posts: 141
Joined: Wed 04 Apr 2018, 06:36

Re: Focus Handle of Multiwin Output Window

Post by KenDown »

Hmmm. I have multiple windows and although I don't need to ensure that one of them has the focus, I do need to know which one is being accessed by the program, which I guess comes down to the same thing.

SYS"GetForegroundWindow"TOhw%
IFhw%=hw1%ORhw%=hw2%ORhw%=hw3%ORhw%=hw5%ORhw%=hw6%ELSEENDPROC

hw1% hw2% etc are the handles of the windows that are created with FN_createwin. I can only suggest that perhaps it is the hwnd%, which is perhaps too similar to @hwnd%? You haven't used it more than once, have you?

MattC
Posts: 57
Joined: Mon 16 Apr 2018, 06:17

Re: Focus Handle of Multiwin Output Window

Post by MattC »

I tried so many variations of different things that I may have just overlooked 'GetForegroundWindow'. Thanks.

I would be surprised if BB4W got confused with hwnd% and @hwnd%. Particularly as @... is a system variable. But I will investigate what you have brought up.

Thanks.

Matt

RichardRussell
Posts: 309
Joined: Tue 15 Oct 2019, 09:10

Re: Focus Handle of Multiwin Output Window

Post by RichardRussell »

MattC wrote:
Sun 19 May 2019, 18:58
As much as this is, to some extent, useful, it would be good to have the current child window's handle, to guarantee the focus. Is there a routine available?
Possibly I'm missing the point entirely, but surely the current (child) window's handle is, by definition, @hwnd%? If you need to test whether the currently-selected window is the main output window, I would have expected that it would be as simple as comparing the current value of @hwnd% with the value it had when the program started. Something like:

Code: Select all

      REM At the start of the program:
      HwndOrig% = @hwnd%
      ...
      REM When you want to perform the test:
      IF @hwnd% = HwndOrig% THEN ....
If I've got the wrong end of the stick, sorry.
If you have a comment about the style or tone of this message please report it to the moderators by clicking the exclamation mark icon, rather than complaining on the public forum.

MattC
Posts: 57
Joined: Mon 16 Apr 2018, 06:17

Re: Focus Handle of Multiwin Output Window

Post by MattC »

Thank you, Richard, for responding to this. It's been many months since I worked on this one, and I seem to remember tackling the problem from a different direction. If I get chance I'll have a look again.

Thanks again,

Matt

RichardRussell
Posts: 309
Joined: Tue 15 Oct 2019, 09:10

Re: Focus Handle of Multiwin Output Window

Post by RichardRussell »

MattC wrote:
Thu 02 Apr 2020, 19:12
Thank you, Richard, for responding to this. It's been many months since I worked on this one
I know it's a late reply, but I have only recently rejoined the forum, and I am shortly going to leave again, so I'm trying to work through as many outstanding issues as possible before then. It's all rather unfortunate really, because the very fact that I am bombarding the forum with messages (for what I think is a justifiable reason) is really winding up those who complain about me - it's one of my 'habits' that they don't like - making my early departure even more certain. :(

I'm surprised you didn't receive the same suggestion when you first asked the question. BB4W and BBCSDL users should be familiar with @hwnd% being the handle of the 'current' window, and with it changing as you switch windows when using the Multiwin library. It doesn't take much thought to realise that @hwnd% must change like that, for example suppose you want to set the window title with:

Code: Select all

      SYS "SetWindowText", @hwnd%, "New title"
or
      SYS "SDL_SetWindowTitle", @hwnd%, "New title", @memhdc%
If @hwnd% wasn't the handle of the 'current' window the wrong title would be changed!
If you have a comment about the style or tone of this message please report it to the moderators by clicking the exclamation mark icon, rather than complaining on the public forum.

MattC
Posts: 57
Joined: Mon 16 Apr 2018, 06:17

Re: Focus Handle of Multiwin Output Window

Post by MattC »

Thanks Richard,

I will definitely look at this when I get round to it. The issue will undoubtedly come up in another program.

As to your first comment, and I know this isn't the right thread, but I for one will be very sorry to see you go. If that is your decision, then I wish you all the very best.

Matt