If you are learning how to use Windows API (specially Win32 API) in Qt you might have come across a lot of functions which require the usage of Callback Functions. A very well-known example is EnumWindows function. This function allows listing all open windows through a callback function.
The part of the process in using functions like EnumWindows that is a little bit confusing for Qt programmers is that the callback function’s address needs to be the same for all classes. Think about it! This can only be implemented with an static method right?!
To describe this with an example, let’s go back to our main topic which is using EnumWindows function in Qt. This function requires a callback to be able to perform its task. To be able to provide EnumWindows function with a correct callback procedure you need to define it like this:
static BOOL CALLBACK StaticEnumWindowsProc(HWND hwnd, LPARAM lParam);
To understand the whole process I suggest taking a look at the example below. The screenshot displayed is the MainWindow of the example project.
You can download the complete source code of the example project (ready to build and run) using this button: