int __stdcall WinMain(HINSTANCE, HINSTANCE, LPSTR, INT) { // endauvor to register window classes if(!registerWindowClasses()) { MessageBox(GetActiveWindow(), "Could not register window classes", "Error", MB_OK | MB_ICONERROR); return(0); // fatal error } // create our main window HWND mainWindow; if(!initWindow(mainWindow)) { MessageBox(GetActiveWindow(), "Could not create main window", "Error", MB_OK | MB_ICONERROR); return(0); // fatal error } // message loop MSG msg; while(GetMessage(&msg, 0, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return(msg.wParam); }
BOOL initInstance( HINSTANCE hinst, UINT resPoolID, int nCmdShow, LPSTR lpCmdLine) { HWND hwnd; TCHAR ClassName [MAX_RESOURCESTRING + 1] ; int n; COPYDATASTRUCT theCDS; char *fileName; size_t length; hMainAccel = LoadAccelerators(hinst, "ClipsAcc"); n = LoadString (hinst, resPoolID, ClassName, DIM(ClassName)) ; VERIFY(n != 0); /*========================================*/ /* Determine if there is a prior instance */ /* of the main frame window. */ /*========================================*/ hwnd = FindWindow(ClassName,NULL); /*===================================================*/ /* Register all application-specific window classes. */ /*===================================================*/ if (! registerWindowClasses (hinst, resPoolID)) { return FALSE; } /*=====================================*/ /* Initialize the Common Controls DLL. */ /*=====================================*/ InitCommonControls(); /*=============================================*/ /* Create the application's main frame window. */ /*=============================================*/ hMainFrame = createMainFrameWindow (hinst, nCmdShow); if (hMainFrame == NULL) { return FALSE; } /*======================================================*/ /* Constrain this application to run a single instance. */ /*======================================================*/ if (hwnd != NULL) { /*=====================================================*/ /* A previous instance of this application is running. */ /* Activate the previous instance, tell it what the */ /* user requested this instance to do, then abort */ /* initialization of this instance. */ /*=====================================================*/ if (IsIconic (hwnd)) { ShowWindow(hwnd,SW_RESTORE); } SetForegroundWindow(hwnd); /*=====================================================*/ /* Send an application-defined message to the previous */ /* instance (or use some other type of IPC mechanism) */ /* to tell the previous instance what to do. */ /* Determining what to do generally depends on how the */ /* user started this instance. */ /*=====================================================*/ length = strlen(lpCmdLine); fileName = (char *) malloc(length - 1); if (fileName == NULL) return FALSE; strncpy(fileName,&lpCmdLine[1],length-2); fileName[length-2] = 0; theCDS.dwData = CD_FILENAME; theCDS.cbData = (DWORD) (length - 1); theCDS.lpData = fileName; SendMessage(hwnd,WM_COPYDATA, (WPARAM)(HWND) hMainFrame, (LPARAM) (LPVOID) &theCDS); free(fileName); /*=======================================*/ /* Abort this instance's initialization. */ /*=======================================*/ return FALSE; } /*==================================*/ /* Go ahead and show the main frame */ /* at this point in initialization. */ /*==================================*/ ShowWindow(hMainFrame,nCmdShow); UpdateWindow(hMainFrame); /*================================*/ /* Initialize text child windows. */ /*================================*/ if (! text_InitInstance(hinst)) { return FALSE; } /*===================================*/ /* Initialize display child windows. */ /*===================================*/ if (! display_InitInstance(hinst)) { return FALSE; } /*====================================*/ /* Initialize display child windoows. */ /*====================================*/ if (! status_InitInstance(hinst)) { return FALSE; } /*===================*/ /* Set up the menus. */ /*===================*/ hMainAccel = LoadAccelerators(hinst,"ClipsAcc"); haccel = hMainAccel; if (FORWARD_WM_MDISETMENU(MDIClientWnd,TRUE,hMainMenu, NULL,SendMessage) != 0) { SendMessage(hMainFrame, UWM_SET_ACCELERATOR, 0, (LPARAM) hMainAccel); DrawMenuBar(hMainFrame); PostMessage(hMainFrame, UWM_UPDATE_TOOLBAR, 0, 0); } /*======================================*/ /* Initialize find/replace information. */ /*======================================*/ InitFindReplace(hwnd); hHourGlass = LoadCursor(NULL,IDC_WAIT); /* Initialize cursors. */ WAIT[0] = LoadCursor((HINSTANCE) hinst, "CURSOR0" ); WAIT[1] = LoadCursor((HINSTANCE) hinst, "CURSOR1" ); WAIT[2] = LoadCursor((HINSTANCE) hinst, "CURSOR2" ); WAIT[3] = LoadCursor((HINSTANCE) hinst, "CURSOR3" ); WAIT[4] = LoadCursor((HINSTANCE) hinst, "CURSOR4" ); WAIT[5] = LoadCursor((HINSTANCE) hinst, "CURSOR5" ); WAIT[6] = LoadCursor((HINSTANCE) hinst, "CURSOR6" ); WAIT[7] = LoadCursor((HINSTANCE) hinst, "CURSOR7" ); WAIT[8] = LoadCursor((HINSTANCE) hinst, "CURSOR8" ); WAIT[9] = LoadCursor((HINSTANCE) hinst, IDC_WAIT ); QUERY = LoadCursor((HINSTANCE) hinst,"CLIPS_QUERY"); ARROW = LoadCursor(NULL,IDC_ARROW); SetCursor(ARROW); /*====================================================*/ /* Fill in non-variant fields of OPENFILENAME struct. */ /*====================================================*/ ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hMainFrame; ofn.lpstrFilter = "CLIPS Files (*.CLP)\0*.CLP\0Batch Files (*.BAT)\0*.BAT\0Text Files (*.TXT)\0*.TXT\0All Files (*.*)\0*.*\0"; ofn.lpstrCustomFilter = NULL; ofn.nMaxCustFilter = 0; ofn.nFilterIndex = 1; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAXFILENAME; ofn.lpstrInitialDir = NULL; ofn.lpstrFileTitle = szFileTitle; ofn.nMaxFileTitle = MAXFILENAME; ofn.lpstrTitle = NULL; ofn.lpstrDefExt = "CLP"; ofn.Flags = OFN_HIDEREADONLY; /*==============================*/ /* Initialize the print dialog. */ /*==============================*/ InitializePrintDialog(hMainFrame); /*============================*/ /* Create the display window. */ /*============================*/ #if DEFTEMPLATE_CONSTRUCT factsWindow_New(hMainFrame); #endif #if DEFRULE_CONSTRUCT agendaWindow_New(hMainFrame); #endif #if OBJECT_SYSTEM instancesWindow_New(hMainFrame); #endif #if DEFGLOBAL_CONSTRUCT globalsWindow_New(hMainFrame); #endif #if DEFRULE_CONSTRUCT focusWindow_New(hMainFrame); #endif displayWindow_New(hMainFrame); SendMessage(DialogWindow,WM_MDIACTIVATE,0,(LPARAM) DialogWindow); return TRUE; }