API Questions
#3
(08-18-2023, 07:51 PM)SpriggsySpriggs Wrote:
(08-18-2023, 07:35 PM)TerryRitchie Wrote: Since I've started diving into API calls I figured a dedicated thread for API related questions would be better.

Here is my first question.

In the Wiki here: https://qb64phoenix.com/qb64wiki/index.p...ndow_Focus

It's shown how to determine the foreground window (the one in focus).

The Microsoft docs for GetForegroundWindow are located here: https://learn.microsoft.com/en-us/window...oundwindow

I noticed in the Wiki example that GetForegroundWindow is declared as an _OFFSET (%&). How was this determined? Looking at the Microsoft docs there is no indication of the type of variable returned. With other window handle (hWnd) related functions I've noticed a variable type of LONG is used. Why was _OFFSET needed here instead of LONG?

This has me confused. Any clarification would be greatly appreciated.
HWND is 4 bytes in 32 bit and 8 bytes in 64. The reason you probably see it often declared as a LONG is because many people use 32 bit QB64. Using OFFSET makes it automatically the right size for either system. From Microsoft, the declaration for GetForegroundWindow is: HWND GetForegroundWindow();
The HWND is a handle to the window. Most handles in Win32 are going to be translated best to OFFSET in QB64.
Ah, ok, so basically it's acting like an _INTEGER64 in this sense. So the rule of thumb is if a handle is returned best practice is to use _OFFSET.

Thank you for the quick reply and explanation. Smile
Software and cathedrals are much the same — first we build them, then we pray.
QB64 Tutorial
Reply


Messages In This Thread
API Questions - by TerryRitchie - 08-18-2023, 07:35 PM
RE: API Questions - by SpriggsySpriggs - 08-18-2023, 07:51 PM
RE: API Questions - by TerryRitchie - 08-18-2023, 07:55 PM
RE: API Questions - by SMcNeill - 08-18-2023, 10:36 PM
RE: API Questions - by SMcNeill - 08-18-2023, 10:45 PM
RE: API Questions - by SpriggsySpriggs - 08-18-2023, 10:48 PM
RE: API Questions - by TerryRitchie - 08-19-2023, 02:06 AM
RE: API Questions - by SpriggsySpriggs - 08-19-2023, 04:32 AM
RE: API Questions - by TerryRitchie - 08-19-2023, 03:32 PM
RE: API Questions - by Dav - 08-19-2023, 03:48 PM
RE: API Questions - by TerryRitchie - 08-19-2023, 03:53 PM
RE: API Questions - by SpriggsySpriggs - 08-19-2023, 09:10 PM
RE: API Questions - by TerryRitchie - 08-19-2023, 09:45 PM
RE: API Questions - by Jack - 08-19-2023, 10:45 PM
RE: API Questions - by TerryRitchie - 08-19-2023, 11:06 PM
RE: API Questions - by a740g - 08-20-2023, 12:01 AM
RE: API Questions - by TerryRitchie - 08-20-2023, 05:47 PM
RE: API Questions - by SMcNeill - 08-20-2023, 06:04 PM
RE: API Questions - by a740g - 08-20-2023, 06:32 PM
RE: API Questions - by SMcNeill - 08-20-2023, 06:08 PM
RE: API Questions - by Jack - 08-20-2023, 06:15 PM
RE: API Questions - by a740g - 08-20-2023, 06:20 PM
RE: API Questions - by SMcNeill - 08-20-2023, 06:22 PM
RE: API Questions - by a740g - 08-20-2023, 06:23 PM
RE: API Questions - by SpriggsySpriggs - 08-20-2023, 11:10 PM



Users browsing this thread: 7 Guest(s)