4 ms·
> Win32 does not revolve around an update loop you own while (GetMessage(&msg, NULL, 0, 0) > 0) { TranslateMessage(&msg); DispatchMessage(&
by ahartmetz 7mo ago
> Win32 does not revolve around an update loop you own
while (GetMessage(&msg, NULL, 0, 0) > 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
...How much more could you own it, really? Is that the LLM talking?
- pharrington 7mo agoHe means its about a message loop, as opposed to an update loop.
- ahartmetz 7mo agoThe main loop of any GUI application is an event loop. You can't do that without using a platform API, and the platform API happens to be GetMessage() / TranslateMessage() / DispatchMessage(). There is nothing Win32 specific that somehow gives you less ownership of the main loop than you would have otherwise. If anything, it gives you more customization than most other platforms / frameworks by having three separate functions between which you can manipulate events. At best, what the article is trying to say is "This is a GUI application, so we need to handle user input and paint request events etc in the main loop. Here is how to set up such a main loop in Win32:" Win32 messages are higher-level than what you get out of select() and such, but that only serves to make it easier to customize things at the appropriate level of abstraction and with sufficient high-level information.
- sumtechguy 7mo agoHad one project where for some reason one of the devs wanted to access the messages before it got translated. The reasons are lost to time. You technically could create other types of application that is not CLI or 'windows'. But then you are own your own making the queues or console items. Think they were typically used for device drivers or background service manager tasks. https://learn.microsoft.com/en-us/cpp/build/reference/subsystem-specify-subsystem?view=msvc-170 https://learn.microsoft.com/en-us/cpp/build/reference/subsys... Pretty sure it just changes out what the default function that is called before winmain. So you probably could just switch out the first function called (dont remember the cli option for that). Most of the time you just picked the right type at project creation so it would feed correctly into the project solution which would set the right flags on build. But technically you could pick the most basic one and do it all yourself.
- jasomill 7mo agoPresumably you're talking about /SUBSYSTEM:NATIVE, and while you're correct that it changes the default entry point (to NtProcessStartup in this case), it also sets the Subsystem field in the PE optional header to IMAGE_SUBSYSTEM_NATIVE, which causes CreateProcess to fail to start the executable with ERROR_CHILD_NOT_COMPLETE ("The %1 application cannot be run in Win32 mode."). To see this, try press Windows+R and try running C:\Windows\System32\autochk.exe. There are workarounds, but AFAIK there's no officially supported way to launch a native executable. But that doesn't matter unless you want to avoid creating Win32 process structures, loading default Win32 DLLs, etc., as no windows are created and no messages are dispatched by code other than your own unless peculiar startup code is injected into your process at load time. In particular, you have access to untranslated messages by default, and if you don't want translated messages to be posted, just don't call TranslateMessage in your message loop.
- direwolf20 7mo agoMicrosoft Windows technologies like COM do create windows and run message loops on your behalf. When you drag on a title bar it runs a modal message loop in kernel mode. Took me a while to figure that one out...
- Dwedit 7mo ago"GetMessage" can do a lot of things you don't expect it to do. Ever used a global keyboard hook? Your keyboard handler code is called because "GetMessage" is calling other functions to have it get handled.