|
|
1.1 ! root 1: /*++ ! 2: ! 3: Copyright (c) 1993 Microsoft Corporation ! 4: ! 5: Module Name: ! 6: ! 7: fontdlg.c ! 8: ! 9: Abstract: ! 10: ! 11: Font Editor interface to the common dialog Open File and Save File ! 12: functions. Also, this routine displays and controls the font format ! 13: save dialog. ! 14: ! 15: ! 16: --*/ ! 17: ! 18: ! 19: #include "windows.h" ! 20: #include <windowsx.h> ! 21: #include "fontedit.h" ! 22: #include "commdlg.h" ! 23: ! 24: ! 25: /* message box strings loaded in sample.c from the stringtable */ ! 26: extern CHAR szIFN[], szFNF[], szREF[], szSCC[], szEOF[], szECF[]; ! 27: ! 28: extern CHAR szAppName []; ! 29: extern CHAR szExt []; ! 30: extern CHAR szExtDesc []; ! 31: ! 32: extern CHAR szNEWFONT []; ! 33: extern CHAR szFRO []; ! 34: ! 35: extern INT iFontFormat; /* Set to the id of current font format */ ! 36: extern BOOL fReadOnly; ! 37: ! 38: CHAR szDlgMsg [MAX_STR_LEN+MAX_FNAME_LEN]; ! 39: ! 40: extern CHAR szFilter[]; ! 41: ! 42: // ! 43: // Local Function Prototypes. ! 44: // ! 45: ! 46: BOOL ! 47: DlgCheckFormat ( ! 48: HANDLE hInstance, // app module instance handle ! 49: HWND hWndParent // window handle of parent window ! 50: ); ! 51: ! 52: BOOL APIENTRY ! 53: DlgFnCheckFormat ( ! 54: HWND hDlg, ! 55: WORD message, ! 56: WPARAM wParam, ! 57: LPARAM lParam ! 58: ); ! 59: ! 60: // ! 61: // Functions. ! 62: // ! 63: ! 64: BOOL ! 65: CommDlgOpen ( ! 66: HWND hWndParent, /* window handle of parent window */ ! 67: OFSTRUCT *pofsReOpenInfo,/* ptr to current file OFSTRUCT (->cBytes=0 if no ! 68: * cur. file)*/ ! 69: CHAR *pszNewNameIn, /* ptr to array which will get new file's name ! 70: * (no path) */ ! 71: CHAR *pszExtIn, /* ptr to current default extension */ ! 72: CHAR *pszFileNameOnly, /* ptr to application name */ ! 73: BOOL fOpenType ! 74: ) ! 75: { ! 76: OPENFILENAME ofTempOF; ! 77: HFILE hFile; ! 78: ! 79: ofTempOF.lStructSize = sizeof(OPENFILENAME); ! 80: ofTempOF.hwndOwner = hWndParent; ! 81: ofTempOF.lpstrFilter = szFilter; ! 82: ofTempOF.lpstrCustomFilter = (LPSTR)NULL; ! 83: ofTempOF.nMaxCustFilter = 0L; ! 84: ofTempOF.nFilterIndex = 0L; ! 85: ofTempOF.lpstrFile = pszNewNameIn; ! 86: ofTempOF.nMaxFile = MAX_FNAME_LEN; ! 87: ofTempOF.lpstrFileTitle = pszFileNameOnly; ! 88: ofTempOF.nMaxFileTitle = MAX_FNAME_LEN; ! 89: ofTempOF.lpstrInitialDir = (LPSTR)NULL; ! 90: ofTempOF.lpstrTitle = (LPSTR)NULL; ! 91: ofTempOF.Flags = OFN_SHOWHELP; ! 92: ofTempOF.nFileOffset = 0; ! 93: ofTempOF.nFileExtension = 0; ! 94: ofTempOF.lpstrDefExt = pszExtIn; ! 95: ! 96: if (fOpenType == FONT_NEW) ! 97: { ! 98: if (MessageBox (hWndParent, (LPSTR)szNEWFONT, (LPSTR)szAppName, ! 99: MB_OKCANCEL | MB_ICONEXCLAMATION | MB_APPLMODAL) == IDCANCEL) ! 100: { ! 101: return (FALSE); ! 102: } ! 103: } ! 104: ! 105: if (GetOpenFileName (&ofTempOF) == FALSE) ! 106: { ! 107: return (FALSE); ! 108: } ! 109: ! 110: CharUpper (pszNewNameIn); ! 111: ! 112: fReadOnly = FALSE; ! 113: ! 114: hFile = (HFILE)OpenFile (pszNewNameIn, pofsReOpenInfo, OF_READWRITE); ! 115: ! 116: if (hFile == (HFILE) -1) { ! 117: ! 118: hFile = (HFILE)OpenFile (pszNewNameIn, pofsReOpenInfo, OF_READ); ! 119: ! 120: if (hFile == (HFILE) -1) { ! 121: ! 122: DlgMergeStrings (szFNF, pszNewNameIn, szDlgMsg); ! 123: ! 124: MessageBox (hWndParent, szDlgMsg, szAppName, ! 125: MB_OK | MB_ICONASTERISK | MB_APPLMODAL); ! 126: ! 127: return (FALSE); ! 128: ! 129: } else if (fOpenType != FONT_NEW) { ! 130: ! 131: BOOL fResult; ! 132: ! 133: DlgMergeStrings (szFRO, pszNewNameIn, szDlgMsg); ! 134: ! 135: /* File Is Read Only */ ! 136: fResult = MessageBox (hWndParent, szDlgMsg, szAppName, ! 137: MB_OKCANCEL | MB_ICONEXCLAMATION | MB_APPLMODAL); ! 138: ! 139: /* Give them the chance to cancel right now. */ ! 140: if (fResult == IDCANCEL) { ! 141: ! 142: _lclose((HFILE)hFile); ! 143: return (FALSE); ! 144: } ! 145: ! 146: fReadOnly = TRUE; ! 147: } ! 148: } ! 149: ! 150: _lclose((HFILE)hFile); ! 151: ! 152: return (TRUE); ! 153: } ! 154: ! 155: BOOL ! 156: CommDlgSaveAs( ! 157: HANDLE hInstance, ! 158: HWND hWndParent, /* window handle of parent window */ ! 159: OFSTRUCT *pofsReOpenInfo,/* ptr to current file OFSTRUCT (->cBytes=0 if no ! 160: * cur. file)*/ ! 161: CHAR *pszNewNameIn, /* ptr to array which will get new file's name ! 162: * (no path) */ ! 163: CHAR *pszExtIn, /* ptr to current default extension */ ! 164: CHAR *pszFileNameOnly /* ptr to file name */ ! 165: ) ! 166: { ! 167: OPENFILENAME ofTempOF; ! 168: HFILE hFile; ! 169: ! 170: ofTempOF.lStructSize = sizeof(OPENFILENAME); ! 171: ofTempOF.hwndOwner = hWndParent; ! 172: ofTempOF.lpstrFilter = szFilter; ! 173: ofTempOF.lpstrCustomFilter = (LPSTR)NULL; ! 174: ofTempOF.nMaxCustFilter = 0L; ! 175: ofTempOF.nFilterIndex = 0L; ! 176: ofTempOF.lpstrFile = pszNewNameIn; ! 177: ofTempOF.nMaxFile = MAX_FNAME_LEN; ! 178: ofTempOF.lpstrFileTitle = pszFileNameOnly; ! 179: ofTempOF.nMaxFileTitle = MAX_FNAME_LEN; ! 180: ofTempOF.lpstrInitialDir = (LPSTR)NULL; ! 181: ofTempOF.lpstrTitle = (LPSTR)NULL; ! 182: ofTempOF.Flags = OFN_SHOWHELP; ! 183: ofTempOF.nFileOffset = 0; ! 184: ofTempOF.nFileExtension = 0; ! 185: ofTempOF.lpstrDefExt = pszExtIn; ! 186: ! 187: if (DlgCheckFormat (hInstance, hWndParent) == FALSE) ! 188: { ! 189: return (FALSE); ! 190: } ! 191: ! 192: if (GetSaveFileName (&ofTempOF) == FALSE) ! 193: { ! 194: return (FALSE); ! 195: } ! 196: ! 197: CharUpper (pszNewNameIn); ! 198: ! 199: hFile = (HFILE)OpenFile (pszNewNameIn, pofsReOpenInfo, OF_EXIST); ! 200: ! 201: if (hFile >= (HFILE) 0) /* already exists */ ! 202: { ! 203: _lclose((HFILE)hFile); ! 204: ! 205: DlgMergeStrings (szREF, pszNewNameIn, szDlgMsg); ! 206: ! 207: if (MessageBox (hWndParent, (LPSTR)szDlgMsg, (LPSTR)pszNewNameIn, ! 208: MB_YESNO | MB_DEFBUTTON2 | MB_ICONQUESTION | MB_APPLMODAL) ! 209: == IDNO) ! 210: { ! 211: return (FALSE); ! 212: } ! 213: ! 214: hFile = (HFILE)OpenFile (pszNewNameIn, pofsReOpenInfo, OF_WRITE); ! 215: ! 216: if (hFile == (HFILE) -1) ! 217: { ! 218: DlgMergeStrings(szEOF, pszNewNameIn, szDlgMsg); ! 219: ! 220: MessageBox(hWndParent, (LPSTR)szDlgMsg, (LPSTR)pszNewNameIn, ! 221: MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL); ! 222: ! 223: return (FALSE); ! 224: } ! 225: ! 226: _lclose((HFILE)hFile); ! 227: ! 228: return (TRUE); ! 229: } ! 230: ! 231: hFile = (HFILE)OpenFile (pszNewNameIn, pofsReOpenInfo, OF_CREATE); ! 232: ! 233: if (hFile == (HFILE) -1) ! 234: { ! 235: DlgMergeStrings(szECF, pszNewNameIn, szDlgMsg); ! 236: ! 237: MessageBox(hWndParent, (LPSTR)szDlgMsg, (LPSTR)pszNewNameIn, ! 238: MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL); ! 239: ! 240: return (FALSE); ! 241: } ! 242: ! 243: _lclose((HFILE)hFile); ! 244: ! 245: return (TRUE); ! 246: ! 247: } /* end dlgsaveas */ ! 248: ! 249: ! 250: /*============================================================================= ! 251: DLGMERGESTRINGS scans string1 for merge spec (%%). If found, insert string2 at ! 252: that point, and then append remainder of string1. Result in string3. ! 253: ==============================================================================*/ ! 254: BOOL ! 255: DlgMergeStrings( ! 256: CHAR *szSrc, ! 257: CHAR *szMerge, ! 258: CHAR *szDst ! 259: ) ! 260: { ! 261: CHAR *pchSrc; ! 262: CHAR *pchDst; ! 263: ! 264: pchSrc = szSrc; ! 265: pchDst = szDst; ! 266: ! 267: /* Find merge spec if there is one. */ ! 268: while (!((*pchSrc == '%') && (*(pchSrc+1) == '%'))) { ! 269: *pchDst++ = *pchSrc; ! 270: ! 271: /* If we reach end of string before merge spec, just return. */ ! 272: if (!*pchSrc++) ! 273: return FALSE; ! 274: ! 275: } ! 276: /* If merge spec found, insert sz2 there. (check for null merge string */ ! 277: if (szMerge) { ! 278: while (*szMerge) ! 279: *pchDst++ = *szMerge++; ! 280: ! 281: } ! 282: ! 283: /* Jump over merge spec */ ! 284: pchSrc++; pchSrc++; ! 285: ! 286: ! 287: /* Now append rest of Src String */ ! 288: while (*pchDst++ = *pchSrc++); ! 289: return TRUE; ! 290: ! 291: } /* end dlgmergestrings */ ! 292: ! 293: ! 294: BOOL ! 295: DlgCheckFormat ( ! 296: HANDLE hInstance, // app module instance handle ! 297: HWND hWndParent // window handle of parent window ! 298: ) ! 299: { ! 300: //FARPROC lpProc; ! 301: BOOL fResult; ! 302: ! 303: fResult = DialogBox (hInstance, (LPSTR)MAKEINTRESOURCE (IDD_FORMAT), ! 304: //hWndParent, (WNDPROC)(lpProc = DlgFnCheckFormat)); ! 305: hWndParent, (WNDPROC)DlgFnCheckFormat); ! 306: ! 307: //FreeProcInstance(lpProc); ! 308: ! 309: return (fResult); ! 310: ! 311: } /* end dlgcheckformat */ ! 312: ! 313: ! 314: BOOL APIENTRY ! 315: DlgFnCheckFormat ( ! 316: HWND hDlg, ! 317: WORD message, ! 318: WPARAM wParam, ! 319: LPARAM lParam ! 320: ) ! 321: { ! 322: ! 323: switch (message) ! 324: { ! 325: ! 326: case WM_INITDIALOG: ! 327: CheckRadioButton (hDlg, ID_FORMAT2, ID_FORMAT3, iFontFormat); ! 328: break; ! 329: ! 330: case WM_COMMAND: ! 331: ! 332: switch (LOWORD(wParam)) ! 333: { ! 334: case IDOK: ! 335: ! 336: EndDialog (hDlg, TRUE); ! 337: break; ! 338: ! 339: case IDCANCEL: ! 340: EndDialog (hDlg, FALSE); ! 341: break; ! 342: ! 343: case ID_FORMAT2: ! 344: case ID_FORMAT3: ! 345: CheckRadioButton(hDlg, ID_FORMAT2,ID_FORMAT3, ! 346: iFontFormat = LOWORD(wParam)); ! 347: break; ! 348: ! 349: default: ! 350: ! 351: return FALSE; ! 352: ! 353: } /* end switch wparam */ ! 354: break; ! 355: ! 356: default: ! 357: ! 358: return FALSE; ! 359: ! 360: } /* end switch message */ ! 361: ! 362: return TRUE; ! 363: ! 364: } /* end dlgsaveasdlg */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.