a function of windows API

what does the following code do?
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
What is the difference of this code with
1
2
3
4
5
6
7
8
9
switch (wmId)
		{
		case IDM_ABOUT:
			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
			break;
		case IDM_EXIT:
			DestroyWindow(hWnd);
			break;
...
?
I didnt really look at the first one but the second one is using the switch statement to tell the program what to do if the case is either IDM_ABOUT or IDM_EXIT.
Last edited on
The first one is a Callback function, these are functions that are usually passed by reference to other functions so that they can be called from inside someplace unreachable such as the kernel or a DLL. Another use for them is to associate them with particular instances of objects such as the WindowProc variable of the WNDCLASS and WNDCLASSEX structures in the WinAPI. In this example you're passing a pointer to your callback function to tell the Operating System where you want messages meant for that window to go.

As megasnorlax said about the second entry it is a basic switch case statement. Something to understand is that the WinAPI likes to use the #define macro to assign slightly more meaningful names to otherwise confusing numbers and strings. In this particular example IDM_ABOUT and IDM_EXIT each evaluate to a different constant that matches a possible command sent to this switch(). It's likely that wmId is the LOWORD of the wParam argument passed to this WindowProc instance. IDD_ABOUTBOX would be a label in an accompanying resource file that describes a template (not to be confused with a C++ template) for a window class. This "template" label is passed as an argument to the "DialogBox()" function which then uses that label to find and pull the data describing the window from the place in memory that the resource file was compiled to.
Last edited on
so, DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); gives the command to INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) when user click the about bar, right?
It would be more accurate to say that DialogBox function calls the About function. But you're close.
Topic archived. No new replies allowed.