Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

windlg.c

Go to the documentation of this file.
00001 /***************************************************************
00002 * File: WinDlg.c                                              *
00003 ***************************************************************/
00004 
00005 /* Include Files */
00006 #include <windows.h>
00007 #include "dlgproc.h"
00008 #include "nmlperf.rh"
00009 #include "windlg.h"
00010 
00011 HINSTANCE hWinDlgInstance;
00012 int nWinDlgCmdShow;
00013 DLGPROC dlg_proc_instance = NULL;
00014 HRSRC dlg_resource_handle = NULL;
00015 LPCSTR dlg_resource_str;
00016 HGLOBAL dlg_resource = NULL;
00017 HWND hDlg = NULL;
00018 MSG main_loop_message;
00019 HWND title_window;
00020 void FAR *dlg_resource_ptr = NULL;
00021 
00022 
00023 void
00024 WinDlgExit ()
00025 {
00026   if (NULL != title_window)
00027     {
00028       DestroyWindow (title_window);
00029     }
00030 }
00031 
00032 int PASCAL
00033 main_window_proc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
00034 {
00035   switch (message)
00036     {
00037     case WM_DESTROY:
00038       PostQuitMessage (0);
00039       break;
00040     default:
00041       return DefWindowProc (hwnd, message, wParam, lParam);
00042     }
00043 }
00044 
00045 int PASCAL
00046 WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
00047          LPSTR lpstrCmdLine, int nCmdShow)
00048 {
00049   WNDCLASS wndclass;
00050   hWinDlgInstance = hInstance;
00051   nWinDlgCmdShow = nCmdShow;
00052 
00053   if (NULL == hPrevInstance)
00054     {
00055       wndclass.style = CS_HREDRAW | CS_VREDRAW;
00056       wndclass.lpfnWndProc = main_window_proc;
00057       wndclass.cbClsExtra = 0;
00058       // Reserve extra bytes for each instance of the window;
00059       // we will use these bytes to store a pointer to the C++
00060       // (MainWindow) object corresponding to the window.
00061       // the size of a 'this' pointer depends on the memory model.
00062       wndclass.cbWndExtra = 0;
00063       wndclass.hInstance = hInstance;
00064       wndclass.hIcon = NULL;
00065       wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
00066       wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
00067       wndclass.lpszMenuName = NULL;
00068       wndclass.lpszClassName = "TITLE_WINDOW";
00069 
00070       if (!RegisterClass (&wndclass))
00071         {
00072           MessageBox (NULL, "Can't Registor TITLE_WINDOW Class.", "ERROR",
00073                       MB_OK);
00074           return (0);
00075         }
00076     }
00077   title_window =
00078     CreateWindow ("TITLE_WINDOW", "The Title", WS_CAPTION | WS_SYSMENU, 0,      /* X */
00079                   0,            /* Y */
00080                   0,            /* width */
00081                   0,            /* hieght */
00082                   NULL,         /* Parent */
00083                   NULL,         /* hMenu */
00084                   hInstance, 0);
00085   if (title_window == NULL)
00086     {
00087       MessageBox (NULL, "Can't Create TITLE_WINDOW.", "ERROR", MB_OK);
00088       return 0;
00089     }
00090   ShowWindow (title_window, nCmdShow);
00091   dlg_proc_instance = MakeProcInstance (main_window_dialog_proc, hInstance);
00092   if (NULL == dlg_proc_instance)
00093     {
00094       MessageBox (NULL, "Can't MakeProcInstance for dialog_proc.", "ERROR",
00095                   MB_OK);
00096       return NULL;
00097     }
00098   dlg_resource_str = MAKEINTRESOURCE (MAIN_WINDOW_DIALOG);
00099   if (dlg_resource_str == NULL)
00100     {
00101       MessageBox (NULL, "Can't MAKEINTRESOURCE for MAIN_WINDOW_DIALOG",
00102                   "ERROR", MB_OK);
00103       return 0;
00104     }
00105 #if 0
00106   dlg_resource_handle = FindResource (hInstance, dlg_resource_str, RT_DIALOG);
00107   if (NULL == dlg_resource_handle)
00108     {
00109       MessageBox (NULL, "Can't FindResource MAIN_WINDOW_DIALOG", "ERROR",
00110                   MB_OK);
00111       FreeProcInstance (dlg_proc_instance);
00112       dlg_proc_instance = NULL;
00113       return NULL;
00114     }
00115   dlg_resource = LoadResource (hInstance, dlg_resource_handle);
00116   if (NULL == dlg_resource)
00117     {
00118       MessageBox (NULL, "Can't LoadResource MAIN_WINDOW_DIALOG", "ERROR",
00119                   MB_OK);
00120       FreeProcInstance (dlg_proc_instance);
00121       dlg_proc_instance = NULL;
00122       return NULL;
00123     }
00124   dlg_resource_ptr = LockResource (dlg_resource);
00125   if (dlg_resource_ptr == NULL)
00126     {
00127       MessageBox (NULL, "Can't LockResource MAIN_WINDOW_DIALOG", "ERROR",
00128                   MB_OK);
00129       return 0;
00130     }
00131 #endif
00132   hDlg = CreateDialog (hInstance,
00133                        dlg_resource_str, title_window, dlg_proc_instance);
00134   if (NULL == hDlg)
00135     {
00136       MessageBox (NULL, "Can't CreateDialog.", "ERROR", MB_OK);
00137       FreeProcInstance (dlg_proc_instance);
00138       dlg_proc_instance = NULL;
00139       FreeResource (dlg_resource);
00140       dlg_resource = NULL;
00141       return NULL;
00142     }
00143   while (GetMessage (&main_loop_message, NULL, 0, 0))
00144     {
00145       if (IsDialogMessage (hDlg, &main_loop_message))
00146         {
00147           continue;
00148         }
00149       TranslateMessage (&main_loop_message);
00150       DispatchMessage (&main_loop_message);
00151     }
00152   return main_loop_message.wParam;
00153 }

Generated on Sun Dec 2 15:56:53 2001 for rcslib by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001