Free Portals Example
Click here to go to the Portals example

Download the example program

I haven't put together a tutorial for this program, if you know how to create a standard dialog box then you shouldn't have any trouble following the source code. One interesting point is that if you remove the WS_VISIBLE style from the dialog template then the dialog will run without showing on the taskbar or appear in the running tasks list.

Source code for

Dialog Main Window

Listing of resource.h

#define IDI_ICON 100 #define IDD_DIALOG 101 #define IDC_DLG_TEXT 102

Listing of resource.rc

#include <windows.h> #include "resource.h" IDI_ICON ICON "icon.ico" DIALOG_NAME DIALOG 0, 0, 179, 61 STYLE DS_SYSMODAL | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU CAPTION "Dialog Box as main window" LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL FONT 8, "MS Sans Serif" { CONTROL "Enter some text in the edit control to test.", -1, "STATIC", SS_CENTER | WS_CHILD | WS_VISIBLE, 8, 6, 129, 11
CONTROL "Default Text", IDC_DLG_TEXT, "EDIT", ES_LEFT | ES_AUTOHSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 10, 20, 158, 12 CONTROL "&Ok", IDOK, "BUTTON", BS_PUSHBUTTON | BS_CENTER | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 37, 39, 50, 14 CONTROL "&Cancel", IDCANCEL, "BUTTON", BS_PUSHBUTTON | BS_CENTER | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 92, 39, 50, 14 }

Listing of main.cpp

// Win32 Tutorial (Dialog Box as main window) // Alan Baylis 2004 #include <windows.h> #include "resource.h" #define BUFFER_SIZE 256 char szText[BUFFER_SIZE]; HBRUSH g_hbrBackground = CreateSolidBrush(RGB(255, 255, 255)); HINSTANCE hInst; BOOL CALLBACK InitProc( HWND hDlgWnd, UINT Message, WPARAM wParam, LPARAM lParam ) { switch(Message) { case WM_CTLCOLORDLG: return (LONG)g_hbrBackground; case WM_CTLCOLORSTATIC: { HDC hdcStatic = (HDC)wParam; SetTextColor(hdcStatic, RGB(0, 0, 0)); SetBkMode(hdcStatic, TRANSPARENT); return (LONG)g_hbrBackground; } break; case WM_INITDIALOG: { RECT DesktopRect; RECT DialogRect; GetWindowRect(GetDesktopWindow(), &DesktopRect); GetWindowRect(hDlgWnd, &DialogRect); SetWindowPos( hDlgWnd, HWND_TOP, (DesktopRect.right - DialogRect.right) / 2, (DesktopRect.bottom - DialogRect.bottom) / 2, 0,0, SWP_NOSIZE ); SendMessage(hDlgWnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON))); SendMessage(hDlgWnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON))); SendDlgItemMessage(hDlgWnd, IDC_DLG_TEXT, EM_SETLIMITTEXT, (WPARAM)BUFFER_SIZE - 1, (LPARAM)0); SetDlgItemText(hDlgWnd, IDC_DLG_TEXT, "Enter Text"); return TRUE; } break; case WM_COMMAND: switch(LOWORD(wParam)) { case IDCANCEL: ExitProcess(0); return TRUE; break; case IDOK: MessageBox(hDlgWnd, "Ok", "Success", MB_OK); GetDlgItemText(hDlgWnd, IDC_DLG_TEXT, szText, BUFFER_SIZE); ExitProcess(0); return TRUE; break; } break; } return FALSE; } INT WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow ) { hInst = hInstance; HWND hWnd = CreateDialog( hInstance, (LPCTSTR)"DIALOG_NAME", NULL, (DLGPROC)InitProc ); MSG Msg; while(GetMessage(&Msg, NULL,0,0) == TRUE) { if(!IsDialogMessage(hWnd,&Msg)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } } return Msg.wParam; }


Copyright © 1998 - 2010 Alan Baylis, All Rights Reserved