Source code of Windows XP (NT5)
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.

181 lines
5.8 KiB

  1. #include <windows.h>
  2. #include "clipbrd.h"
  3. /*--------------------------------------------------------------------------*/
  4. /* */
  5. /* SetCharDimensions() - */
  6. /* */
  7. /*--------------------------------------------------------------------------*/
  8. void SetCharDimensions(
  9. HWND hWnd,
  10. HFONT hFont)
  11. {
  12. register HDC hdc;
  13. TEXTMETRIC tm;
  14. hdc = GetDC(hWnd);
  15. SelectObject(hdc, hFont);
  16. GetTextMetrics(hdc, (LPTEXTMETRIC)&tm);
  17. ReleaseDC(hWnd, hdc);
  18. cxChar = tm.tmAveCharWidth;
  19. cxMaxCharWidth = tm.tmMaxCharWidth;
  20. cyLine = tm.tmHeight + tm.tmExternalLeading;
  21. cxMargin = cxChar / 2;
  22. cyMargin = cyLine / 4;
  23. }
  24. /*--------------------------------------------------------------------------*/
  25. /* */
  26. /* ClipbrdInit() - */
  27. /* */
  28. /*--------------------------------------------------------------------------*/
  29. BOOL NEAR PASCAL ClipbrdInit()
  30. {
  31. WNDCLASS class;
  32. if (!(hAccel = LoadAccelerators(hInst, (LPTSTR)MAKEINTRESOURCE(CBACCEL))))
  33. return(FALSE);
  34. hbrBackground = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
  35. class.hCursor = LoadCursor(NULL, IDC_ARROW);
  36. class.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(CBICON));
  37. class.lpszClassName = szAppName;
  38. class.hbrBackground = (HBRUSH)NULL;
  39. class.style = CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNCLIENT;
  40. class.lpszMenuName = (LPTSTR)MAKEINTRESOURCE(CBMENU);
  41. class.hInstance = hInst;
  42. class.lpfnWndProc = ClipbrdWndProc;
  43. class.cbClsExtra = 0;
  44. class.cbWndExtra = 0;
  45. return(RegisterClass((LPWNDCLASS)&class));
  46. }
  47. /*--------------------------------------------------------------------------*/
  48. /* */
  49. /* WinMain() - */
  50. /* */
  51. /*--------------------------------------------------------------------------*/
  52. int WINAPI WinMain(
  53. HINSTANCE hInstance,
  54. HINSTANCE hPrevInstance,
  55. LPSTR lpszCmdLine,
  56. int cmdShow)
  57. {
  58. MSG msg;
  59. HWND hwndPrev;
  60. typedef VOID (FAR PASCAL *LPVFNWB)(WORD, BOOL);
  61. LPVFNWB lpfnRegisterPenApp = NULL;
  62. LOGFONT UniFont;
  63. hInst = hInstance;
  64. // If there's a previous instance, activate its window and blow.
  65. if (hwndPrev = FindWindow(szAppName, NULL))
  66. {
  67. ShowWindow(hwndPrev, SW_RESTORE);
  68. SetForegroundWindow(hwndPrev);
  69. return(0);
  70. }
  71. else
  72. {
  73. LoadString(hInst, IDS_NAME, szCaptionName, sizeof(szCaptionName));
  74. LoadString(hInst, IDS_HELPFILE, (LPTSTR)szHelpFileName, sizeof(szHelpFileName));
  75. /* load caption strings for new File/Open and File/saveAs dialogs */
  76. LoadString(hInst, IDS_OPENCAPTION, (LPTSTR)szOpenCaption, CAPTIONMAX);
  77. LoadString(hInst, IDS_SAVECAPTION, (LPTSTR)szSaveCaption, CAPTIONMAX);
  78. /* Load default extension */
  79. LoadString(hInst, IDS_DEFEXTENSION, (LPTSTR)szDefExt, CCH_szDefExt);
  80. /* Load custom resources for CommDlg filters */
  81. /* a-mgates 9/24/92 */
  82. LoadString(hInst, IDS_FILTERTEXT, szFilterSpec, FILTERMAX);
  83. /* To prevent LoadString failure on low memory situations. */
  84. LoadString(hInst, IDS_MEMERROR,(LPTSTR)szMemErr,MSGMAX);
  85. if (!ClipbrdInit())
  86. {
  87. return FALSE;
  88. }
  89. hwndMain = CreateWindow(szAppName,
  90. szCaptionName,
  91. WS_TILEDWINDOW | WS_VSCROLL | WS_HSCROLL,
  92. CW_USEDEFAULT, 0,
  93. GetSystemMetrics(SM_CXSCREEN) / 2, GetSystemMetrics(SM_CYSCREEN) / 2,
  94. (HWND)NULL,
  95. (HMENU)NULL,
  96. hInstance, (LPTSTR)NULL);
  97. /* Obtain size of standard chars; compute white border size from this */
  98. hfontSys = GetStockObject(SYSTEM_FONT);
  99. hfontOem = GetStockObject(OEM_FIXED_FONT);
  100. GetObject(hfontSys, sizeof(LOGFONT), &UniFont);
  101. UniFont.lfCharSet = ANSI_CHARSET;
  102. lstrcpy(UniFont.lfFaceName, TEXT("Lucida Sans Unicode"));
  103. hfontUni = CreateFontIndirect(&UniFont);
  104. if (hfontUni == NULL)
  105. hfontUni = (HFONT)hfontSys;
  106. /* Get the character dimensions for the default font */
  107. SetCharDimensions(hwndMain, hfontSys);
  108. /* Attach us to the clipboard viewer chain */
  109. hwndNextViewer = SetClipboardViewer(hwndMain);
  110. /* init. some fields of the OPENFILENAME struct used by fileopen and
  111. * filesaveas
  112. */
  113. OFN.lStructSize = sizeof(OPENFILENAME);
  114. OFN.hwndOwner = hwndMain;
  115. OFN.lpstrFileTitle = 0;
  116. OFN.nMaxCustFilter = FILTERMAX;
  117. OFN.nFilterIndex = 1;
  118. OFN.nMaxFile = PATHMAX;
  119. OFN.lpfnHook = NULL;
  120. OFN.Flags = 0L;/* for now, since there's no readonly support */
  121. /* determine the message number to be used for communication with
  122. * help application
  123. */
  124. if (!(wHlpMsg = RegisterWindowMessage ((LPTSTR)HELPMSGSTRING)))
  125. return FALSE;
  126. ShowWindow(hwndMain, cmdShow);
  127. if (lpfnRegisterPenApp = (LPVFNWB)
  128. GetProcAddress((HANDLE)GetSystemMetrics(SM_PENWINDOWS),
  129. "RegisterPenApp")) /* Anas May 92 should I? */
  130. {
  131. (*lpfnRegisterPenApp)(1, TRUE);
  132. }
  133. while (GetMessage(&msg, NULL, 0, 0))
  134. {
  135. if (TranslateAccelerator(hwndMain, hAccel, (LPMSG)&msg) == 0)
  136. {
  137. TranslateMessage(&msg);
  138. DispatchMessage(&msg);
  139. }
  140. }
  141. if (lpfnRegisterPenApp)
  142. (*lpfnRegisterPenApp)(1, FALSE);
  143. return(msg.wParam);
  144. }
  145. UNREFERENCED_PARAMETER(hPrevInstance);
  146. UNREFERENCED_PARAMETER(lpszCmdLine);
  147. }