Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

234 lines
6.0 KiB

  1. #include <windows.h>
  2. #include <windowsx.h>
  3. #include "resource.h"
  4. char g_szCurrentDir[MAX_PATH];
  5. char *g_szLicenseText;
  6. //---------------------------------------------------------------------------
  7. BOOL _PathRemoveFileSpec(LPSTR pFile)
  8. {
  9. LPSTR pT;
  10. LPSTR pT2 = pFile;
  11. for (pT = pT2; *pT2; pT2 = CharNext(pT2)) {
  12. if (*pT2 == '\\')
  13. pT = pT2; // last "\" found, (we will strip here)
  14. else if (*pT2 == ':') { // skip ":\" so we don't
  15. if (pT2[1] =='\\') // strip the "\" from "C:\"
  16. pT2++;
  17. pT = pT2 + 1;
  18. }
  19. }
  20. if (*pT == 0)
  21. return FALSE; // didn't strip anything
  22. //
  23. // handle the \foo case
  24. //
  25. else if ((pT == pFile) && (*pT == '\\')) {
  26. // Is it just a '\'?
  27. if (*(pT+1) != '\0') {
  28. // Nope.
  29. *(pT+1) = '\0';
  30. return TRUE; // stripped something
  31. }
  32. else {
  33. // Yep.
  34. return FALSE;
  35. }
  36. }
  37. else {
  38. *pT = 0;
  39. return TRUE; // stripped something
  40. }
  41. }
  42. //---------------------------------------------------------------------------
  43. // L O A D R E A D M E
  44. //
  45. // ISK3
  46. // This will load the readme data file
  47. //
  48. //---------------------------------------------------------------------------
  49. void LoadReadme( char *szLicenseText)
  50. {
  51. CHAR szLicensePath[MAX_PATH];
  52. const CHAR szLicenseFile[] = "\\license.txt";
  53. BOOL retval = FALSE;
  54. HANDLE hLicense;
  55. INT filesize;
  56. DWORD cbRead;
  57. lstrcpy( szLicensePath, g_szCurrentDir );
  58. lstrcat( szLicensePath, "\\Moreinfo.txt" );
  59. if (GetFileAttributes(szLicensePath) != (DWORD) -1)
  60. {
  61. // Open the file
  62. hLicense = CreateFile(szLicensePath, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  63. if (hLicense != INVALID_HANDLE_VALUE)
  64. {
  65. // Get size and allocate buffer
  66. filesize = GetFileSize(hLicense, NULL);
  67. // Read File
  68. if (ReadFile( hLicense, szLicenseText, filesize, &cbRead, NULL))
  69. {
  70. // NULL terminate it
  71. szLicenseText[ filesize ] = '\0';
  72. }
  73. }
  74. CloseHandle( hLicense );
  75. }
  76. }
  77. void ReadmeCenterWindow( HWND hwnd )
  78. {
  79. int screenx;
  80. int screeny;
  81. int height, width, x, y;
  82. RECT rect;
  83. screenx = GetSystemMetrics( SM_CXSCREEN );
  84. screeny = GetSystemMetrics( SM_CYSCREEN );
  85. GetWindowRect( hwnd, &rect );
  86. width = rect.right - rect.left;
  87. height = rect.bottom - rect.top;
  88. x = (screenx / 2) - (width / 2);
  89. y = (screeny / 2) - (height / 2);
  90. SetWindowPos( hwnd, HWND_TOP, x, y, width, height, SWP_NOZORDER );
  91. }
  92. void InitSysFont(HWND hDlg, int iCtrlID)
  93. {
  94. static HFONT hfontSys;
  95. LOGFONT lf;
  96. HDC hDC;
  97. HWND hwndCtrl = GetDlgItem(hDlg, iCtrlID);
  98. HFONT hFont;
  99. int cyLogPixels;
  100. hDC = GetDC(NULL);
  101. if (hDC == NULL)
  102. return;
  103. cyLogPixels = GetDeviceCaps(hDC, LOGPIXELSY);
  104. ReleaseDC(NULL, hDC);
  105. if (hfontSys == NULL) {
  106. LOGFONT lfTemp;
  107. HFONT hfontDef = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
  108. GetObject(hfontDef, sizeof(lfTemp), &lfTemp);
  109. hFont = GetWindowFont(hwndCtrl);
  110. if (hFont != NULL)
  111. if (GetObject(hFont, sizeof(LOGFONT), (PVOID)&lf)) {
  112. lstrcpy(lf.lfFaceName, lfTemp.lfFaceName);
  113. lf.lfQuality = lfTemp.lfQuality;
  114. lf.lfPitchAndFamily = lfTemp.lfPitchAndFamily;
  115. lf.lfCharSet = lfTemp.lfCharSet;
  116. hfontSys = CreateFontIndirect(&lf);
  117. }
  118. }
  119. if (iCtrlID == 0xFFFF)
  120. return;
  121. if (hfontSys != NULL)
  122. SetWindowFont(hwndCtrl, hfontSys, FALSE);
  123. }
  124. INT_PTR CALLBACK ReadmeProc( HWND hDlg, UINT msg, WPARAM wparam, LPARAM lparam )
  125. {
  126. switch( msg )
  127. {
  128. case WM_INITDIALOG:
  129. InitSysFont(hDlg, IDC_README);
  130. ReadmeCenterWindow( hDlg );
  131. SetDlgItemText( hDlg, IDC_README, g_szLicenseText );
  132. return(0);
  133. case WM_COMMAND:
  134. if( wparam == IDOK )
  135. EndDialog( hDlg, 0 );
  136. break;
  137. if( wparam == IDC_README )
  138. return(0);
  139. break;
  140. case WM_CLOSE:
  141. EndDialog( hDlg, 0 );
  142. break;
  143. }
  144. return(0);
  145. }
  146. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow )
  147. {
  148. char *szLicenseText = (char *) LocalAlloc( LPTR, 64000 );
  149. g_szLicenseText = szLicenseText;
  150. GetModuleFileName( NULL, g_szCurrentDir, MAX_PATH );
  151. _PathRemoveFileSpec( g_szCurrentDir );
  152. LoadReadme( szLicenseText );
  153. DialogBox( hInstance, MAKEINTRESOURCE( IDD_README ), NULL, ReadmeProc );
  154. LocalFree( szLicenseText );
  155. szLicenseText = NULL;
  156. return(0);
  157. }
  158. int _stdcall ModuleEntry(void)
  159. {
  160. int i;
  161. STARTUPINFO si;
  162. LPSTR pszCmdLine = GetCommandLine();
  163. if ( *pszCmdLine == '\"' ) {
  164. /*
  165. * Scan, and skip over, subsequent characters until
  166. * another double-quote or a null is encountered.
  167. */
  168. while ( *++pszCmdLine && (*pszCmdLine != '\"') )
  169. ;
  170. /*
  171. * If we stopped on a double-quote (usual case), skip
  172. * over it.
  173. */
  174. if ( *pszCmdLine == '\"' )
  175. pszCmdLine++;
  176. }
  177. else {
  178. while (*pszCmdLine > ' ')
  179. pszCmdLine++;
  180. }
  181. /*
  182. * Skip past any white space preceeding the second token.
  183. */
  184. while (*pszCmdLine && (*pszCmdLine <= ' ')) {
  185. pszCmdLine++;
  186. }
  187. si.dwFlags = 0;
  188. GetStartupInfoA(&si);
  189. i = WinMain(GetModuleHandle(NULL), NULL, pszCmdLine,
  190. si.dwFlags & STARTF_USESHOWWINDOW ? si.wShowWindow : SW_SHOWDEFAULT);
  191. ExitProcess(i);
  192. return i; // We never comes here.
  193. }