home *** CD-ROM | disk | FTP | other *** search
- /*** Windows Application ***/
- /*** --- DIALOG BOX example ***/
- /*** ***/
- /*** WDLG-1 includes ***/
- /*** (1) WDLG-1.C ***/
- /*** (2) WDLG-1.DEF ***/
- /*** (3) WDLG-1.RES ***/
-
- #pragma hdrfile "windows.sym"
- #include <windows.h>
- #pragma hdrstop
-
- #define IDM_DEMO 101 // for menu item
-
- #define ID_OK 1001 // for control
- #define ID_CANCEL 1002 // for control
-
- // Declaration
-
- void InitFirstInstance(HANDLE) ;
- void InitEachInstance(HANDLE, int) ;
- long FAR PASCAL AppWndProc (HWND, WORD, WORD, LONG) ;
-
- BOOL FAR PASCAL DemoDlgProc(HWND, WORD, WORD, LONG) ;
-
- static char szAppName[12] = "WinDlg";
- static char szMenuName[12] = "WinDlgMenu";
-
- HWND hwnd ;
-
- // Definition
-
- int PASCAL WinMain(HANDLE hInstance,
- HANDLE hPrevInstance,
- LPSTR lpszCmdLine,
- int nCmdShow)
- { MSG msg ;
-
- if ( !hPrevInstance ) InitFirstInstance(hInstance) ;
-
- InitEachInstance(hInstance,nCmdShow) ;
-
- while ( GetMessage(&msg, NULL, 0, 0) )
- { TranslateMessage(&msg) ;
- DispatchMessage(&msg) ;
- }
- return msg.wParam ;
- }
-
- void InitFirstInstance(HANDLE hInstance)
- { WNDCLASS wndclass ;
-
- wndclass.style = CS_HREDRAW | CS_VREDRAW ;
- wndclass.lpfnWndProc = AppWndProc ;
- wndclass.cbClsExtra = 0 ;
- wndclass.cbWndExtra = 0 ;
- wndclass.hInstance = hInstance ;
- wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION) ;
- wndclass.hCursor = LoadCursor(NULL,IDC_ARROW) ;
- wndclass.hbrBackground = GetStockObject(WHITE_BRUSH) ;
- wndclass.lpszMenuName = szMenuName ;
- wndclass.lpszClassName = szAppName ;
-
- RegisterClass(&wndclass) ;
- }
-
-
- void InitEachInstance(HANDLE hInstance, int nCmdShow)
- {
- hwnd = CreateWindow(szAppName, // window class name
- "Windows Application", // window caption
- WS_OVERLAPPEDWINDOW ,
- CW_USEDEFAULT, // initial x position
- 0, // initial y position
- CW_USEDEFAULT, // initial x length
- 0, // initial y length
- NULL, // parent window handle
- NULL, // window menu handle
- hInstance, // program instance handle
- NULL) ; // parameters
-
- ShowWindow(hwnd,nCmdShow) ;
- UpdateWindow(hwnd) ;
- }
-
-
- long FAR PASCAL AppWndProc (HWND hwnd, WORD message,
- WORD wParam, LONG lParam)
- { static HANDLE hInstance ;
- static FARPROC lpfnDemoDlgProc ;
-
- switch (message)
- { case WM_CREATE :
- hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
- lpfnDemoDlgProc = MakeProcInstance(DemoDlgProc, hInstance) ;
- break ;
-
- case WM_COMMAND :
- switch(wParam)
- { case IDM_DEMO :
- DialogBox(hInstance, "DemoDlg",
- hwnd, lpfnDemoDlgProc) ;
- break ;
- }
- break ;
-
- case WM_DESTROY :
- FreeProcInstance(lpfnDemoDlgProc) ;
- PostQuitMessage(0) ;
- break ;
-
- default :
- return DefWindowProc(hwnd, message, wParam, lParam) ;
- }
-
- return 0L ;
- }
-
-
- BOOL FAR PASCAL DemoDlgProc(HWND hDlg, WORD message,
- WORD wParam, LONG lParam)
- {
- switch (message)
- { case WM_INITDIALOG :
- return TRUE ;
-
- case WM_COMMAND :
- switch (wParam)
- { case ID_OK :
- case ID_CANCEL :
- EndDialog(hDlg,0) ;
- return TRUE ;
- }
- break ;
- }
- return FALSE ;
- }
-