Skip to content

Win32 Version Dialog

A Win32 dialog that displays the current Windows version string, with a ShellAbout entry in the system menu.

Published Jul 21, 2000

The smallest possible "what OS am I on?" viewer. The dialog's WM_INITDIALOG handler asks a helper (Get_OsVersion, the same routine exported by the DLL Skeleton) for a human-readable version string and drops it into a static control; Okay closes the dialog, and an About entry appended to the system menu calls ShellAbout for the standard credits box. A handy template when you want your app to show its environment - pairing well with the Detect WinVersion article, which covers the raw GetVersionEx mechanics behind strings like this.

/////////////////////////////////////////////////////////////////////

extern int WINAPI WinMain (HWND hInstance, HWND hPrev, LPSTR Cmd, int nCmdShow)
{
	MainInstance = hInstance;
	DialogBox(MainInstance,MAKEINTRESOURCE(100),0,MainDilaog);
	return 0;
}
/////////////////////////////////////////////////////////////////////

extern int MainDilaog (HWND hDlg, int Msg, int wParam, int lParam)
{
	static HWND WindowsVersion_hWnd;
	static HWND SystemMenu;

	while(1) // Loop Forever
	{
		if(Msg==WM_INITDIALOG)
		{
			MainDialog_hWnd=hDlg;

			SendMessage(MainDialog_hWnd,(UINT)WM_SETTEXT,(WPARAM)0,(LPARAM)TitleCaption);

			WindowsVersion_hWnd = GetDlgItem(MainDialog_hWnd,1000);

			SystemMenu = GetSystemMenu(MainDialog_hWnd,FALSE);
			AppendMenu(SystemMenu,MF_SEPARATOR,0,0);
			AppendMenu(SystemMenu,MF_STRING,1001,"About");

			SetText(WindowsVersion_hWnd,Get_OsVersion());

			CenterWindow(MainDialog_hWnd);
			break;
		}

		if(Msg==WM_COMMAND)
		{
			if(wParam==100) // Okay (Dialog Command)
			{
				EndDialog(MainDialog_hWnd,0);
			}

			break;
		}

	   if(Msg == WM_SYSCOMMAND)
		{
			if(LOWORD(wParam) == 1001)
			{
				ShellAbout(MainDialog_hWnd,"",TitleCaption,NULL);
			}
		}

		if(Msg==WM_CLOSE) //Exit (Windows Message)
		{
			EndDialog(MainDialog_hWnd,0);
		}

		break;
	}
	return 0;
}

ShellAbout pulls its text from the application's version resource when you pass NULL for the message - set up a VS_VERSION_INFO block in your .rc and the standard About box fills itself in for free.

An unhandled error has occurred. Reload 🗙