upgrddlg.c
Upload User: caisha3
Upload Date: 2013-09-21
Package Size: 208739k
Code Size: 7k
Category:

Windows Develop

Development Platform:

Visual C++

  1. /*      File: D:WACKERtdllupgrddlg.c (Created: 02-Dec-1996 by cab)
  2.  *
  3.  *      Copyright 1996 by Hilgraeve Inc. -- Monroe, MI
  4.  *      All rights reserved
  5.  *
  6.  *  Description:
  7.  *      Implements the "Upgrade Information" dialog. This dialog
  8.  *      displays a simple rich text edit control and displays
  9.  *      information on how to upgrade to our latest and greatest
  10.  *      product.
  11.  *
  12.  *      $Revision: 2 $
  13.  *      $Date: 2/05/99 3:21p $
  14.  */
  15. #include <windows.h>
  16. #include <io.h>
  17. #pragma hdrstop
  18. #include <commctrl.h>
  19. #include <termres.h>
  20. #include "mc.h"
  21. #include "globals.h"
  22. #include "features.h"
  23. #include "richedit.h"
  24. #include "shellapi.h"
  25. #include "registry.h"
  26. // Data structure to copy text into rich text edit control.
  27. //
  28. typedef struct esInfo_
  29.     {
  30.     LPTSTR lptstrText;
  31.     LONG lBytesRead;
  32.     } ESINFO;
  33. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  34.  * FUNCTION:
  35.  *      EditStreamCallback
  36.  *
  37.  * DESCRIPTION:
  38.  *  This callback is used to read .rtf text into the rich edit control.
  39.  *  Its a bit complicated to fill a rich edit control.  The callback
  40.  *  mechanism for this control really was designed to work with file
  41.  *  I/O but is generic enough for reading from any source.  The difficultly
  42.  *  arises in that the callback may be called multiple times since
  43.  *  the data being read may be much larger than the buffer allocated in
  44.  *  pbBuff.  Thus, you have to keep a running count of how may bytes have
  45.  *  been copied from your source buffer so that subsequent calls know
  46.  *  where in the buffer to continue from.  Stick UNICODE into the
  47.  *  equation and you have yourself a nice little puzzle.  Note, you have
  48.  *  to think in bytes here since this is what the rich edit control
  49.  *  thinks in.  That's why the ESINFO structure is used. - mrw
  50.  *
  51.  */
  52. DWORD CALLBACK EditStreamCallback(DWORD_PTR dwCookie, LPBYTE pbBuff,
  53.     LONG cb, LONG *pcb)
  54.     {
  55.     int iLen;
  56.     ESINFO *pstInfo = (ESINFO *)dwCookie;
  57.     BYTE *pbText = (BYTE *)pstInfo->lptstrText + pstInfo->lBytesRead;
  58.     iLen = lstrlen(pbText) + 1;     // get len in chars (DBCS returns bytes)
  59.     iLen *= sizeof(TCHAR);          // adjust for UNICODE
  60.     *pcb = min(cb, iLen);           // decide how much to copy
  61.     MemCopy(pbBuff, pbText, *pcb);   // copy specified amount into buffer
  62.     pstInfo->lBytesRead += *pcb;    // record how far we got.
  63.     return (cb >= iLen) ? 0 : *pcb; // return bytes read or zero when done.
  64.     }
  65. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  66.  * FUNCTION:
  67.  *      UpgradeDlgProc
  68.  *
  69.  * DESCRIPTION:
  70.  *  Dialog procedure that displays a rich edit control and an OK button.
  71.  *
  72.  */
  73. INT_PTR CALLBACK UpgradeDlgProc(HWND hDlg, UINT uMsg, WPARAM wPar, LPARAM lPar)
  74.     {
  75.     #define IDC_RICHED 100
  76.     int    i;
  77.     TCHAR  ach[257*2];
  78.     static HANDLE hResource;
  79.     static LPTSTR pachUpgrade;
  80.     static EDITSTREAM es;
  81.     static ESINFO esInfo;
  82.     TCHAR  achUseRTF[80];
  83.     BOOL   bUseRTF = TRUE;
  84.     switch (uMsg)
  85. {
  86.     case WM_INITDIALOG:
  87.         if (LoadString (glblQueryDllHinst(),
  88.                         IDS_USE_RTF,
  89.                         achUseRTF,
  90.                         sizeof(achUseRTF)))
  91.             {
  92.             // If IDS_USE_RTF changed to anything else by localizer, we
  93.             //  assume upgrade text is already localized.
  94.             if (0 != strcmp(achUseRTF, "True"))
  95.                 bUseRTF = FALSE;
  96.             }
  97.         if (!bUseRTF) {
  98.             if ((pachUpgrade = malloc(257*2*50 * sizeof(TCHAR))) == 0)
  99.                 break;
  100.             pachUpgrade[0] = TEXT('');
  101.             for (i = IDS_UPGRADE ; i < IDS_UPGRADE + 50 ; ++i)
  102.                 {
  103.                 if (LoadString(glblQueryDllHinst(), i, ach, sizeof(ach)) == 0)
  104.                     break;
  105.                 strcat(pachUpgrade, ach);
  106.                 }
  107.         } else {
  108.             // Upgrade text is a private resource.
  109.             //
  110.             hResource = LoadResource(glblQueryDllHinst(),
  111.                 FindResource(glblQueryDllHinst(),
  112.                 MAKEINTRESOURCE(IDR_UPGRADE_TEXT), "TEXT"));
  113.             pachUpgrade = LockResource(hResource);
  114.         }
  115. // Build a small structure that we'll give to the a callback
  116. // that fills the rich edit control.
  117. //
  118. esInfo.lptstrText = pachUpgrade;
  119. esInfo.lBytesRead = 0;
  120. // Setup the EDITSTREAM structure.
  121. //
  122. es.dwCookie = (DWORD_PTR)&esInfo;
  123. es.dwError = 0;
  124. es.pfnCallback = EditStreamCallback;
  125. // This message does not return until the control has
  126. // read all the text which makes it possible to release
  127. // the resource immediately after this call.
  128. //
  129.         if (!bUseRTF) {
  130.             SetDlgItemText(hDlg, IDC_RICHED, pachUpgrade);
  131.             free(pachUpgrade);
  132.             pachUpgrade = NULL;
  133.         } else {
  134.             SendDlgItemMessage(hDlg, IDC_RICHED, EM_STREAMIN, SF_RTF,
  135.                 (LPARAM)&es);
  136.             // Kill the resource.
  137.             //
  138.             UnlockResource(hResource);
  139.             FreeResource(hResource);
  140.         }
  141.         break;
  142.     case WM_COMMAND:
  143. switch (wPar)
  144.     {
  145. case IDOK:
  146. case IDCANCEL:
  147.     EndDialog(hDlg, TRUE);
  148.     break;
  149. default:
  150.     break;
  151.     }
  152. break;
  153.     default:
  154. return FALSE;
  155. }
  156.     return TRUE;
  157.     }
  158. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  159.  * FUNCTION:
  160.  *      DoUpgradeDialog
  161.  *
  162.  * DESCRIPTION:
  163.  *  Displays a modal "Upgrade Information" dialog box.
  164.  *
  165.  * ARGUMENTS:
  166.  *  hwndParent - Handle of the parent window.
  167.  *
  168.  * AUTHOR:  C. Baumgartner, 12/02/96
  169.  *          M. Thompson, 07/15/97 Attempt to launch htm file first
  170.  */
  171. INT_PTR DoUpgradeDialog(HWND hwndParent)
  172.     {
  173.     //check to see if we should launch browser with htm or do the rtf thing - mpt 07/15/97
  174. INT_PTR result;
  175.     CHAR acRegistryData[MAX_PATH * 2];
  176. CHAR acExePath[MAX_PATH];
  177. CHAR acHTMFile[MAX_PATH];
  178.     DWORD dwSize = sizeof(acRegistryData);
  179. BOOL bLaunchBrowser = FALSE;
  180. CHAR achHTMRegKey[] = TEXT(".htm");
  181. LPTSTR pszPtr;
  182. struct _finddata_t c_file;
  183. long hFile;
  184.     //get .htm file type
  185. if ( regQueryValue(HKEY_CLASSES_ROOT, achHTMRegKey,
  186. TEXT(""), acRegistryData, &dwSize) == 0 )
  187. bLaunchBrowser = TRUE;
  188. if ( bLaunchBrowser )
  189. {
  190. // Get the path name of HyperTerminal and build path to HTM file
  191. //
  192. acExePath[0] = TEXT('');
  193. result = GetModuleFileName(glblQueryHinst(), acExePath, MAX_PATH);
  194. //strip off executable
  195. if (result != 0)
  196. {
  197. pszPtr = strrchr(acExePath, TEXT('\'));
  198. *pszPtr = TEXT('');
  199. }
  200. //build path to htm
  201. acHTMFile[0] = TEXT('');
  202. strcat(acHTMFile, acExePath);
  203. strcat(acHTMFile, TEXT("\"));
  204. strcat(acHTMFile, TEXT("readme.htm"));
  205. //check if file exists
  206. hFile = (long)_findfirst( acHTMFile, &c_file );
  207. if ( hFile != -1 )
  208. {
  209. //tell shell to start the htm file, since we are at this point
  210. //we know there is a registry association for htm files, whether it works
  211. //or not is beyond our control.
  212. ShellExecute(NULL, "open", acHTMFile, NULL, NULL, SW_SHOW);
  213. return 0;
  214. }
  215. }
  216. result = DialogBox(glblQueryDllHinst(), MAKEINTRESOURCE(IDD_UPGRADE_INFO), hwndParent, UpgradeDlgProc);
  217. return result;
  218.     }