home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / MFC / SRC / APPHELP.CP_ / APPHELP.CP
Encoding:
Text File  |  1993-02-08  |  3.7 KB  |  137 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992 Microsoft Corporation 
  3. // All rights reserved. 
  4. //  
  5. // This source code is only intended as a supplement to the 
  6. // Microsoft Foundation Classes Reference and Microsoft 
  7. // QuickHelp and/or WinHelp documentation provided with the library. 
  8. // See these sources for detailed information regarding the 
  9. // Microsoft Foundation Classes product. 
  10.  
  11. #include "stdafx.h"
  12.  
  13. #ifdef AFX_CORE3_SEG
  14. #pragma code_seg(AFX_CORE3_SEG)
  15. #endif
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char BASED_CODE THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. // Help and other support
  24.  
  25. // Strings in format ".....%1 .... %2 ...." etc.
  26.  
  27. void AFXAPI AfxFormatStrings(CString& rString, UINT nIDS, 
  28.         LPCSTR* rglpsz, int nString)
  29. {
  30.     char szFormat[256];
  31.     if (!_AfxLoadString(nIDS, szFormat) != 0)
  32.     {
  33.         TRACE1("Error: failed to load AfxFormatString string 0x%04x\n", nIDS);
  34.         ASSERT(FALSE);
  35.         return;
  36.     }
  37.     AfxFormatStrings(rString, szFormat, rglpsz, nString);
  38. }
  39.  
  40. void AFXAPI AfxFormatStrings(CString& rString, LPCSTR lpszFormat,
  41.         LPCSTR* rglpsz, int nString)
  42. {
  43.     // NOTE: will not work for strings > 255 characters
  44.  
  45.     int nTotalLen = lstrlen(lpszFormat);
  46.     for (int i = 0; i < nString; i++)
  47.         nTotalLen += lstrlen(rglpsz[i]);
  48.  
  49.     LPCSTR pchSrc = lpszFormat;
  50.     char* pchDest = rString.GetBuffer(nTotalLen+1);
  51.     while (*pchSrc != '\0')
  52.     {
  53.         if (pchSrc[0] == '%' && (pchSrc[1] >= '1' && pchSrc[1] <= '9'))
  54.         {
  55.             int iString = pchSrc[1] - '1';
  56.             pchSrc += 2;
  57.             if (iString >= nString)
  58.             {
  59.                 TRACE1("Error: illegal string index requested %d\n", iString);
  60.                 *pchDest++ = '?';
  61.             }
  62.             else
  63.             {
  64.                 lstrcpy(pchDest, rglpsz[iString]);
  65.                 pchDest += strlen(pchDest);
  66.             }
  67.         }
  68.         else
  69.         {
  70.             *pchDest++ = *pchSrc++;
  71.         }
  72.     }
  73.     rString.ReleaseBuffer((int)((const char*)pchDest - (const char*)rString));
  74.             // Release will assert if we went too far
  75. }
  76.  
  77. void AFXAPI AfxFormatString1(CString& rString, UINT nIDS, LPCSTR lpsz1)
  78. {
  79.     AfxFormatStrings(rString, nIDS, &lpsz1, 1);
  80. }
  81.  
  82. void AFXAPI AfxFormatString2(CString& rString, UINT nIDS, LPCSTR lpsz1, 
  83.         LPCSTR lpsz2)
  84. {
  85.     LPCSTR rglpsz[2];
  86.     rglpsz[0] = lpsz1;
  87.     rglpsz[1] = lpsz2;
  88.     AfxFormatStrings(rString, nIDS, rglpsz, 2);
  89. }
  90.  
  91. /////////////////////////////////////////////////////////////////////////////
  92.  
  93. // WinHelp Helper
  94. void CWinApp::WinHelp(DWORD dwData, UINT nCmd /* = HELP_CONTEXT */)
  95. {
  96.     ASSERT(m_pMainWnd != NULL);
  97.     ASSERT(m_pszHelpFilePath != NULL);
  98.  
  99.     if (m_bHelpMode)
  100.     {
  101.         ASSERT(m_hcurHelp != NULL);
  102.         m_hcurHelp = afxData.hcurArrow;
  103.         ::SetCursor(afxData.hcurArrow);
  104.         MSG msg;
  105.         while (::PeekMessage(&msg, NULL, WM_EXITHELPMODE, WM_EXITHELPMODE,
  106.                 PM_REMOVE|PM_NOYIELD))
  107.             ;
  108.         ::PostAppMessage(::GetCurrentTask(), WM_EXITHELPMODE, 0, 0);
  109.         m_bHelpMode = FALSE;
  110.     }
  111.  
  112.     // cancel any tracking modes
  113.     m_pMainWnd->SendMessage(WM_CANCELMODE);
  114.     m_pMainWnd->SendMessageToDescendants(WM_CANCELMODE, 0, 0, TRUE);
  115.  
  116.     // attempt to cancel capture
  117.     HWND hWndCapture = ::GetCapture();
  118.     if (hWndCapture != NULL)
  119.         ::SendMessage(hWndCapture, WM_CANCELMODE, 0, 0);
  120.  
  121.     // need to use top level parent (for the case where m_pMainWnd is in DLL)
  122.     HWND hWnd = m_pMainWnd->m_hWnd;
  123.     HWND hWndT;
  124.     while ((hWndT = ::GetParent(hWnd)) != NULL)
  125.         hWnd = hWndT;
  126.  
  127.     TRACE2("calling WinHelp, dwData: $%lx, fuCommand: %d\n", dwData, nCmd);
  128.  
  129.     // finally, run the Windows Help engine
  130.     BeginWaitCursor();
  131.     if (!::WinHelp(hWnd, m_pszHelpFilePath, nCmd, dwData))
  132.         AfxMessageBox(AFX_IDP_FAILED_TO_LAUNCH_HELP);
  133.     EndWaitCursor();
  134. }
  135.  
  136. /////////////////////////////////////////////////////////////////////////////
  137.