Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

main.c

Go to the documentation of this file.
00001 00002 /******************************************************************************\ 00003 * This is a part of the Microsoft Source Code Samples. 00004 * Copyright (C) 1993 Microsoft Corporation. 00005 * All rights reserved. 00006 * This source code is only intended as a supplement to 00007 * Microsoft Development Tools and/or WinHelp documentation. 00008 * See these sources for detailed information regarding the 00009 * Microsoft samples programs. 00010 \******************************************************************************/ 00011 00012 /**************************************************************************** 00013 * 00014 * 00015 * PROGRAM: CmnDlg.c 00016 * 00017 * PURPOSE: Sample demonstrating the use of the common dialogs in Windows 00018 * 00019 * FUNCTIONS: 00020 * 00021 * WinMain() - calls initialization function, processes message loop 00022 * InitApplication() - initializes window data and registers window 00023 * InitInstance() - saves instance handle and creates main window 00024 * MainWndProc() - processes messages 00025 * About() - processes messages for "About" dialog box 00026 * OpenNewFile() - opens a new file 00027 * SaveToFile() - saves the current text buffer to the current filename 00028 * SaveAs() - saves the current text buffer to a new file name 00029 * EnterNew() - to enter new text into the text buffer 00030 * FileOpenHookProc() - Hook procedure for GetOpenFileName() common dialog 00031 * FileSaveHookProc() - Hook procedure for GetSaveFileName() common dialog 00032 * ChooseFontHookProc() - Hook procedure for ChooseFont() common dialog 00033 * FindTextHookProc() - Hook procedure for FindText() common dialog 00034 * ReplaceTextHookProc() - Hook procedure for the ReplaceText() common dialog 00035 * PrintDlgHookProc() - Hook procedure for the PrintDlg() common dialog 00036 * PrintSetupHookProc() - Hook procedure for the PrintDlg() setup common dialog 00037 * SearchFile() - Searches for the specified text in the file buffer 00038 * ChooseNewFont() - chooses a new font for display 00039 * ChooseNewColor() - chooses a new color for display 00040 * PrintFile() - prints the current text in the file buffer 00041 * CallFindText() - calls the FindText() common dialog function 00042 * CallReplaceText() - calls the ReplaceText() common dialog function 00043 * ProcessCDError() - uses CommonDialogExtendedError() to output useful error messages 00044 * 00045 * COMMENTS: 00046 * 00047 * 00048 * The common dialog APIs demonstrated in the sample include: 00049 * 00050 * ChooseColor() 00051 * ChooseFont() 00052 * FindText() 00053 * GetOpenFileName() 00054 * GetSaveFileName() 00055 * PrintDlg() 00056 * ReplaceText() 00057 * 00058 * 00059 * Each dialog box is demonstrated being used in three different ways: 00060 * standard, using a modified template and using a hook function. 00061 * 00062 * 00063 ****************************************************************************/ 00064 00065 #include <windows.h> // includes basic windows functionality 00066 #include <commdlg.h> // includes common dialog functionality 00067 #include <dlgs.h> // includes common dialog template defines 00068 #include <stdio.h> // includes standard file i/o functionality 00069 #include <string.h> // includes string functions 00070 #include <cderr.h> // includes the common dialog error codes 00071 #include "main.h" // includes my common dialog functions 00072 #include "resource.h" 00073 00074 HANDLE hInst; 00075 OPENFILENAME OpenFileName; 00076 CHAR szDirName[256] = ""; 00077 CHAR szFile[256] = "\0"; 00078 CHAR szFileTitle[256]; 00079 00080 // Filter specification for the OPENFILENAME struct 00081 // This is portable for i386 and MIPS 00082 // Leaving out the \0 terminator will cause improper DWORD alignment 00083 // and cause a failure under MIPS 00084 CHAR szFilter[] = "Text Files (*.ICM)\0*.ICM\0All Files (*.*)\0*.*\0"; 00085 CHAR szSaveFilter[] = "Text Files (*.CSA)\0*.CSA\0All Files (*.*)\0*.*\0"; 00086 00087 CHAR FileBuf[FILE_LEN]; 00088 DWORD dwFileSize; 00089 UINT FindReplaceMsg; 00090 CHAR szFindString[64] = ""; 00091 CHAR szReplaceString[64] = ""; 00092 FINDREPLACE frText; 00093 LPFINDREPLACE lpFR; 00094 CHAR * lpBufPtr = FileBuf; 00095 CHOOSEFONT chf; 00096 CHOOSECOLOR chsclr; 00097 COLORREF crColor; 00098 LOGFONT lf; 00099 WORD wMode = IDM_CUSTOM; 00100 WORD wAsciiMode = IDM_ASCII; 00101 WORD wIntentMode = IDM_PERCEPUAL; 00102 WORD wCSAMode = IDM_AUTO; 00103 WORD wInpDrvClrSp = IDM_INP_AUTO; 00104 WORD wCSAorCRD = IDM_CSA; 00105 HWND hDlgFR = NULL; 00106 PRINTDLG pd; 00107 00108 BOOL AllowBinary = FALSE; 00109 DWORD Intent = 0; 00110 HWND hWnd; 00111 00112 BOOL WINAPI OpenFiles( 00113 HWND hDlg, /* window handle of the dialog box */ 00114 UINT message, /* type of message */ 00115 WPARAM wParam, /* message-specific information */ 00116 LPARAM lParam); 00117 00118 /**************************************************************************** 00119 * 00120 * FUNCTION: WinMain(HINSTANCE, HINSTANCE, LPSTR, int) 00121 * 00122 * PURPOSE: calls initialization function, processes message loop 00123 * 00124 * COMMENTS: 00125 * 00126 * 00127 ****************************************************************************/ 00128 00129 int PASCAL WinMain( 00130 HINSTANCE hInstance, 00131 HINSTANCE hPrevInstance, 00132 LPSTR lpCmdLine, 00133 int nCmdShow 00134 ) 00135 { 00136 00137 MSG msg; /* message */ 00138 00139 if (!hPrevInstance) /* Other instances of app running? */ 00140 if (!InitApplication(hInstance)) /* Initialize shared things */ 00141 return (FALSE); /* Exits if unable to initialize */ 00142 00143 hInst = hInstance; 00144 00145 /* Perform initializations that apply to a specific instance */ 00146 00147 if (!InitInstance(hInstance, nCmdShow)) 00148 return (FALSE); 00149 00150 // register window message for FindText() and ReplaceText() hook procs 00151 FindReplaceMsg = RegisterWindowMessage( (LPSTR) FINDMSGSTRING ); 00152 00153 /* Acquire and dispatch messages until a WM_QUIT message is received. */ 00154 00155 while (GetMessage(&msg, /* message structure */ 00156 NULL, /* handle of window receiving the message */ 00157 0, /* lowest message to examine */ 00158 0)) /* highest message to examine */ 00159 if ( !hDlgFR || !IsWindow(hDlgFR) || !IsDialogMessage( hDlgFR, &msg ) ) 00160 { 00161 TranslateMessage(&msg); /* Translates virtual key codes */ 00162 DispatchMessage(&msg); /* Dispatches message to window */ 00163 } 00164 return (msg.wParam); /* Returns the value from PostQuitMessage */ 00165 00166 // avoid compiler warnings at W3 00167 lpCmdLine; 00168 } 00169 00170 00171 /**************************************************************************** 00172 * 00173 * FUNCTION: InitApplication(HANDLE) 00174 * 00175 * PURPOSE: Initializes window data and registers window class 00176 * 00177 * COMMENTS: 00178 * 00179 * In this function, we initialize a window class by filling out a data 00180 * structure of type WNDCLASS and calling the Windows RegisterClass() 00181 * function. 00182 * 00183 ****************************************************************************/ 00184 00185 BOOL InitApplication(HANDLE hInstance) /* current instance */ 00186 { 00187 WNDCLASS wc; 00188 00189 /* Fill in window class structure with parameters that describe the */ 00190 /* main window. */ 00191 00192 wc.style = 0; /* Class style(s). */ 00193 wc.lpfnWndProc = (WNDPROC)MainWndProc; /* Function to retrieve messages for */ 00194 /* windows of this class. */ 00195 wc.cbClsExtra = 0; /* No per-class extra data. */ 00196 wc.cbWndExtra = 0; /* No per-window extra data. */ 00197 wc.hInstance = hInstance; /* Application that owns the class. */ 00198 wc.hIcon = LoadIcon(NULL, IDI_ICON1); 00199 wc.hCursor = LoadCursor(NULL, IDC_ARROW); 00200 wc.hbrBackground = GetStockObject(WHITE_BRUSH); 00201 wc.lpszMenuName = "CmnDlgMenu"; /* Name of menu resource in .RC file. */ 00202 wc.lpszClassName = "CmnDlgWClass"; /* Name used in call to CreateWindow. */ 00203 00204 /* Register the window class and return success/failure code. */ 00205 00206 return (RegisterClass(&wc)); 00207 00208 } 00209 00210 00211 /**************************************************************************** 00212 * 00213 * FUNCTION: InitInstance(HANDLE, int) 00214 * 00215 * PURPOSE: Saves instance handle and creates main window 00216 * 00217 * COMMENTS: 00218 * 00219 * In this function, we save the instance handle in a static variable and 00220 * create and display the main program window. 00221 * 00222 ****************************************************************************/ 00223 00224 BOOL InitInstance( 00225 HANDLE hInstance, /* Current instance identifier. */ 00226 int nCmdShow) /* Param for first ShowWindow() call. */ 00227 { 00228 HWND hWND; /* Main window handle. */ 00229 00230 /* Save the instance handle in static variable, which will be used in */ 00231 /* many subsequence calls from this application to Windows. */ 00232 00233 hInst = hInstance; 00234 00235 /* Create a main window for this application instance. */ 00236 00237 hWND = CreateWindow( 00238 "CmnDlgWClass", /* See RegisterClass() call. */ 00239 "CIEBASED_CDEF Color Space", /* Text for window title bar. */ 00240 WS_OVERLAPPEDWINDOW, /* Window style. */ 00241 CW_USEDEFAULT, /* Default horizontal position. */ 00242 CW_USEDEFAULT, /* Default vertical position. */ 00243 CW_USEDEFAULT, /* Default width. */ 00244 CW_USEDEFAULT, /* Default height. */ 00245 NULL, /* Overlapped windows have no parent. */ 00246 NULL, /* Use the window class menu. */ 00247 hInstance, /* This instance owns this window. */ 00248 NULL /* Pointer not needed. */ 00249 ); 00250 00251 /* If window could not be created, return "failure" */ 00252 00253 if (!hWND) 00254 return (FALSE); 00255 00256 hWnd = hWND; 00257 /* Make the window visible; update its client area; and return "success" */ 00258 00259 ShowWindow(hWnd, nCmdShow); /* Show the window */ 00260 UpdateWindow(hWnd); /* Sends WM_PAINT message */ 00261 return (TRUE); /* Returns the value from PostQuitMessage */ 00262 00263 } 00264 00265 /**************************************************************************** 00266 * 00267 * FUNCTION: MainWndProc(HWND, UINT, WPARAM, LPARAM) 00268 * 00269 * PURPOSE: Processes messages 00270 * 00271 * COMMENTS: 00272 * 00273 * This function processes all messags sent to the window. When the 00274 * user choses one of the options from one of the menus, the command 00275 * is processed here and passed onto the function for that command. 00276 * This function also processes the special "FindReplace" message that 00277 * this application registers for hook processing of the FindText() 00278 * and ReplaceText() common dialog functions. 00279 * 00280 ****************************************************************************/ 00281 00282 LRESULT CALLBACK MainWndProc( 00283 HWND hWnd, /* window handle */ 00284 UINT message, /* type of message */ 00285 WPARAM wParam, /* additional information */ 00286 LPARAM lParam) /* additional information */ 00287 { 00288 FARPROC lpProcAbout; /* pointer to the "About" function */ 00289 FARPROC lpProcOpen; 00290 FARPROC lpProcEnterNew; /* pointer to the "EnterNew" function */ 00291 HDC hDC; 00292 PAINTSTRUCT ps; 00293 INT nDrawX; 00294 INT nDrawY; 00295 HFONT hFont; 00296 HANDLE Handle; 00297 static BOOL NewFont; 00298 00299 switch (message) { 00300 00301 00302 case WM_CREATE: 00303 //initialize the output on the screen 00304 strcpy( FileBuf, " "); 00305 lpBufPtr = FileBuf; 00306 dwFileSize = strlen(FileBuf); 00307 crColor = 0; 00308 NewFont = FALSE; 00309 break; 00310 00311 00312 case WM_PAINT: 00313 /* Set up a display context to begin painting */ 00314 hDC = BeginPaint (hWnd, &ps); 00315 00316 /* Initialize drawing position to 1/4 inch from the top */ 00317 /* and from the left of the top, left corner of the */ 00318 /* client area of the main windows. */ 00319 nDrawX = GetDeviceCaps(hDC, LOGPIXELSX) / 4; /* 1/4 inch */ 00320 nDrawY = GetDeviceCaps(hDC, LOGPIXELSY) / 4; /* 1/4 inch */ 00321 00322 if ( NewFont == TRUE ) 00323 { 00324 hFont = CreateFontIndirect( &lf ); 00325 Handle = SelectObject( hDC, hFont ); 00326 } 00327 00328 SetTextColor( hDC, crColor ); 00329 00330 // end painting and release hDC 00331 EndPaint( hWnd, &ps ); 00332 break; 00333 00334 00335 case WM_COMMAND: /* message: command from application menu */ 00336 00337 switch( LOWORD( wParam )) 00338 { 00339 case IDM_OPENFILE: 00340 lpProcOpen = MakeProcInstance((FARPROC)OpenFiles, hInst); 00341 00342 DialogBox(hInst, /* current instance */ 00343 "OPENFILES", /* resource to use */ 00344 hWnd, /* parent handle */ 00345 (DLGPROC)lpProcOpen); /* About() instance address */ 00346 00347 FreeProcInstance(lpProcOpen); 00348 break; 00349 00350 case IDM_EXIT: 00351 PostQuitMessage(0); 00352 break; 00353 00354 case IDM_CHOOSECOLOR: 00355 if (ChooseNewColor( hWnd )) 00356 InvalidateRect( hWnd, NULL, TRUE ); 00357 break; 00358 00359 case IDM_CHOOSEFONT: 00360 if (NewFont = ChooseNewFont( hWnd )) 00361 InvalidateRect( hWnd, NULL, TRUE ); 00362 00363 break; 00364 00365 case IDM_FINDTEXT: 00366 CallFindText( hWnd ); 00367 break; 00368 00369 case IDM_REPLACETEXT: 00370 CallReplaceText( hWnd ); 00371 break; 00372 00373 case IDM_STANDARD: 00374 // enable the ChooseColor() option 00375 EnableMenuItem(GetMenu(hWnd), IDM_CHOOSECOLOR, 00376 MF_BYCOMMAND | MF_ENABLED ); 00377 // uncheck previous selection 00378 CheckMenuItem( GetMenu( hWnd ), wMode, MF_UNCHECKED | MF_BYCOMMAND); 00379 //reset mode 00380 wMode = LOWORD(wParam); 00381 //check new selection 00382 CheckMenuItem( GetMenu( hWnd ), wMode, MF_CHECKED | MF_BYCOMMAND); 00383 DrawMenuBar( hWnd); 00384 break; 00385 case IDM_HOOK: 00386 case IDM_CUSTOM: 00387 // disable the ChooseColor() option 00388 EnableMenuItem(GetMenu(hWnd), IDM_CHOOSECOLOR, 00389 MF_BYCOMMAND | MF_GRAYED ); 00390 // uncheck previous selection 00391 CheckMenuItem( GetMenu( hWnd ), wMode, MF_UNCHECKED | MF_BYCOMMAND); 00392 //reset mode 00393 wMode = LOWORD(wParam); 00394 //check new selection 00395 CheckMenuItem( GetMenu( hWnd ), wMode, MF_CHECKED | MF_BYCOMMAND); 00396 DrawMenuBar( hWnd); 00397 break; 00398 00399 case IDM_ENTERNEW: 00400 lpProcEnterNew = MakeProcInstance((FARPROC)EnterNew, hInst); 00401 00402 if (DialogBox(hInst, /* current instance */ 00403 "EnterNewBox", /* resource to use */ 00404 hWnd, /* parent handle */ 00405 (DLGPROC)lpProcEnterNew) == TRUE) 00406 00407 InvalidateRect( hWnd, NULL, TRUE ); 00408 00409 FreeProcInstance(lpProcEnterNew); 00410 break; 00411 00412 case IDM_PERCEPUAL: 00413 Intent = 0; 00414 CheckMenuItem( GetMenu( hWnd ), wIntentMode, MF_UNCHECKED | MF_BYCOMMAND); 00415 //reset mode 00416 wIntentMode = LOWORD(wParam); 00417 //check new selection 00418 CheckMenuItem( GetMenu( hWnd ), wIntentMode, MF_CHECKED | MF_BYCOMMAND); 00419 DrawMenuBar( hWnd); 00420 break; 00421 case IDM_COLOR: 00422 Intent = 1; 00423 CheckMenuItem( GetMenu( hWnd ), wIntentMode, MF_UNCHECKED | MF_BYCOMMAND); 00424 //reset mode 00425 wIntentMode = LOWORD(wParam); 00426 //check new selection 00427 CheckMenuItem( GetMenu( hWnd ), wIntentMode, MF_CHECKED | MF_BYCOMMAND); 00428 DrawMenuBar( hWnd); 00429 break; 00430 case IDM_SATURATION: 00431 Intent = 2; 00432 CheckMenuItem( GetMenu( hWnd ), wIntentMode, MF_UNCHECKED | MF_BYCOMMAND); 00433 //reset mode 00434 wIntentMode = LOWORD(wParam); 00435 //check new selection 00436 CheckMenuItem( GetMenu( hWnd ), wIntentMode, MF_CHECKED | MF_BYCOMMAND); 00437 DrawMenuBar( hWnd); 00438 break; 00439 00440 case IDM_ASCII: 00441 AllowBinary = FALSE; 00442 CheckMenuItem( GetMenu( hWnd ), wAsciiMode, MF_UNCHECKED | MF_BYCOMMAND); 00443 //reset mode 00444 wAsciiMode = LOWORD(wParam); 00445 //check new selection 00446 CheckMenuItem( GetMenu( hWnd ), wAsciiMode, MF_CHECKED | MF_BYCOMMAND); 00447 DrawMenuBar( hWnd); 00448 break; 00449 case IDM_BINARY: 00450 AllowBinary = TRUE; 00451 CheckMenuItem( GetMenu( hWnd ), wAsciiMode, MF_UNCHECKED | MF_BYCOMMAND); 00452 //reset mode 00453 wAsciiMode = LOWORD(wParam); 00454 //check new selection 00455 CheckMenuItem( GetMenu( hWnd ), wAsciiMode, MF_CHECKED | MF_BYCOMMAND); 00456 DrawMenuBar( hWnd); 00457 break; 00458 case IDM_AUTO: 00459 case IDM_ABC: 00460 case IDM_DEFG: 00461 CheckMenuItem( GetMenu( hWnd ), wCSAMode, MF_UNCHECKED | MF_BYCOMMAND); 00462 //reset mode 00463 wCSAMode = LOWORD(wParam); 00464 //check new selection 00465 CheckMenuItem( GetMenu( hWnd ), wCSAMode, MF_CHECKED | MF_BYCOMMAND); 00466 DrawMenuBar( hWnd); 00467 break; 00468 00469 case IDM_INP_AUTO: 00470 case IDM_INP_GRAY: 00471 case IDM_INP_RGB: 00472 case IDM_INP_CMYK: 00473 CheckMenuItem( GetMenu( hWnd ), wInpDrvClrSp, MF_UNCHECKED | MF_BYCOMMAND); 00474 //reset mode 00475 wInpDrvClrSp = LOWORD(wParam); 00476 //check new selection 00477 CheckMenuItem( GetMenu( hWnd ), wInpDrvClrSp, MF_CHECKED | MF_BYCOMMAND); 00478 DrawMenuBar( hWnd); 00479 break; 00480 00481 case IDM_CSA: 00482 case IDM_CRD: 00483 case IDM_PROFCRD: 00484 case IDM_INTENT: 00485 CheckMenuItem( GetMenu( hWnd ), wCSAorCRD, MF_UNCHECKED | MF_BYCOMMAND); 00486 //reset mode 00487 wCSAorCRD = LOWORD(wParam); 00488 if ((wCSAorCRD == IDM_CRD) || (wCSAorCRD == IDM_INTENT)) 00489 { 00490 EnableMenuItem(GetMenu(hWnd), IDM_INP_AUTO, MF_BYCOMMAND | MF_GRAYED ); 00491 EnableMenuItem(GetMenu(hWnd), IDM_INP_GRAY, MF_BYCOMMAND | MF_GRAYED ); 00492 EnableMenuItem(GetMenu(hWnd), IDM_INP_RGB, MF_BYCOMMAND | MF_GRAYED ); 00493 EnableMenuItem(GetMenu(hWnd), IDM_INP_CMYK, MF_BYCOMMAND | MF_GRAYED ); 00494 EnableMenuItem(GetMenu(hWnd), IDM_AUTO, MF_BYCOMMAND | MF_GRAYED ); 00495 EnableMenuItem(GetMenu(hWnd), IDM_ABC, MF_BYCOMMAND | MF_GRAYED ); 00496 EnableMenuItem(GetMenu(hWnd), IDM_DEFG, MF_BYCOMMAND | MF_GRAYED ); 00497 } 00498 else 00499 { 00500 EnableMenuItem(GetMenu(hWnd), IDM_INP_AUTO, MF_BYCOMMAND | MF_ENABLED ); 00501 EnableMenuItem(GetMenu(hWnd), IDM_INP_GRAY, MF_BYCOMMAND | MF_ENABLED ); 00502 EnableMenuItem(GetMenu(hWnd), IDM_INP_RGB, MF_BYCOMMAND | MF_ENABLED ); 00503 EnableMenuItem(GetMenu(hWnd), IDM_INP_CMYK, MF_BYCOMMAND | MF_ENABLED ); 00504 EnableMenuItem(GetMenu(hWnd), IDM_AUTO, MF_BYCOMMAND | MF_ENABLED ); 00505 EnableMenuItem(GetMenu(hWnd), IDM_ABC, MF_BYCOMMAND | MF_ENABLED ); 00506 EnableMenuItem(GetMenu(hWnd), IDM_DEFG, MF_BYCOMMAND | MF_ENABLED ); 00507 } 00508 00509 //check new selection 00510 CheckMenuItem( GetMenu( hWnd ), wCSAorCRD, MF_CHECKED | MF_BYCOMMAND); 00511 DrawMenuBar( hWnd); 00512 break; 00513 00514 case IDM_ABOUT: 00515 lpProcAbout = MakeProcInstance((FARPROC)About, hInst); 00516 00517 DialogBox(hInst, /* current instance */ 00518 "AboutBox", /* resource to use */ 00519 hWnd, /* parent handle */ 00520 (DLGPROC)lpProcAbout); /* About() instance address */ 00521 00522 FreeProcInstance(lpProcAbout); 00523 break; 00524 00525 default: 00526 return (DefWindowProc(hWnd, message, wParam, lParam)); 00527 00528 } 00529 break; 00530 00531 case WM_DESTROY: /* message: window being destroyed */ 00532 PostQuitMessage(0); 00533 break; 00534 00535 00536 default: 00537 // Handle the special findreplace message (FindReplaceMsg) which 00538 // was registered at initialization time. 00539 if ( message == FindReplaceMsg ) 00540 { 00541 if ( lpFR = (LPFINDREPLACE) lParam ) 00542 { 00543 if (lpFR->Flags & FR_DIALOGTERM ) // terminating dialog 00544 return (0); 00545 SearchFile( lpFR ); 00546 InvalidateRect( hWnd, NULL, TRUE ); 00547 } 00548 return (0); 00549 } 00550 00551 return (DefWindowProc(hWnd, message, wParam, lParam)); 00552 } 00553 return (0); 00554 } 00555 00556 00557 /**************************************************************************** 00558 * 00559 * FUNCTION: EnterNew(HWND, UINT, WPARAM, LPARAM) 00560 * 00561 * PURPOSE: Processes messages for "EnterNew" dialog box 00562 * 00563 * COMMENTS: 00564 * 00565 * This function allows the user to enter new text in the current 00566 * window. This text is stored in the global current buffer. 00567 * 00568 ****************************************************************************/ 00569 00570 BOOL CALLBACK EnterNew( 00571 HWND hDlg, /* window handle of the dialog box */ 00572 UINT message, /* type of message */ 00573 WPARAM wParam, /* message-specific information */ 00574 LPARAM lParam) 00575 { 00576 CHAR Buf[FILE_LEN-1]; 00577 00578 switch (message) 00579 { 00580 case WM_INITDIALOG: /* message: initialize dialog box */ 00581 return (TRUE); 00582 00583 case WM_COMMAND: /* message: received a command */ 00584 if (LOWORD(wParam) == IDOK) 00585 { 00586 GetDlgItemText( hDlg, IDEDIT, Buf, FILE_LEN-1); 00587 strcpy( FileBuf, Buf); 00588 lpBufPtr = FileBuf; 00589 dwFileSize = strlen(FileBuf); 00590 EndDialog( hDlg, TRUE ); 00591 return (TRUE); 00592 } 00593 else if (LOWORD(wParam) == IDCANCEL) 00594 { /* System menu close command? */ 00595 EndDialog(hDlg, FALSE); /* Exits the dialog box */ 00596 return (TRUE); 00597 } 00598 break; 00599 } 00600 return (FALSE); /* Didn't process a message */ 00601 00602 // avoid compiler warnings at W3 00603 lParam; 00604 } 00605 00606 00607 /**************************************************************************** 00608 * 00609 * FUNCTION: About(HWND, UINT, WPARAM, LPARAM) 00610 * 00611 * PURPOSE: Processes messages for "About" dialog box 00612 * 00613 * COMMENTS: 00614 * 00615 * No initialization is needed for this particular dialog box, but TRUE 00616 * must be returned to Windows. 00617 * 00618 * Wait for user to click on "Ok" button, then close the dialog box. 00619 * 00620 ****************************************************************************/ 00621 00622 BOOL WINAPI About( 00623 HWND hDlg, /* window handle of the dialog box */ 00624 UINT message, /* type of message */ 00625 WPARAM wParam, /* message-specific information */ 00626 LPARAM lParam) 00627 { 00628 switch (message) 00629 { 00630 case WM_INITDIALOG: /* message: initialize dialog box */ 00631 return (TRUE); 00632 00633 case WM_COMMAND: /* message: received a command */ 00634 if (LOWORD(wParam) == IDOK /* "OK" box selected? */ 00635 || LOWORD(wParam) == IDCANCEL) { /* System menu close command? */ 00636 EndDialog(hDlg, TRUE); /* Exits the dialog box */ 00637 return (TRUE); 00638 } 00639 break; 00640 } 00641 return (FALSE); /* Didn't process a message */ 00642 00643 // avoid compiler warnings at W3 00644 lParam; 00645 } 00646 00647 /**************************************************************************** 00648 * 00649 * FUNCTION: FileOpenHookProc(HWND, UINT, WPARAM, LPARAM) 00650 * 00651 * PURPOSE: Processes messages for GetFileNameOpen() common dialog box 00652 * 00653 * COMMENTS: 00654 * 00655 * This function will prompt the user if they are sure they want 00656 * to open the file if the OFN_ENABLEHOOK flag is set. 00657 * 00658 * If the current option mode is CUSTOM, the user is allowed to check 00659 * a box in the dialog prompting them whether or not they would like 00660 * the file created. If they check this box, the file is created and 00661 * the string 'Empty' is written to it. 00662 * 00663 * RETURN VALUES: 00664 * TRUE - User chose 'Yes' from the "Are you sure message box". 00665 * FALSE - User chose 'No'; return to the dialog box. 00666 * 00667 ****************************************************************************/ 00668 00669 BOOL CALLBACK FileOpenHookProc( 00670 HWND hDlg, /* window handle of the dialog box */ 00671 UINT message, /* type of message */ 00672 WPARAM wParam, /* message-specific information */ 00673 LPARAM lParam) 00674 { 00675 00676 int hFile; 00677 CHAR szTempText[256]; 00678 CHAR szString[256]; 00679 OFSTRUCT OfStruct; 00680 00681 switch (message) 00682 { 00683 00684 case WM_COMMAND: 00685 if (LOWORD(wParam) == IDOK) 00686 { 00687 GetDlgItemText( hDlg, edt1, szTempText, 00688 sizeof( szTempText ) - 1); 00689 00690 if ( OpenFileName.Flags & OFN_PATHMUSTEXIST ) 00691 { 00692 sprintf( szString, "Are you sure you want to open %s?", 00693 szTempText); 00694 if ( MessageBox( hDlg, szString, "Information", 00695 MB_YESNO ) == IDYES ) 00696 00697 break; 00698 return (TRUE); 00699 } 00700 00701 // check to see if the Create File box has been checked 00702 if ( (BOOL)(SendMessage( GetDlgItem(hDlg, chx2), 00703 BM_GETCHECK, 0, 0L )) == TRUE ) 00704 { 00705 // if so, create the file 00706 if ((hFile = OpenFile(szTempText, 00707 &OfStruct, 00708 OF_CREATE)) == -1) 00709 { 00710 MessageBox( hDlg, 00711 "Directory could not be created.", 00712 NULL, 00713 MB_OK ); 00714 return (FALSE); 00715 } 00716 00717 strcpy(FileBuf, "Empty"); 00718 lpBufPtr = FileBuf; 00719 dwFileSize = strlen(FileBuf); 00720 if (_lwrite( hFile, (LPSTR)&FileBuf[0], dwFileSize)==-1) 00721 MessageBox( hDlg, "Error writing file.", NULL, MB_OK ); 00722 00723 // close the file 00724 _lclose( hFile ); 00725 } 00726 00727 } 00728 break; 00729 } 00730 return (FALSE); 00731 00732 // avoid compiler warnings at W3 00733 lParam; 00734 00735 } 00736 00737 /**************************************************************************** 00738 * 00739 * FUNCTION: OpenNewFile(HWND) 00740 * 00741 * PURPOSE: Invokes common dialog function to open a file and opens it. 00742 * 00743 * COMMENTS: 00744 * 00745 * This function initializes the OPENFILENAME structure and calls 00746 * the GetOpenFileName() common dialog function. This function will 00747 * work regardless of the mode: standard, using a hook or using a 00748 * customized template. 00749 * 00750 * RETURN VALUES: 00751 * TRUE - The file was opened successfully and read into the buffer. 00752 * FALSE - No files were opened. 00753 * 00754 ****************************************************************************/ 00755 BOOL OpenNewFile( HWND hWnd ) 00756 { 00757 strcpy( szFile, ""); 00758 strcpy( szFileTitle, ""); 00759 00760 OpenFileName.lStructSize = sizeof(OPENFILENAME); 00761 OpenFileName.hwndOwner = hWnd; 00762 OpenFileName.hInstance = (HANDLE) hInst; 00763 OpenFileName.lpstrFilter = szFilter; 00764 OpenFileName.lpstrCustomFilter = (LPSTR) NULL; 00765 OpenFileName.nMaxCustFilter = 0L; 00766 OpenFileName.nFilterIndex = 1L; 00767 OpenFileName.lpstrFile = szFile; 00768 OpenFileName.nMaxFile = sizeof(szFile); 00769 OpenFileName.lpstrFileTitle = szFileTitle; 00770 OpenFileName.nMaxFileTitle = sizeof(szFileTitle); 00771 OpenFileName.lpstrInitialDir = NULL; 00772 OpenFileName.lpstrTitle = "Open a File"; 00773 OpenFileName.nFileOffset = 0; 00774 OpenFileName.nFileExtension = 0; 00775 OpenFileName.lpstrDefExt = "*.icm"; 00776 OpenFileName.lCustData = 0; 00777 00778 switch( wMode ) 00779 { 00780 case IDM_STANDARD: 00781 OpenFileName.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST | 00782 OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; 00783 break; 00784 00785 case IDM_HOOK: 00786 OpenFileName.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST | 00787 OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_ENABLEHOOK; 00788 OpenFileName.lpfnHook = (LPOFNHOOKPROC)MakeProcInstance(FileOpenHookProc, NULL); 00789 break; 00790 00791 case IDM_CUSTOM: 00792 OpenFileName.Flags = OFN_SHOWHELP | OFN_ENABLEHOOK | 00793 OFN_HIDEREADONLY | OFN_ENABLETEMPLATE; 00794 OpenFileName.lpfnHook = (LPOFNHOOKPROC)MakeProcInstance(FileOpenHookProc, NULL); 00795 OpenFileName.lpTemplateName = (LPSTR)MAKEINTRESOURCE(FILEOPENORD); 00796 break; 00797 } 00798 00799 if (GetOpenFileName(&OpenFileName)) 00800 { 00801 } 00802 else 00803 { 00804 ProcessCDError(CommDlgExtendedError(), hWnd ); 00805 return FALSE; 00806 } 00807 return TRUE; 00808 } 00809 00810 /**************************************************************************** 00811 * 00812 * FUNCTION: SaveToFile( HWND ) 00813 * 00814 * PURPOSE: Saves the current buffer to the current file. 00815 * 00816 * COMMENTS: 00817 * 00818 * This function will save the current text buffer into the file 00819 * specified from the GetSaveFileName() common dialog function. 00820 * 00821 * RETURN VALUES: 00822 * TRUE - The file was saved successfully. 00823 * FALSE - The buffer was not saved to a file. 00824 * 00825 ****************************************************************************/ 00826 BOOL SaveToFile( HWND hWnd ) 00827 { 00828 int hFile; 00829 OFSTRUCT OfStruct; 00830 WORD wStyle; 00831 CHAR buf[256]; 00832 00833 if (OpenFileName.Flags | OFN_FILEMUSTEXIST) 00834 wStyle = OF_READWRITE; 00835 else 00836 wStyle = OF_READWRITE | OF_CREATE; 00837 00838 if ((hFile = OpenFile(OpenFileName.lpstrFile, &OfStruct, 00839 wStyle)) == -1) 00840 { 00841 sprintf( buf, "Could not create file %s", OpenFileName.lpstrFile ); 00842 MessageBox( hWnd, buf, NULL, MB_OK ); 00843 return FALSE; 00844 } 00845 // write it's contents into a file 00846 if (_lwrite( hFile, (LPSTR)&FileBuf[0], dwFileSize)==-1) 00847 { 00848 MessageBox( hWnd, "Error writing file.", NULL, MB_OK ); 00849 return FALSE; 00850 } 00851 00852 // close the file 00853 _lclose( hFile ); 00854 00855 sprintf( buf, "%s", OpenFileName.lpstrFile ); 00856 MessageBox( hWnd, buf, "File Saved", MB_OK ); 00857 return TRUE; 00858 } 00859 00860 00861 /**************************************************************************** 00862 * 00863 * FUNCTION: FileSaveHookProc(HWND, UINT, WPARAM, LPARAM) 00864 * 00865 * PURPOSE: Processes messages for FileSave common dialog box 00866 * 00867 * COMMENTS: 00868 * 00869 * This hook procedure prompts the user if they want to save the 00870 * current file. If they choose YES, the file is saved and the dialog 00871 * is dismissed. If they choose NO, they are returned to the 00872 * GetSaveFileName() common dialog. 00873 * 00874 * If the current mode calls for a customized template, this function 00875 * will test the 'Create File?' checkbox. If the user choses no, the 00876 * OFN_FILEMUSTEXIST flag is set. 00877 * 00878 * RETURN VALUES: 00879 * TRUE - User chose 'Yes' from the "Are you sure message box". 00880 * FALSE - User chose 'No'; return to the dialog box. 00881 * 00882 * 00883 ****************************************************************************/ 00884 00885 BOOL CALLBACK FileSaveHookProc( 00886 HWND hDlg, /* window handle of the dialog box */ 00887 UINT message, /* type of message */ 00888 WPARAM wParam, /* message-specific information */ 00889 LPARAM lParam) 00890 { 00891 CHAR szTempText[256]; 00892 CHAR szString[256]; 00893 00894 switch (message) 00895 { 00896 case WM_COMMAND: 00897 if (LOWORD(wParam) == IDOK) 00898 { 00899 GetDlgItemText( hDlg, edt1, szTempText, 00900 sizeof( szTempText ) - 1); 00901 if ( OpenFileName.Flags & OFN_ENABLETEMPLATE ) 00902 { 00903 // check to see if the Create File box has been checked 00904 if ( (BOOL)(SendMessage( GetDlgItem(hDlg, chx2), 00905 BM_GETCHECK, 0, 0L )) == FALSE ) 00906 OpenFileName.Flags |= OFN_FILEMUSTEXIST; 00907 break; 00908 00909 } 00910 else 00911 { 00912 sprintf( szString, "Are you sure you want to save %s?", 00913 szTempText); 00914 if ( MessageBox( hDlg, szString, "Information", 00915 MB_YESNO ) == IDYES ) 00916 break; 00917 return(TRUE); 00918 } 00919 00920 } 00921 break; 00922 } 00923 return (FALSE); 00924 00925 // avoid compiler warnings at W3 00926 lParam; 00927 00928 } 00929 00930 /**************************************************************************** 00931 * 00932 * FUNCTION: SaveAs(HWND) 00933 * 00934 * PURPOSE: Invokes the common dialog function to save the current 00935 * buffer to a file. 00936 * COMMENTS: 00937 * 00938 * This function initializes the OPENFILENAME structure for any 00939 * mode selected by the user: standard, using a hook or using a 00940 * customized template. It then calls the GetSaveFileName() 00941 * common dialog function. 00942 * 00943 * RETURN VALUES: 00944 * TRUE - The file was saved successfully. 00945 * FALSE - The buffer was not saved to a file. 00946 * 00947 ****************************************************************************/ 00948 BOOL SaveAs( HWND hWnd ) 00949 { 00950 int i; 00951 00952 // strcpy( szFile, ""); 00953 // strcpy( szFileTitle, ""); 00954 00955 for ( i = lstrlen(OpenFileName.lpstrFileTitle); i > 0; i--) 00956 { 00957 if (OpenFileName.lpstrFileTitle[i] == '.') break; 00958 } 00959 i ++; 00960 if (wCSAorCRD == IDM_CSA) 00961 { 00962 OpenFileName.lpstrFileTitle[i++] = 'C'; 00963 OpenFileName.lpstrFileTitle[i++] = 'S'; 00964 OpenFileName.lpstrFileTitle[i++] = 'A'; 00965 OpenFileName.lpstrFileTitle[i] = 0; 00966 } 00967 else if ((wCSAorCRD == IDM_CRD) || 00968 (wCSAorCRD == IDM_PROFCRD)) 00969 { 00970 OpenFileName.lpstrFileTitle[i++] = 'C'; 00971 OpenFileName.lpstrFileTitle[i++] = 'R'; 00972 OpenFileName.lpstrFileTitle[i++] = 'D'; 00973 OpenFileName.lpstrFileTitle[i] = 0; 00974 } 00975 else 00976 { 00977 OpenFileName.lpstrFileTitle[i++] = 'I'; 00978 OpenFileName.lpstrFileTitle[i++] = 'N'; 00979 OpenFileName.lpstrFileTitle[i++] = 'T'; 00980 OpenFileName.lpstrFileTitle[i] = 0; 00981 } 00982 strcpy(OpenFileName.lpstrFile, OpenFileName.lpstrFileTitle); 00983 00984 OpenFileName.lStructSize = sizeof(OPENFILENAME); 00985 OpenFileName.hwndOwner = hWnd; 00986 OpenFileName.hInstance = (HANDLE) hInst; 00987 OpenFileName.lpstrFilter = szSaveFilter; 00988 OpenFileName.lpstrCustomFilter = (LPSTR) NULL; 00989 OpenFileName.nMaxCustFilter = 0L; 00990 OpenFileName.nFilterIndex = 1L; 00991 OpenFileName.nMaxFile = sizeof(szFile); 00992 OpenFileName.nMaxFileTitle = sizeof(szFileTitle); 00993 OpenFileName.lpstrInitialDir = NULL; 00994 OpenFileName.lpstrTitle = "Save File As"; 00995 OpenFileName.nFileOffset = 0; 00996 OpenFileName.nFileExtension = 0; 00997 OpenFileName.lpstrDefExt = "*.csa"; 00998 OpenFileName.lCustData = 0; 00999 01000 switch( wMode ) 01001 { 01002 case IDM_STANDARD: 01003 OpenFileName.Flags = 0L; 01004 OpenFileName.lpfnHook = (LPOFNHOOKPROC)(FARPROC)NULL; 01005 OpenFileName.lpTemplateName = (LPSTR)NULL; 01006 break; 01007 01008 case IDM_HOOK: 01009 OpenFileName.Flags = OFN_ENABLEHOOK; 01010 OpenFileName.lpfnHook = (LPOFNHOOKPROC)MakeProcInstance(FileSaveHookProc, NULL); 01011 OpenFileName.lpTemplateName = (LPSTR)NULL; 01012 break; 01013 01014 case IDM_CUSTOM: 01015 OpenFileName.Flags = OFN_ENABLEHOOK | OFN_ENABLETEMPLATE; 01016 OpenFileName.lpfnHook = (LPOFNHOOKPROC)MakeProcInstance(FileSaveHookProc, NULL); 01017 OpenFileName.lpTemplateName = (LPSTR)MAKEINTRESOURCE(FILEOPENORD); 01018 break; 01019 } 01020 01021 if ( GetSaveFileName( &OpenFileName )) 01022 { 01023 return (TRUE); 01024 } 01025 else 01026 { 01027 ProcessCDError(CommDlgExtendedError(), hWnd ); 01028 return FALSE; 01029 } 01030 01031 return (FALSE); 01032 } 01033 01034 01035 /**************************************************************************** 01036 * 01037 * FUNCTION: ChooseColorHookProc(HWND, UINT, WPARAM, LPARAM) 01038 * 01039 * PURPOSE: Processes messages for ChooseColor common dialog box 01040 * 01041 * COMMENTS: 01042 * 01043 * This hook procedure simply prompts the user whether or not they 01044 * want to change the color. if they choose YES, the color of the 01045 * text will be changed and the dialog will be dismissed. If they 01046 * choose NO, the color will not be changed and the user will be 01047 * returned to the dialog 01048 * 01049 * RETURN VALUES: 01050 * TRUE - User chose 'Yes' from the "Are you sure message box". 01051 * FALSE - User chose 'No'; return to the dialog box. 01052 * 01053 ****************************************************************************/ 01054 01055 BOOL CALLBACK ChooseColorHookProc( 01056 HWND hDlg, /* window handle of the dialog box */ 01057 UINT message, /* type of message */ 01058 WPARAM wParam, /* message-specific information */ 01059 LPARAM lParam) 01060 { 01061 01062 switch (message) 01063 { 01064 case WM_COMMAND: 01065 if (LOWORD(wParam) == IDOK) 01066 { 01067 if (MessageBox( hDlg, "Are you sure you want to change the color?", 01068 "Information", MB_YESNO ) == IDYES ) 01069 break; 01070 return (TRUE); 01071 01072 } 01073 break; 01074 } 01075 return (FALSE); 01076 01077 // avoid compiler warnings at W3 01078 lParam; 01079 01080 } 01081 01082 01083 /**************************************************************************** 01084 * 01085 * FUNCTION: ChooseNewColor(HWND) 01086 * 01087 * PURPOSE: Invokes common dialog function to chose a new color. 01088 * 01089 * COMMENTS: 01090 * This function initializes the CHOOSECOLOR structure for any 01091 * mode the user chooses: standard, using a hook or using a 01092 * customized template. It then calls the ChooseColor() 01093 * common dialog function. 01094 * 01095 * RETURN VALUES: 01096 * TRUE - A new color was chosen. 01097 * FALSE - No new color was chosen. 01098 * 01099 ****************************************************************************/ 01100 BOOL ChooseNewColor( HWND hWnd ) 01101 { 01102 01103 DWORD dwColor; 01104 DWORD dwCustClrs[16]; 01105 BOOL fSetColor = FALSE; 01106 int i; 01107 01108 01109 for (i=0; i < 15; i++) 01110 dwCustClrs[i] = RGB( 255, 255, 255); 01111 01112 dwColor = RGB( 0, 0, 0 ); 01113 01114 chsclr.lStructSize = sizeof(CHOOSECOLOR); 01115 chsclr.hwndOwner = hWnd; 01116 chsclr.hInstance = (HANDLE)hInst; 01117 chsclr.rgbResult = dwColor; 01118 chsclr.lpCustColors = (LPDWORD)dwCustClrs; 01119 chsclr.lCustData = 0L; 01120 01121 switch( wMode ) 01122 { 01123 case IDM_HOOK: 01124 case IDM_CUSTOM: 01125 chsclr.Flags = CC_PREVENTFULLOPEN | CC_ENABLEHOOK; 01126 chsclr.lpfnHook = (LPCCHOOKPROC)MakeProcInstance(ChooseColorHookProc, NULL); 01127 chsclr.lpTemplateName = (LPSTR)NULL; 01128 break; 01129 01130 case IDM_STANDARD: 01131 chsclr.Flags = CC_PREVENTFULLOPEN; 01132 chsclr.lpfnHook = (LPCCHOOKPROC)(FARPROC)NULL; 01133 chsclr.lpTemplateName = (LPSTR)NULL; 01134 break; 01135 01136 01137 } 01138 01139 if ( fSetColor = ChooseColor( &chsclr )) 01140 { 01141 crColor = chsclr.rgbResult; 01142 return (TRUE); 01143 } 01144 else 01145 { 01146 ProcessCDError(CommDlgExtendedError(), hWnd ); 01147 return FALSE; 01148 } 01149 } 01150 01151 01152 /**************************************************************************** 01153 * 01154 * FUNCTION: ChooseFontHookProc(HWND, UINT, WPARAM, LPARAM) 01155 * 01156 * PURPOSE: Processes messages for ChooseFont common dialog box 01157 * 01158 * COMMENTS: 01159 * 01160 * This hook procedure simply prompts the user whether or not they 01161 * want to change the font. if they choose YES, the color of the 01162 * font will be changed and the dialog will be dismissed. If they 01163 * choose NO, the font will not be changed and the user will be 01164 * returned to the dialog 01165 * 01166 * If the current mode is set to use a customized template, the 01167 * color drop down combo box is hidden. 01168 * 01169 * RETURN VALUES: 01170 * TRUE - Change the font. 01171 * FALSE - Return to the dialog box. 01172 * 01173 ****************************************************************************/ 01174 01175 BOOL CALLBACK ChooseFontHookProc( 01176 HWND hDlg, /* window handle of the dialog box */ 01177 UINT message, /* type of message */ 01178 WPARAM wParam, /* message-specific information */ 01179 LPARAM lParam) 01180 { 01181 01182 switch (message) 01183 { 01184 case WM_INITDIALOG: 01185 if (chf.Flags & CF_ENABLETEMPLATE) 01186 { 01187 ShowWindow(GetDlgItem(hDlg, stc4), SW_HIDE); 01188 ShowWindow(GetDlgItem(hDlg, cmb4), SW_HIDE); 01189 } 01190 break; 01191 01192 case WM_COMMAND: 01193 if (LOWORD(wParam) == IDOK) 01194 { 01195 if (MessageBox( hDlg, "Are you sure you want to change the font?", 01196 "Information", MB_YESNO ) == IDYES ) 01197 break; 01198 return (TRUE); 01199 01200 } 01201 break; 01202 } 01203 return (FALSE); 01204 01205 // avoid compiler warnings at W3 01206 lParam; 01207 01208 } 01209 01210 01211 /**************************************************************************** 01212 * 01213 * FUNCTION: ChooseNewFont(HWND) 01214 * 01215 * PURPOSE: Invokes common dialog function to chose a new font. 01216 * 01217 * COMMENTS: 01218 * 01219 * This function initializes the CHOOSEFONT structure for any mode 01220 * the user chooses: standard, using a hook or using a customized 01221 * template. It then calls the ChooseFont() common dialog function. 01222 * 01223 * RETURN VALUES: 01224 * TRUE - A new font was chosen. 01225 * FALSE - No new font was chosen. 01226 * 01227 ****************************************************************************/ 01228 BOOL ChooseNewFont( HWND hWnd ) 01229 { 01230 01231 HDC hDC; 01232 01233 hDC = GetDC( hWnd ); 01234 chf.hDC = CreateCompatibleDC( hDC ); 01235 ReleaseDC( hWnd, hDC ); 01236 chf.lStructSize = sizeof(CHOOSEFONT); 01237 chf.hwndOwner = hWnd; 01238 chf.lpLogFont = &lf; 01239 chf.Flags = CF_SCREENFONTS | CF_EFFECTS; 01240 chf.rgbColors = RGB(0, 255, 255); 01241 chf.lCustData = 0; 01242 chf.hInstance = (HANDLE)hInst; 01243 chf.lpszStyle = (LPSTR)NULL; 01244 chf.nFontType = SCREEN_FONTTYPE; 01245 chf.nSizeMin = 0; 01246 chf.nSizeMax = 0; 01247 01248 switch( wMode ) 01249 { 01250 case IDM_STANDARD: 01251 chf.Flags = CF_SCREENFONTS | CF_EFFECTS; 01252 chf.lpfnHook = (LPCFHOOKPROC)(FARPROC)NULL; 01253 chf.lpTemplateName = (LPSTR)NULL; 01254 break; 01255 01256 case IDM_HOOK: 01257 chf.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_ENABLEHOOK; 01258 chf.lpfnHook = (LPCFHOOKPROC)MakeProcInstance(ChooseFontHookProc, NULL); 01259 chf.lpTemplateName = (LPSTR)NULL; 01260 break; 01261 01262 case IDM_CUSTOM: 01263 chf.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_ENABLEHOOK | 01264 CF_ENABLETEMPLATE; 01265 chf.lpfnHook = (LPCFHOOKPROC)MakeProcInstance(ChooseFontHookProc, NULL); 01266 chf.lpTemplateName = (LPSTR)MAKEINTRESOURCE(FORMATDLGORD31); 01267 break; 01268 } 01269 01270 01271 if( ChooseFont( &chf ) == FALSE ) 01272 { 01273 DeleteDC( hDC ); 01274 ProcessCDError(CommDlgExtendedError(), hWnd ); 01275 return FALSE; 01276 } 01277 01278 01279 DeleteDC( hDC ); 01280 01281 return (TRUE); 01282 } 01283 01284 /**************************************************************************** 01285 * 01286 * FUNCTION: PrintSetupHookProc(HWND, UINT, WPARAM, LPARAM) 01287 * 01288 * PURPOSE: Processes messages for PrintDlg setup common dialog box 01289 * 01290 * COMMENTS: 01291 * 01292 * This function processes the hook and customized template for the 01293 * print setup common dialog box. If the customized template has 01294 * been provided, the 'Options' pushbutton is hidden. If the hook only mode 01295 * is chosen, a message box is displayed informing the user that the 01296 * hook has been installed. 01297 * 01298 * RETURN VALUES: 01299 * TRUE - Continue. 01300 * FALSE - Return to the dialog box. 01301 * 01302 ****************************************************************************/ 01303 01304 BOOL CALLBACK PrintSetupHookProc( 01305 HWND hDlg, /* window handle of the dialog box */ 01306 UINT message, /* type of message */ 01307 WPARAM wParam, /* message-specific information */ 01308 LPARAM lParam) 01309 { 01310 01311 switch (message) 01312 { 01313 case WM_INITDIALOG: 01314 if (pd.Flags & PD_ENABLESETUPTEMPLATE ) 01315 { 01316 ShowWindow( GetDlgItem(hDlg, psh1), SW_HIDE ); 01317 return(TRUE); 01318 } 01319 MessageBox( hDlg, 01320 "Hook installed.", 01321 "Information", MB_OK ); 01322 return (TRUE); 01323 } 01324 return (FALSE); 01325 01326 // avoid compiler warnings at W3 01327 lParam; 01328 wParam; 01329 } 01330 01331 01332 01333 /**************************************************************************** 01334 * 01335 * FUNCTION: PrintDlgHookProc(HWND, UINT, UINT, LONG) 01336 * 01337 * PURPOSE: Processes messages for PrintDlg common dialog box 01338 * 01339 * COMMENTS: 01340 * 01341 * This hook procedure simply prompts the user whether or not they 01342 * want to print. if they choose YES, the text buf will be printed 01343 * and the dialog will be dismissed. If they choose NO, the text buf 01344 * will not be printeded and the user will be returned to the dialog. 01345 * 01346 * If the current mode is 'custom', the 'Print to file' and 'Collate 01347 * Copies' options are hidden. 01348 * 01349 * RETURN VALUES: 01350 * TRUE - Continue. 01351 * FALSE - Return to the dialog box. 01352 * 01353 ****************************************************************************/ 01354 01355 BOOL CALLBACK PrintDlgHookProc( 01356 HWND hDlg, /* window handle of the dialog box */ 01357 UINT message, /* type of message */ 01358 WPARAM wParam, /* message-specific information */ 01359 LPARAM lParam) 01360 { 01361 01362 switch (message) 01363 { 01364 case WM_INITDIALOG: 01365 if (pd.Flags & PD_ENABLEPRINTTEMPLATE ) 01366 { 01367 ShowWindow( GetDlgItem(hDlg, chx1), SW_HIDE ); 01368 ShowWindow( GetDlgItem(hDlg, chx2), SW_HIDE ); 01369 return(TRUE); 01370 } 01371 MessageBox( hDlg, 01372 "Hook installed.", 01373 "Information", MB_OK ); 01374 return (TRUE); 01375 01376 case WM_COMMAND: 01377 if (LOWORD(wParam) == IDOK) 01378 { 01379 if (MessageBox( hDlg, "Are you sure you want to print?", 01380 "Information", MB_YESNO ) == IDYES ) 01381 break; 01382 return (TRUE); 01383 01384 } 01385 break; 01386 } 01387 return (FALSE); 01388 01389 // avoid compiler warnings at W3 01390 lParam; 01391 01392 } 01393 01394 01395 /**************************************************************************** 01396 * 01397 * FUNCTION: PrintFile(HWND) 01398 * 01399 * PURPOSE: Invokes common dialog function to print. 01400 * 01401 * COMMENTS: 01402 * 01403 * This function initializes the PRINTDLG structure for all modes 01404 * possible: standard, using a hook or using a customized template. 01405 * When hook mode is chosen, a hook is installed for both the 01406 * Print dialog and the Print Setup dialog. When custom mode is 01407 * chosen, the templates are enabled for both the print dialog and 01408 * the Print Setup dialog boxes. 01409 * 01410 * If the PrintDlg() common dialog returns TRUE, the current 01411 * text buffer is printed out. 01412 * 01413 * 01414 * RETURN VALUES: 01415 * void. 01416 * 01417 ****************************************************************************/ 01418 void PrintFile( HWND hWnd ) 01419 { 01420 01421 01422 // initialize PRINTDLG structure 01423 pd.lStructSize = sizeof(PRINTDLG); 01424 pd.hwndOwner = hWnd; 01425 pd.hDevMode = (HANDLE)NULL; 01426 pd.hDevNames = (HANDLE)NULL; 01427 pd.nFromPage = 0; 01428 pd.nToPage = 0; 01429 pd.nMinPage = 0; 01430 pd.nMaxPage = 0; 01431 pd.nCopies = 0; 01432 pd.hInstance = (HANDLE)hInst; 01433 01434 01435 switch( wMode ) 01436 { 01437 case IDM_STANDARD: 01438 pd.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_NOSELECTION | PD_PRINTSETUP; 01439 pd.lpfnSetupHook = (LPSETUPHOOKPROC)(FARPROC)NULL; 01440 pd.lpSetupTemplateName = (LPSTR)NULL; 01441 pd.lpfnPrintHook = (LPPRINTHOOKPROC)(FARPROC)NULL; 01442 pd.lpPrintTemplateName = (LPSTR)NULL; 01443 break; 01444 01445 case IDM_HOOK: 01446 pd.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_NOSELECTION | 01447 PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK | PD_PRINTSETUP; 01448 pd.lpfnSetupHook = (LPSETUPHOOKPROC)MakeProcInstance(PrintSetupHookProc, NULL); 01449 pd.lpSetupTemplateName = (LPSTR)NULL; 01450 pd.lpfnPrintHook = (LPPRINTHOOKPROC)MakeProcInstance(PrintDlgHookProc, NULL); 01451 pd.lpPrintTemplateName = (LPSTR)NULL; 01452 break; 01453 01454 case IDM_CUSTOM: 01455 pd.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_NOSELECTION | 01456 PD_ENABLEPRINTHOOK | PD_ENABLEPRINTTEMPLATE | 01457 PD_ENABLESETUPHOOK | PD_ENABLESETUPTEMPLATE | PD_PRINTSETUP; 01458 pd.lpfnSetupHook = (LPSETUPHOOKPROC)MakeProcInstance(PrintSetupHookProc, NULL); 01459 pd.lpSetupTemplateName = (LPSTR)MAKEINTRESOURCE(PRNSETUPDLGORD); 01460 pd.lpfnPrintHook = (LPPRINTHOOKPROC)MakeProcInstance(PrintDlgHookProc, NULL); 01461 pd.lpPrintTemplateName = (LPSTR)MAKEINTRESOURCE(PRINTDLGORD); 01462 break; 01463 01464 } 01465 01466 //print a test page if successful 01467 if (PrintDlg(&pd) == TRUE) 01468 { 01469 Escape(pd.hDC, STARTDOC, 8, "Test-Doc", NULL); 01470 01471 //Print text 01472 TextOut(pd.hDC, 5, 5, FileBuf, strlen(FileBuf)); 01473 01474 Escape(pd.hDC, NEWFRAME, 0, NULL, NULL); 01475 Escape(pd.hDC, ENDDOC, 0, NULL, NULL ); 01476 DeleteDC(pd.hDC); 01477 if (pd.hDevMode) 01478 GlobalFree(pd.hDevMode); 01479 if (pd.hDevNames) 01480 GlobalFree(pd.hDevNames); 01481 } 01482 else 01483 ProcessCDError(CommDlgExtendedError(), hWnd ); 01484 } 01485 01486 01487 /**************************************************************************** 01488 * 01489 * FUNCTION: ReplaceTextHookProc(HWND, UINT, WPARAM, LPARAM) 01490 * 01491 * PURPOSE: Processes messages for ReplaceText common dialog box 01492 * 01493 * COMMENTS: 01494 * 01495 * Puts up a message stating that the hook is active if hook 01496 * only active. Otherwise, if template enabled, hides the 01497 * Replace All pushbutton, plus the 'Match case' and 01498 * 'Match whole word' check box options. 01499 * 01500 * RETURN VALUES: 01501 * TRUE - Continue. 01502 * FALSE - Return to the dialog box. 01503 * 01504 ****************************************************************************/ 01505 01506 BOOL CALLBACK ReplaceTextHookProc( 01507 HWND hDlg, /* window handle of the dialog box */ 01508 UINT message, /* type of message */ 01509 WPARAM wParam, /* message-specific information */ 01510 LPARAM lParam) 01511 { 01512 switch (message) 01513 { 01514 case WM_INITDIALOG: 01515 if (frText.Flags & FR_ENABLETEMPLATE ) 01516 { 01517 ShowWindow( GetDlgItem(hDlg, psh2), SW_HIDE ); 01518 ShowWindow( GetDlgItem(hDlg, chx1), SW_HIDE ); 01519 ShowWindow( GetDlgItem(hDlg, chx2), SW_HIDE ); 01520 } 01521 MessageBox( hDlg, 01522 "Hook installed.", 01523 "Information", MB_OK ); 01524 return (TRUE); 01525 01526 01527 default: 01528 break; 01529 } 01530 return (FALSE); 01531 01532 // avoid compiler warnings at W3 01533 lParam; 01534 wParam; 01535 } 01536 01537 /**************************************************************************** 01538 * 01539 * FUNCTION: FindTextHookProc(HWND, UINT, UINT, LONG) 01540 * 01541 * PURPOSE: Processes messages for FindText common dialog box 01542 * 01543 * COMMENTS: 01544 * 01545 * Puts up a message stating that the hook is active if hook 01546 * only enabled. If custom template, hides the 'Match case' 01547 * and 'Match whole word' options, hides the group box 'Direction' 01548 * with the radio buttons 'Up' and 'Down'. 01549 * 01550 * RETURN VALUES: 01551 * TRUE - Continue. 01552 * FALSE - Return to the dialog box. 01553 * 01554 ****************************************************************************/ 01555 01556 BOOL CALLBACK FindTextHookProc( 01557 HWND hDlg, /* window handle of the dialog box */ 01558 UINT message, /* type of message */ 01559 WPARAM wParam, /* message-specific information */ 01560 LPARAM lParam) 01561 { 01562 01563 switch (message) 01564 { 01565 case WM_INITDIALOG: 01566 if (frText.Flags & FR_ENABLETEMPLATE ) 01567 { 01568 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE); 01569 ShowWindow(GetDlgItem(hDlg, grp1), SW_HIDE); 01570 ShowWindow(GetDlgItem(hDlg, chx2), SW_HIDE); 01571 ShowWindow(GetDlgItem(hDlg, rad1), SW_HIDE); 01572 ShowWindow(GetDlgItem(hDlg, rad2), SW_HIDE); 01573 } 01574 MessageBox( hDlg, 01575 "Hook installed.", 01576 "Information", MB_OK ); 01577 return (TRUE); 01578 01579 01580 default: 01581 break; 01582 } 01583 return (FALSE); 01584 01585 // avoid compiler warnings at W3 01586 lParam; 01587 wParam; 01588 } 01589 01590 01591 /**************************************************************************** 01592 * 01593 * FUNCTION: CallFindText( HWND ) 01594 * 01595 * PURPOSE: Initializes and calls the FindText() 01596 * common dialog. 01597 * 01598 * COMMENTS: 01599 * 01600 * This function initialzes the FINDREPLACE structure for any mode: 01601 * standard, using a hook or using a customized template. It then 01602 * calls the FindText() common dialog function. 01603 * 01604 * RETURN VALUES: 01605 * void. 01606 * 01607 ****************************************************************************/ 01608 void CallFindText( HWND hWnd ) 01609 { 01610 01611 frText.lStructSize = sizeof( frText ); 01612 frText.hwndOwner = hWnd; 01613 frText.hInstance = (HANDLE)hInst; 01614 frText.lpstrFindWhat = szFindString; 01615 frText.lpstrReplaceWith = (LPSTR)NULL; 01616 frText.wFindWhatLen = sizeof(szFindString); 01617 frText.wReplaceWithLen = 0; 01618 frText.lCustData = 0; 01619 lpBufPtr = FileBuf; 01620 01621 switch( wMode ) 01622 { 01623 case IDM_STANDARD: 01624 frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD; 01625 frText.lpfnHook = (LPFRHOOKPROC)(FARPROC)NULL; 01626 frText.lpTemplateName = (LPSTR)NULL; 01627 break; 01628 01629 case IDM_HOOK: 01630 frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD | 01631 FR_ENABLEHOOK; 01632 frText.lpfnHook = (LPFRHOOKPROC)MakeProcInstance(FindTextHookProc, NULL); 01633 frText.lpTemplateName = (LPSTR)NULL; 01634 break; 01635 01636 case IDM_CUSTOM: 01637 frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD | 01638 FR_ENABLEHOOK | FR_ENABLETEMPLATE; 01639 frText.lpfnHook = (LPFRHOOKPROC)MakeProcInstance(FindTextHookProc, NULL); 01640 frText.lpTemplateName = (LPSTR)MAKEINTRESOURCE(FINDDLGORD); 01641 break; 01642 } 01643 01644 if ((hDlgFR = FindText(&frText)) == NULL) 01645 ProcessCDError(CommDlgExtendedError(), hWnd ); 01646 01647 } 01648 01649 01650 /**************************************************************************** 01651 * 01652 * FUNCTION: CallReplaceText( HWND ) 01653 * 01654 * PURPOSE: Initializes and calls the ReplaceText() 01655 * common dialog. 01656 * 01657 * COMMENTS: 01658 * 01659 * This function initialzes the FINDREPLACE structure for any mode: 01660 * standard, using a hook or using a customized template. It then 01661 * calls the ReplaceText() common dialog function. 01662 * 01663 * RETURN VALUES: 01664 * void. 01665 * 01666 ****************************************************************************/ 01667 void CallReplaceText( HWND hWnd ) 01668 { 01669 frText.lStructSize = sizeof( frText ); 01670 frText.hwndOwner = hWnd; 01671 frText.hInstance = (HANDLE)hInst; 01672 frText.lpstrFindWhat = szFindString; 01673 frText.lpstrReplaceWith = szReplaceString; 01674 frText.wFindWhatLen = sizeof(szFindString); 01675 frText.wReplaceWithLen = sizeof( szReplaceString ); 01676 frText.lCustData = 0; 01677 lpBufPtr = FileBuf; 01678 01679 switch( wMode ) 01680 { 01681 case IDM_STANDARD: 01682 frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD; 01683 frText.lpfnHook = (LPFRHOOKPROC)(FARPROC)NULL; 01684 frText.lpTemplateName = (LPSTR)NULL; 01685 break; 01686 01687 case IDM_HOOK: 01688 frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD | 01689 FR_ENABLEHOOK; 01690 frText.lpfnHook = (LPFRHOOKPROC)MakeProcInstance(ReplaceTextHookProc, NULL); 01691 frText.lpTemplateName = (LPSTR)NULL; 01692 break; 01693 01694 case IDM_CUSTOM: 01695 frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD | 01696 FR_ENABLEHOOK | FR_ENABLETEMPLATE; 01697 frText.lpfnHook = (LPFRHOOKPROC)MakeProcInstance(ReplaceTextHookProc, NULL); 01698 frText.lpTemplateName = (LPSTR)MAKEINTRESOURCE(REPLACEDLGORD); 01699 break; 01700 } 01701 01702 if ( (hDlgFR = ReplaceText( &frText )) == NULL ) 01703 ProcessCDError(CommDlgExtendedError(), hWnd ); 01704 01705 } 01706 01707 /**************************************************************************** 01708 * 01709 * FUNCTION: SearchFile(LPFINDREPLACE) 01710 * 01711 * PURPOSE: Does the find/replace specified by the Find/ReplaceText 01712 * common dialog. 01713 * 01714 * COMMENTS: 01715 * 01716 * This function does the lease necessary to implement find and 01717 * replace by calling existing c-runtime functions. It is in 01718 * no way intended to demonstrate either correct or efficient 01719 * methods for doing textual search or replacement. 01720 * 01721 * RETURN VALUES: 01722 * void. 01723 * 01724 ****************************************************************************/ 01725 void SearchFile( LPFINDREPLACE lpFR ) 01726 { 01727 01728 CHAR Buf[FILE_LEN]; 01729 CHAR *pStr; 01730 int count, newcount; 01731 static BOOL bFoundLast = FALSE; 01732 01733 if ( lpFR->Flags & ( FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL ) ) 01734 { 01735 memset(Buf, '\0', FILE_LEN -1); 01736 if ( bFoundLast ) 01737 { 01738 if ( (lpBufPtr != FileBuf) && (lpFR->Flags & FR_FINDNEXT) ) 01739 lpBufPtr++; 01740 bFoundLast = FALSE; 01741 } 01742 01743 if (!*lpBufPtr || !(pStr = strstr( lpBufPtr, lpFR->lpstrFindWhat ) ) ) 01744 { 01745 sprintf( Buf, "'%s' not found!", lpFR->lpstrFindWhat ); 01746 lpBufPtr = FileBuf; 01747 MessageBox( lpFR->hwndOwner, Buf, "No luck", MB_OK | MB_TASKMODAL); 01748 } 01749 else 01750 { 01751 if ( lpFR->Flags & FR_FINDNEXT ) 01752 { 01753 sprintf( Buf, "Found Next '%s'!\nSubstring: '%.10s'", 01754 lpFR->lpstrFindWhat, pStr ); 01755 lpBufPtr = pStr; 01756 bFoundLast = TRUE; 01757 MessageBox( lpFR->hwndOwner, Buf, "Success!", MB_OK | MB_TASKMODAL ); 01758 } 01759 else if ( lpFR->Flags & FR_REPLACE ) 01760 { 01761 // replace string specified in the replace with found string 01762 // copy up to found string into new buffer 01763 for( count=0; 01764 *pStr && lpBufPtr[count] && *pStr != lpBufPtr[count]; 01765 count++); 01766 strncpy( Buf, lpBufPtr, count ); 01767 // concatenate new string 01768 strcat( Buf, lpFR->lpstrReplaceWith ); 01769 // copy rest of string (less the found string) 01770 newcount = count + strlen(lpFR->lpstrFindWhat); 01771 strcat( Buf, lpBufPtr+newcount); 01772 strcpy( lpBufPtr, Buf ); 01773 lpBufPtr += count + strlen(lpFR->lpstrReplaceWith); 01774 dwFileSize = strlen(FileBuf); 01775 MessageBox( lpFR->hwndOwner, FileBuf, "Success!", MB_OK | MB_TASKMODAL ); 01776 } 01777 else if ( lpFR->Flags & FR_REPLACEALL) 01778 { 01779 do 01780 { 01781 // replace string specified in the replace with found string 01782 // copy up to found string into new buffer 01783 memset(Buf, '\0', FILE_LEN -1); 01784 for( count=0; 01785 *pStr && lpBufPtr[count] && *pStr != lpBufPtr[count]; 01786 count++); 01787 strncpy( Buf, lpBufPtr, count ); 01788 // concatenate new string 01789 strcat( Buf, lpFR->lpstrReplaceWith ); 01790 // copy rest of string (less the found string) 01791 newcount = count + strlen(lpFR->lpstrFindWhat); 01792 strcat( Buf, lpBufPtr + newcount); 01793 strcpy( lpBufPtr, Buf ); 01794 lpBufPtr += count + strlen(lpFR->lpstrReplaceWith); 01795 } 01796 while ( *lpBufPtr && 01797 (pStr = strstr( lpBufPtr, lpFR->lpstrFindWhat ) ) ); 01798 dwFileSize = strlen(FileBuf); 01799 lpBufPtr = FileBuf; 01800 MessageBox( lpFR->hwndOwner, FileBuf, 01801 "Success!", MB_OK | MB_TASKMODAL ); 01802 } 01803 01804 } 01805 } 01806 } 01807 01808 01809 /**************************************************************************** 01810 * 01811 * FUNCTION: ProcessCDError(DWORD) 01812 * 01813 * PURPOSE: Processes errors from the common dialog functions. 01814 * 01815 * COMMENTS: 01816 * 01817 * This function is called whenever a common dialog function 01818 * fails. The CommonDialogExtendedError() value is passed to 01819 * the function which maps the error value to a string table. 01820 * The string is loaded and displayed for the user. 01821 * 01822 * RETURN VALUES: 01823 * void. 01824 * 01825 ****************************************************************************/ 01826 void ProcessCDError(DWORD dwErrorCode, HWND hWnd) 01827 { 01828 WORD wStringID; 01829 CHAR buf[256]; 01830 01831 switch(dwErrorCode) 01832 { 01833 case CDERR_DIALOGFAILURE: wStringID=IDS_DIALOGFAILURE; break; 01834 case CDERR_STRUCTSIZE: wStringID=IDS_STRUCTSIZE; break; 01835 case CDERR_INITIALIZATION: wStringID=IDS_INITIALIZATION; break; 01836 case CDERR_NOTEMPLATE: wStringID=IDS_NOTEMPLATE; break; 01837 case CDERR_NOHINSTANCE: wStringID=IDS_NOHINSTANCE; break; 01838 case CDERR_LOADSTRFAILURE: wStringID=IDS_LOADSTRFAILURE; break; 01839 case CDERR_FINDRESFAILURE: wStringID=IDS_FINDRESFAILURE; break; 01840 case CDERR_LOADRESFAILURE: wStringID=IDS_LOADRESFAILURE; break; 01841 case CDERR_LOCKRESFAILURE: wStringID=IDS_LOCKRESFAILURE; break; 01842 case CDERR_MEMALLOCFAILURE: wStringID=IDS_MEMALLOCFAILURE; break; 01843 case CDERR_MEMLOCKFAILURE: wStringID=IDS_MEMLOCKFAILURE; break; 01844 case CDERR_NOHOOK: wStringID=IDS_NOHOOK; break; 01845 case PDERR_SETUPFAILURE: wStringID=IDS_SETUPFAILURE; break; 01846 case PDERR_PARSEFAILURE: wStringID=IDS_PARSEFAILURE; break; 01847 case PDERR_RETDEFFAILURE: wStringID=IDS_RETDEFFAILURE; break; 01848 case PDERR_LOADDRVFAILURE: wStringID=IDS_LOADDRVFAILURE; break; 01849 case PDERR_GETDEVMODEFAIL: wStringID=IDS_GETDEVMODEFAIL; break; 01850 case PDERR_INITFAILURE: wStringID=IDS_INITFAILURE; break; 01851 case PDERR_NODEVICES: wStringID=IDS_NODEVICES; break; 01852 case PDERR_NODEFAULTPRN: wStringID=IDS_NODEFAULTPRN; break; 01853 case PDERR_DNDMMISMATCH: wStringID=IDS_DNDMMISMATCH; break; 01854 case PDERR_CREATEICFAILURE: wStringID=IDS_CREATEICFAILURE; break; 01855 case PDERR_PRINTERNOTFOUND: wStringID=IDS_PRINTERNOTFOUND; break; 01856 case CFERR_NOFONTS: wStringID=IDS_NOFONTS; break; 01857 case FNERR_SUBCLASSFAILURE: wStringID=IDS_SUBCLASSFAILURE; break; 01858 case FNERR_INVALIDFILENAME: wStringID=IDS_INVALIDFILENAME; break; 01859 case FNERR_BUFFERTOOSMALL: wStringID=IDS_BUFFERTOOSMALL; break; 01860 01861 case 0: //User may have hit CANCEL or we got a *very* random error 01862 return; 01863 01864 default: 01865 wStringID=IDS_UNKNOWNERROR; 01866 } 01867 01868 LoadString(NULL, wStringID, buf, sizeof(buf)); 01869 MessageBox(hWnd, buf, NULL, MB_OK); 01870 return; 01871 } 01872 01873 /***********************************************************************/ 01874 01875 BOOL WINAPI OpenFiles( 01876 HWND hDlg, /* window handle of the dialog box */ 01877 UINT message, /* type of message */ 01878 WPARAM wParam, /* message-specific information */ 01879 LPARAM lParam) 01880 { 01881 int Length; 01882 char DevProfileName[FILE_LEN]; 01883 char TargetProfileName[FILE_LEN]; 01884 char OutputFileName[FILE_LEN]; 01885 WORD InpClrSp; 01886 01887 switch (message) 01888 { 01889 case WM_INITDIALOG: /* message: initialize dialog box */ 01890 return (TRUE); 01891 01892 case WM_COMMAND: /* message: received a command */ 01893 switch (LOWORD(wParam)) 01894 { 01895 case IDC_BUTTON1: 01896 if ( OpenNewFile( hWnd ) == TRUE ) 01897 SendDlgItemMessage(hDlg, IDC_EDIT1, WM_SETTEXT, 0, (long)(OpenFileName.lpstrFile)); 01898 break; 01899 case IDC_BUTTON2: 01900 if ( OpenNewFile( hWnd ) == TRUE ) 01901 SendDlgItemMessage(hDlg, IDC_EDIT2, WM_SETTEXT, 0, (long)(OpenFileName.lpstrFile)); 01902 break; 01903 case IDC_BUTTON3: 01904 if ( SaveAs( hWnd ) == TRUE ) 01905 SendDlgItemMessage(hDlg, IDC_EDIT3, WM_SETTEXT, 0, (long)(OpenFileName.lpstrFile)); 01906 break; 01907 case IDOK: 01908 Length = SendDlgItemMessage(hDlg, IDC_EDIT1, WM_GETTEXTLENGTH, 0, 0); 01909 SendDlgItemMessage(hDlg, IDC_EDIT1, WM_GETTEXT, Length + 1, (long)(DevProfileName)); 01910 Length = SendDlgItemMessage(hDlg, IDC_EDIT2, WM_GETTEXTLENGTH, 0, 0); 01911 SendDlgItemMessage(hDlg, IDC_EDIT2, WM_GETTEXT, Length + 1, (long)(TargetProfileName)); 01912 Length = SendDlgItemMessage(hDlg, IDC_EDIT3, WM_GETTEXTLENGTH, 0, 0); 01913 SendDlgItemMessage(hDlg, IDC_EDIT3, WM_GETTEXT, Length + 1, (long)(OutputFileName)); 01914 switch (wInpDrvClrSp) 01915 { 01916 case IDM_INP_AUTO: InpClrSp = 0; break; 01917 case IDM_INP_GRAY: InpClrSp = 1; break; 01918 case IDM_INP_RGB: InpClrSp = 3; break; 01919 case IDM_INP_CMYK: InpClrSp = 4; break; 01920 default: InpClrSp = 0; break; 01921 } 01922 if (wCSAorCRD == IDM_CSA) 01923 { 01924 ColorSpaceControl(DevProfileName, OutputFileName, 01925 InpClrSp, Intent, wCSAMode, AllowBinary); 01926 } 01927 else if (wCSAorCRD == IDM_CRD) 01928 { 01929 CreateCRDControl(DevProfileName, OutputFileName, 01930 Intent, AllowBinary); 01931 } 01932 else if (wCSAorCRD == IDM_PROFCRD) 01933 { 01934 CreateProfCRDControl(DevProfileName, 01935 TargetProfileName, OutputFileName, 01936 Intent, AllowBinary); 01937 } 01938 else 01939 { 01940 CreateINTENTControl(DevProfileName, OutputFileName, Intent); 01941 } 01942 01943 case IDCANCEL: 01944 EndDialog(hDlg, TRUE); /* Exits the dialog box */ 01945 return (TRUE); 01946 } 01947 break; 01948 } 01949 return (FALSE); /* Didn't process a message */ 01950 01951 // avoid compiler warnings at W3 01952 lParam; 01953 }

Generated on Sat May 15 19:40:41 2004 for test by doxygen 1.3.7