static void Setup (OPENFILENAME *fnStruct) { TOLEApp *pApp = (TOLEApp *) GetApplicationObject(); // // we want the fully qualified pathname that is returned in "lpstrFile" // and not the simple name/extension // static char simpleName[13]; fnStruct->lStructSize = sizeof (OPENFILENAME); fnStruct->nMaxFile = MAXPATHLENGTH; fnStruct->Flags = 0; fnStruct->hInstance = pApp->hInstance; fnStruct->hwndOwner = pApp->MainWindow->HWindow; fnStruct->lCustData = 0; fnStruct->lpfnHook = 0; fnStruct->lpstrCustomFilter = 0; fnStruct->lpstrDefExt = szFileExt; fnStruct->lpstrFilter = "OWL OLE Server (*." szFileExt ")\0*." szFileExt "\0" ; fnStruct->lpstrFileTitle = simpleName; fnStruct->lpstrInitialDir = 0; fnStruct->lpstrTitle = 0; // use default fnStruct->lpTemplateName = 0; fnStruct->nFilterIndex = 1; fnStruct->nFileOffset = 0; fnStruct->nFileExtension = 0; fnStruct->nMaxCustFilter = 0; }
HICON CreateIconFromTemplate ( char far * def, int size ) { /*** PASSAGE EN COMMENTAIRE : CREATION DE L'ICONE A PARTIR DE LA CHAINE EN MEMOIRE (DEF). char far * entry = def + sizeof ( ICONHEADER ) ; int Width, Height, ColorCount, Planes ; long int Offset, Size ; char far * XORBits, * ANDBits ; // Récupération des paramètres Width = ( ( ICONENTRY * ) entry ) -> Width ; Height = ( ( ICONENTRY * ) entry ) -> Height ; ColorCount = ( ( ICONENTRY * ) entry ) -> ColorCount ; Size = ( ( ICONENTRY * ) entry ) -> Size ; Offset = ( ( ICONENTRY * ) entry ) -> Offset ; switch ( ColorCount ) { case 2 : Planes = 1 ; break ; case 4 : Planes = 2 ; break ; case 8 : Planes = 3 ; break ; case 16 : Planes = 4 ; break ; } // Adresse des bits XOR Size = ( Width * Height ) / ( 8 / Planes ) ; XORBits = def + ( int ) Offset + 0x7E ; ANDBits = def + ( int ) Offset + 0x7E + ( int ) Size ; // On crée l'icône return ( CreateIcon ( * GetApplicationObject ( ), Width, Height, 1, Planes, ANDBits, XORBits ) ) ; FIN DU PASSAGE COMMENTE ***/ char tempname [ MAX_PARAMETER_LENGTH ] ; register FILE * fp ; register HICON HIcon ; tmpnam ( tempname ) ; fp = fopen ( tempname, "w" ) ; fwrite ( def, 1, size, fp ) ; fclose ( fp ) ; HIcon = ExtractIcon ( * GetApplicationObject ( ), tempname, 0 ) ; unlink ( tempname ) ; return ( HIcon ) ; }
/* Reset ----- the only reason that we need this routine is that we re-use the document object. if your app doesn't then you would delete the old object and create a new one... SIDE EFFECTS: sets "fDirty" flag to FALSE and "fRelease" to FALSE if "lhDoc" is NULL then call OleRegisterServerDoc() */ void TOLEDocument::Reset (LPSTR szPath) { if (!szPath || !LoadFromFile (szPath)) { ((TWindowServer *) GetApplicationObject()->MainWindow)->ShapeChange (objEllipse); pObject->native.type = objEllipse; pObject->native.version = 1; type = doctypeNew; SetDocumentName (UNNAMED_DOC); } if (lhDoc == 0) { TOLEApp *pApp = (TOLEApp *) GetApplicationObject(); OleRegisterServerDoc (pApp->pServer->lhServer, szName, this, (LHSERVERDOC FAR *) &lhDoc); } fDirty = fRelease = FALSE; }
/* callback SetHostNames -------- ------------ the server library is calling to provide the server with the name of the client's document and the name of the object in the client application these names should be used to make the necessary window title bar and menu changes this method is only called for embedded objects because linked objects display their filename in the title bar WHAT IT DOES: - change the title bar and File menu - store the object and client names for later use - return OLE_OK is successful, OLE_ERROR_GENERIC otherwise PARAMETERS: - "lpClient" is the name of the client application document - "lpDoc" is the name of the object in the client application */ OLESTATUS FAR PASCAL _export TOLEDocument::SetHostNames (LPOLESERVERDOC lpOleDoc, LPSTR lpClient, LPSTR lpDoc) { ((TWindowServer *) GetApplicationObject()->MainWindow)->UpdateFileMenu (lpDoc); // // store the document name, but don't update the title bar we will do that // below // ((TOLEDocument *) lpOleDoc)->SetDocumentName (lpDoc, FALSE); // // set the caption to be <App Name> - <Object Name> in <Client App Document> // char buf[128]; wsprintf (buf, "%s - %s in %s", (LPSTR) szAppName, lpDoc, lpClient); GetApplicationObject()->MainWindow->SetCaption (buf); return OLE_OK; }
/* LoadFromFile ------------ returns TRUE if successful and FALSE otherwise SIDE EFFECTS: if successful sets type to "objtypeFromFile" and sets "szName" to "szPath" */ BOOL TOLEDocument::LoadFromFile (LPSTR szPath) { char buf[MAXPATHLENGTH]; TOLEApp *pApp = (TOLEApp *) GetApplicationObject(); // // in small model if I want to use C++ streams I need to have a near // pointer... // lstrcpy (buf, szPath); ifstream in (buf); if (in.fail()) { wsprintf (buf, "Cannot open file %s!", szPath); MessageBeep (0); MessageBox (pApp->MainWindow->HWindow, buf, szAppName, MB_OK | MB_ICONEXCLAMATION); return FALSE; } else { // // read in the signature // in.read (buf, sizeof (szClassKey) - 1); if (strncmp (buf, szClassKey, sizeof (szClassKey) - 1) != 0) { wsprintf (buf, "File %s is not an \"%s\" file!", szPath, (LPSTR) szAppName); MessageBeep (0); MessageBox (pApp->MainWindow->HWindow, buf, szAppName, MB_OK | MB_ICONEXCLAMATION); return FALSE; } else { in >> *pObject; type = doctypeFromFile; SetDocumentName (szPath); } return TRUE; } }
void TMustEnterValidator::Error(TWindow *owner) { string msgTmpl; TApplication* app = GetApplicationObject(); msgTmpl = app->LoadString(IDS_VALMUSTENTER).c_str(); char* msg = new char[msgTmpl.length() + 10 + 10 + 1]; sprintf(msg, msgTmpl.c_str()); if (owner) owner->MessageBox(msg, app->GetName(), MB_ICONEXCLAMATION|MB_OK); else ::MessageBox(0, msg, app->GetName(), MB_ICONEXCLAMATION|MB_OK|MB_TASKMODAL); delete [] msg; }
/* SetDocumentName --------------- changes instance variable "szName" and changes the window caption */ void TOLEDocument::SetDocumentName (LPSTR newName, BOOL changeCaption) { int len = lstrlen (newName); delete szName; szName = new char[len + 1]; lstrcpy (szName, newName); if (changeCaption) { char buf[MAXPATHLENGTH]; wsprintf (buf, "%s - %s", (LPSTR) szAppName, newName); GetApplicationObject()->MainWindow->SetCaption (buf); } }
static BOOL ProcessAppMsg(LPMSG PMessage) { PTApplication Application = GetApplicationObject(); if ( Application->KBHandlerWnd ) if ( Application->KBHandlerWnd->IsFlagSet(WB_MDICHILD) ) return ProcessMDIAccels(PMessage, Application) || ProcessDlgMsg(PMessage, Application) || ProcessAccels(PMessage, Application); else return ProcessDlgMsg(PMessage, Application) || ProcessMDIAccels(PMessage, Application) || ProcessAccels(PMessage, Application); else return ProcessMDIAccels(PMessage, Application) || ProcessAccels(PMessage, Application); }
void TPrinter::ReportError(PTPrintout Printout) { char ErrorMsg[80]; char ErrorCaption[80]; char ErrorTemplate[40]; char ErrorStr[40]; WORD ErrorId; Pchar Title; switch (Error) { case SP_APPABORT: ErrorId = SR_PRNCANCEL; break; case SP_ERROR: ErrorId = SR_GENERROR; break; case SP_OUTOFDISK: ErrorId = SR_OUTOFDISK; break; case SP_OUTOFMEMORY: ErrorId = SR_OUTOFMEMORY; break; case SP_USERABORT: ErrorId = SR_PRNMGRABORT; break; default: return; } HINSTANCE hInstance = GetApplicationObject()->hInstance; LoadString(hInstance, SR_ERRORTEMPLATE, ErrorTemplate, sizeof(ErrorTemplate)); LoadString(hInstance, ErrorId, ErrorStr, sizeof(ErrorStr)); Title = Printout->Title; LPSTR C[1]; C[0] = Title; wvsprintf(ErrorMsg, ErrorTemplate, (LPSTR) C); LoadString(hInstance, SR_ERRORCAPTION, ErrorCaption, sizeof(ErrorCaption)); MessageBox(0, ErrorMsg, ErrorCaption, MB_OK | MB_ICONSTOP); }
void TScientificLowerValidator::Error(TWindow *owner) { string msgTmpl; TApplication* app = GetApplicationObject(); switch(validator_type) { case INCLUSIVE: msgTmpl = app->LoadString(IDS_VALBELOWINCLLIMIT).c_str(); break; case EXCLUSIVE: msgTmpl = app->LoadString(IDS_VALBELOWEXCLLIMIT).c_str(); break; } char* msg = new char[msgTmpl.length() + 10 + 10 + 1]; sprintf(msg, msgTmpl.c_str(), min); if (owner) owner->MessageBox(msg, app->GetName(), MB_ICONEXCLAMATION|MB_OK); else ::MessageBox(0, msg, app->GetName(), MB_ICONEXCLAMATION|MB_OK|MB_TASKMODAL); delete [] msg; }
void TPrinter::Setup(PTWindowsObject Parent) { GetApplicationObject()->ExecDialog( new TPrinterSetupDlg(Parent, "PrinterSetup", this)); }
BOOL TPrinter::Print(PTWindowsObject ParentWin, PTPrintout Printout) { typedef BOOL (FAR PASCAL *PTAbortProc)( HDC Prn, short Code ); BOOL Banding; PTAbortProc AbortProcInst; WORD PageNumber; BOOL result = FALSE; // Assume error occurred Error = 0; if ( Printout == NULL ) return result; if ( ParentWin == NULL ) return result; if ( Status != PS_OK ) { Error = SP_ERROR; ReportError(Printout); return result; } PrnDC = GetDC(); if ( PrnDC == 0 ) return result; PTWindowsObject Dlg = GetApplicationObject()->MakeWindow( new TPrinterAbortDlg(ParentWin, "AbortDialog", Printout->Title, Device, Port) ); if ( Dlg == NULL ) { DeleteDC(PrnDC); return result; } EnableWindow(ParentWin->HWindow, FALSE); AbortProcInst = (PTAbortProc) MakeProcInstance( (FARPROC) AbortProc, GetApplicationObject()->hInstance); Escape(PrnDC, SETABORTPROC, 0, LPSTR(AbortProcInst), NULL); // Get the page size PageSize.x = GetDeviceCaps(PrnDC, HORZRES); PageSize.y = GetDeviceCaps(PrnDC, VERTRES); // Only band if the user requests banding and the printer // supports banding Banding = ( Printout->Banding ) && (GetDeviceCaps(PrnDC, RASTERCAPS) & RC_BANDING); if ( !Banding ) { // Set the banding rectangle to full page BandRect.left = 0; BandRect.top = 0; BandRect.right = PageSize.x; BandRect.bottom = PageSize.y; } else { // Only use BANDINFO if supported (note: using Flags as a temporary) Flags = BANDINFO; // Escape(QUERYESCSUPPORT) returns nonzero for implemented // escape function, and zero otherwise. UseBandInfo = Escape(PrnDC, QUERYESCSUPPORT, sizeof(Flags), (LPSTR) &Flags, NULL); } Flags = PF_BOTH; Error = Escape(PrnDC, STARTDOC, strlen(Printout->Title), Printout->Title, NULL); PageNumber = 1; if ( Error > 0 ) { do { if ( Banding ) { FirstBand = TRUE; Error = Escape(PrnDC, NEXTBAND, 0, NULL, (LPSTR) &BandRect); } do { // Call the abort proc between bands or pages (*AbortProcInst)(PrnDC, 0); if ( Banding ) { CalcBandingFlags(); if ( (Printout->ForceAllBands) && ( ( Flags & PF_BOTH ) == PF_TEXT ) ) SetPixel(PrnDC, 0, 0, 0); } if ( Error > 0 ) { Printout->PrintPage(PrnDC, PageNumber, PageSize, &BandRect, Flags); if ( Banding ) Error = Escape(PrnDC, NEXTBAND, 0, NULL, (LPSTR) &BandRect); } } while ( (Error > 0) && (Banding) && (!IsRectEmpty(&BandRect)) ); // NewFrame should only be called if not banding if ( (Error > 0) && (!Banding) ) Error = Escape(PrnDC, NEWFRAME, 0, NULL, NULL); PageNumber++; } while ( (Error > 0) && (Printout->IsNextPage()) ); // Tell GDI the document is finished if ( Error > 0 ) { if ( Banding && UserAbort ) Escape(PrnDC, ABORTDOC, 0, NULL, NULL); else Escape(PrnDC, ENDDOC, 0, NULL, NULL); } } // Free allocated resources FreeProcInstance((FARPROC) AbortProcInst); EnableWindow(ParentWin->HWindow, TRUE); delete Dlg; DeleteDC(PrnDC); if ( Error & SP_NOTREPORTED ) ReportError(Printout); result = (Error > 0) && (!UserAbort); UserAbort = FALSE; return result; }