Annotation of ntddk/src/print/pscrptui/help.c, revision 1.1

1.1     ! root        1: /******************************* MODULE HEADER *******************************
        !             2:  * utils.c
        !             3:  *      Functions to interface to the help system.
        !             4:  *
        !             5:  *
        !             6:  *  Copyright (C)  1993   Microsoft Corporation.
        !             7:  *
        !             8:  *****************************************************************************/
        !             9: 
        !            10: #include        <stddef.h>
        !            11: #include        <stdlib.h>
        !            12: #include        <string.h>
        !            13: #include        "pscript.h"
        !            14: #include        "dlgdefs.h"
        !            15: #include        "help.h"
        !            16: #include        "pscrptui.h"
        !            17: 
        !            18: /*
        !            19:  *   Some stuff associated with help.
        !            20:  */
        !            21: 
        !            22: static  WCHAR   wcHelpFNM[] = L"\\pscript.hlp";
        !            23: 
        !            24: static  int   cHelpInit = 0;        /* Only do it once */
        !            25: 
        !            26: static  HHOOK   hhookGetMsg;
        !            27: 
        !            28: /*
        !            29:  *   Local function prototypes.
        !            30:  */
        !            31: 
        !            32: 
        !            33: LRESULT CALLBACK GetMsgProc( int, WPARAM, LPARAM );
        !            34: LPWSTR GetDriverDirectory(HANDLE);
        !            35: 
        !            36: 
        !            37: /************************* Function Header *********************************
        !            38:  * vHelpInit
        !            39:  *      Called to initialise the help operations.  Not much to do, but er
        !            40:  *      do keep track of how many times we are called,  and only do the
        !            41:  *      initialisation once, and hence make sure we free it only once.
        !            42:  *
        !            43:  * RETURNS:
        !            44:  *      Nothing,  failure of help is benign.
        !            45:  *
        !            46:  * HISTORY:
        !            47:  *  13:45 on Wed 24 Feb 1993    -by-    Lindsay Harris   [lindsayh]
        !            48:  *      Starting.
        !            49:  *
        !            50:  ****************************************************************************/
        !            51: 
        !            52: void
        !            53: vHelpInit()
        !            54: {
        !            55: 
        !            56:     /*
        !            57:      *   All we need to do (and only the first time!) is put a hook function
        !            58:      *  onto the message queue so that we can intercept the <F1> key and
        !            59:      *  transform it into a mouse click on the "Help" button.  Then the
        !            60:      *  normal windowing code will display the help contents.
        !            61:      */
        !            62: 
        !            63:     if( cHelpInit == 0 )
        !            64:     {
        !            65:         /*  First time only  */
        !            66: 
        !            67:         hhookGetMsg = SetWindowsHookEx( WH_GETMESSAGE, GetMsgProc, hModule,
        !            68:                                                  GetCurrentThreadId() );
        !            69: 
        !            70:     }
        !            71: 
        !            72:     ++cHelpInit;                /* Only do it once */
        !            73: 
        !            74: 
        !            75:     return;
        !            76: }
        !            77: 
        !            78: 
        !            79: /************************** Function Header *******************************
        !            80:  * vHelpDone
        !            81:  *      Called to discombobulate help.
        !            82:  *
        !            83:  * RETURNS:
        !            84:  *      Nothing.
        !            85:  *
        !            86:  * HISTORY:
        !            87:  *  13:09 on Mon 01 Mar 1993    -by-    Lindsay Harris   [lindsayh]
        !            88:  *      Free help file name when done.
        !            89:  *
        !            90:  *  13:52 on Wed 24 Feb 1993    -by-    Lindsay Harris   [lindsayh]
        !            91:  *      First version.
        !            92:  *
        !            93:  **************************************************************************/
        !            94: 
        !            95: void
        !            96: vHelpDone(hWnd)
        !            97: HWND    hWnd;              /* Required to allow us to clean up nicely */
        !            98: {
        !            99:     --cHelpInit;
        !           100: 
        !           101:     if(cHelpInit == 0)
        !           102:         UnhookWindowsHookEx(hhookGetMsg);
        !           103:     else  if(cHelpInit < 0)
        !           104:         cHelpInit = 0;             /* Should never happen, but.... */
        !           105: 
        !           106:     return;
        !           107: }
        !           108: 
        !           109: /************************** Function Header *******************************
        !           110:  * vShowHelp
        !           111:  *      Front end to the help facility,  basically providing a pop-up if
        !           112:  *      the help file is not available.
        !           113:  *
        !           114:  * RETURNS:
        !           115:  *      Nothing
        !           116:  *
        !           117:  * HISTORY:
        !           118:  *  13:09 on Mon 01 Mar 1993    -by-    Lindsay Harris   [lindsayh]
        !           119:  *      Generate the help file name when needed.
        !           120:  *
        !           121:  *  16:29 on Mon 22 Feb 1993    -by-    Lindsay Harris   [lindsayh]
        !           122:  *      First rasddui incarnation, borrowed from printman (AndrewBe).
        !           123:  *
        !           124:  **************************************************************************/
        !           125: 
        !           126: void
        !           127: vShowHelp( hWnd, iType, dwData, hPrinter)
        !           128: HWND     hWnd;            /* Window of interest */
        !           129: UINT     iType;           /* Type of help, param #3 to WinHelp */
        !           130: DWORD    dwData;          /* Additional data for WinHelp, sometimes optional */
        !           131: HANDLE   hPrinter;
        !           132: {
        !           133:     WCHAR           wcbuf1[32];
        !           134:     WCHAR           wcbuf2[MAX_PATH];
        !           135:     LPWSTR          pDriverDirectory;
        !           136: 
        !           137:     /*
        !           138:      *   Quite easy - simply call the WinHelp function with the parameters
        !           139:      * supplied to us.  If this fails,  then put up a stock dialog box.
        !           140:      *   BUT the first time we figure out what the file name is.  We know
        !           141:      * the actual name,  but we don't know where it is located, so we
        !           142:      * need to call the spooler for that information.
        !           143:      */
        !           144: 
        !           145:     if (!(pDriverDirectory = GetDriverDirectory(hPrinter)))
        !           146:         return;
        !           147: 
        !           148:     wcscpy(wcbuf2, pDriverDirectory);
        !           149:     wcscat(wcbuf2, wcHelpFNM );  /* The name */
        !           150: 
        !           151:     LocalFree(pDriverDirectory);
        !           152: 
        !           153:     if( !WinHelp( hWnd, wcbuf2, iType, dwData ) )
        !           154:     {
        !           155:         /*  Well, help failed,  so at least tell the user!  */
        !           156: 
        !           157:         LoadString(hModule,
        !           158:                    (IDS_NO_HELP + STRING_BASE),
        !           159:                    (LPWSTR)wcbuf2,
        !           160:                    (sizeof(wcbuf2) / sizeof(wcbuf2[0])));
        !           161: 
        !           162:         LoadString(hModule,
        !           163:                    (IDS_ERROR + STRING_BASE),
        !           164:                    (LPWSTR)wcbuf1,
        !           165:                    (sizeof(wcbuf1) / sizeof(wcbuf1[0])));
        !           166: 
        !           167:         MessageBox(hWnd, wcbuf2, wcbuf1, MB_DEFBUTTON2 |
        !           168:                    MB_ICONEXCLAMATION | MB_OK);
        !           169:     }
        !           170: 
        !           171: 
        !           172:     return;
        !           173: }
        !           174: 
        !           175: 
        !           176: /***************************** Function Header ****************************
        !           177:  * GetMsgProc
        !           178:  *      Function to hook F1 key presses and turn them into standard
        !           179:  *      help type messages.
        !           180:  *
        !           181:  * RETURNS:
        !           182:  *      0 for an F1 key press,  else whatever comes back from CallNextHookEx()
        !           183:  *
        !           184:  * HISTORY:
        !           185:  *  13:26 on Wed 24 Feb 1993    -by-    Lindsay Harris   [lindsayh]
        !           186:  *      First incarnation here, following a life in printman.c (AndrewBe)
        !           187:  *
        !           188:  **************************************************************************/
        !           189: 
        !           190: LRESULT CALLBACK
        !           191: GetMsgProc( iCode, wParam, lParam )
        !           192: int      iCode;
        !           193: WPARAM   wParam;
        !           194: LPARAM   lParam;
        !           195: {
        !           196: 
        !           197:     /*
        !           198:      * This is the callback routine which hooks F1 keypresses.
        !           199:      *
        !           200:      * Any such message will be repackaged as a WM_COMMAND/IDD_HELP message
        !           201:      * and sent to the top window, which may be the frame window
        !           202:      * or a dialog box.
        !           203:      *
        !           204:      * See the Win32 API programming reference for a description of how this
        !           205:      * routine works.
        !           206:      *
        !           207:      */
        !           208: 
        !           209:     PMSG pMsg = (PMSG)lParam;
        !           210: 
        !           211:     if( iCode < 0 )
        !           212:         return CallNextHookEx( hhookGetMsg, iCode, wParam, lParam );
        !           213: 
        !           214:     if( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_F1 )
        !           215:     {
        !           216: 
        !           217:         /*   Go looking for the real parent - why?  */
        !           218:         HWND   hwndParent;
        !           219:         BOOL   bRet;
        !           220: 
        !           221: 
        !           222:         hwndParent = pMsg->hwnd;
        !           223: 
        !           224:         while( GetWindowLong( hwndParent, GWL_STYLE ) & WS_CHILD )
        !           225:             hwndParent = (HWND)GetWindowLong( hwndParent, GWL_HWNDPARENT );
        !           226: 
        !           227: 
        !           228:         /*  Our window procs all use the same format for help operations. */
        !           229:         bRet = PostMessage( hwndParent, WM_COMMAND, IDD_HELP_BUTTON, 0L );
        !           230:     }
        !           231: 
        !           232:     return 0;
        !           233: }
        !           234: 
        !           235: 
        !           236: //--------------------------------------------------------------------------
        !           237: // LPWSTR GetDriverDirectory(hPrinter)
        !           238: // HANDLE  hPrinter;
        !           239: //
        !           240: // This function returns the directory for the printer driver defined by
        !           241: // hPrinter.
        !           242: //
        !           243: // History:
        !           244: //   20-May-1993     -by-     Dave Snipp    (davesn)
        !           245: //  Wrote it.
        !           246: //--------------------------------------------------------------------------
        !           247: 
        !           248: LPWSTR GetDriverDirectory(hPrinter)
        !           249: HANDLE  hPrinter;
        !           250: {
        !           251:     PPRINTER_INFO_2 pPrinter2;
        !           252:     DWORD           cb, cb1;
        !           253:     LPWSTR          pDirectory=NULL;
        !           254:     BOOL            EveryThingWorked=FALSE;
        !           255: 
        !           256:     if (!GetPrinter(hPrinter, 2, NULL, 0, &cb) &&
        !           257:         GetLastError() == ERROR_INSUFFICIENT_BUFFER)
        !           258:     {
        !           259:         pPrinter2 = LocalAlloc(LMEM_FIXED, cb);
        !           260: 
        !           261:         if (pPrinter2)
        !           262:         {
        !           263:             if (GetPrinter(hPrinter, 2, (LPBYTE)pPrinter2, cb, &cb))
        !           264:             {
        !           265:                 if (!GetPrinterDriverDirectory(pPrinter2->pServerName, NULL,
        !           266:                                                1, NULL, 0, &cb1) &&
        !           267:                     GetLastError() == ERROR_INSUFFICIENT_BUFFER)
        !           268:                 {
        !           269:                     pDirectory = LocalAlloc(LMEM_FIXED, cb1);
        !           270: 
        !           271:                     if (pDirectory)
        !           272:                     {
        !           273:                         if (!GetPrinterDriverDirectory(pPrinter2->pServerName,
        !           274:                                                        NULL, 1,
        !           275:                                                        (LPBYTE)pDirectory,
        !           276:                                                        cb1, &cb1))
        !           277:                         {
        !           278:                             LocalFree(pDirectory);
        !           279:                             pDirectory = NULL;
        !           280:                         }
        !           281:                     }
        !           282:                 }
        !           283:             }
        !           284: 
        !           285:             LocalFree(pPrinter2);
        !           286:         }
        !           287:     }
        !           288: 
        !           289:     return(pDirectory);
        !           290: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.