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.

136 lines
3.7 KiB

  1. /*****************************************************************************
  2. *
  3. * diqhack.c
  4. *
  5. * Property sheet hacks.
  6. *
  7. * COMMCTRL's property sheet manager assume that all property sheet
  8. * pages use "MS Shell Dlg" as their font. We might not (especially
  9. * in Japan), so we need to touch up our dialog dimensions so that
  10. * when COMMCTRL computes page dimensions, it comes out okay again.
  11. *
  12. *****************************************************************************/
  13. #include "diquick.h"
  14. /*****************************************************************************
  15. *
  16. * Diq_HackPropertySheets
  17. *
  18. * hdlg - a sample dialog box whose font is the one we are actually
  19. * using.
  20. *
  21. *****************************************************************************/
  22. #pragma BEGIN_CONST_DATA
  23. #define EMIT_IDD(idd, fn) idd
  24. UINT c_rgidd[] = {
  25. EACH_PROPSHEET(EMIT_IDD)
  26. };
  27. typedef struct DLGTEMPLATEEX {
  28. WORD wDlgVer;
  29. WORD wSignature;
  30. DWORD dwHelpID;
  31. DWORD dwExStyle;
  32. DWORD style;
  33. WORD cDlgItems;
  34. short x;
  35. short y;
  36. short cx;
  37. short cy;
  38. } DLGTEMPLATEEX, *PDLGTEMPLATEEX;
  39. INT_PTR INTERNAL
  40. Diq_HackPropertySheets(HWND hdlg)
  41. {
  42. LOGFONT lf;
  43. HFONT hfShell, hfDlg, hfOld;
  44. HDC hdc;
  45. TEXTMETRIC tmDlg, tmShell;
  46. BOOL fRc = TRUE;
  47. int idlg;
  48. hdc = GetDC(hdlg);
  49. if( hdc == NULL ) {
  50. return FALSE;
  51. }
  52. /*
  53. * For comparison purposes, we need "MS Shell Dlg" at 8pt.
  54. *
  55. * On Windows NT, "MS Shell Dlg" is a real font.
  56. * On Windows 95, it's a fake font that is special-cased by
  57. * the dialog manager. So first try to create it for real.
  58. * If that fails, then create it for fake.
  59. */
  60. ZeroX(lf);
  61. lf.lfHeight = -MulDiv(8, GetDeviceCaps(hdc, LOGPIXELSY), 72);
  62. lf.lfWeight = FW_NORMAL;
  63. lf.lfCharSet = DEFAULT_CHARSET;
  64. lstrcpy(lf.lfFaceName, TEXT("MS Shell Dlg"));
  65. hfShell = CreateFontIndirect(&lf);
  66. if (hfShell == 0) {
  67. lstrcpy(lf.lfFaceName, TEXT("MS Sans Serif"));
  68. hfShell = CreateFontIndirect(&lf);
  69. if (hfShell == 0) {
  70. fRc = FALSE;
  71. goto done;
  72. }
  73. }
  74. hfDlg = GetWindowFont(hdlg);
  75. if (hfDlg == 0) {
  76. hfDlg = GetStockObject(SYSTEM_FONT);
  77. }
  78. hfOld = SelectFont(hdc, hfDlg);
  79. GetTextMetrics(hdc, &tmDlg);
  80. SelectFont(hdc, hfShell);
  81. GetTextMetrics(hdc, &tmShell);
  82. SelectFont(hdc, hfOld);
  83. DeleteObject(hfShell);
  84. /*
  85. * Now adjust all the property sheet page dimensions so that
  86. * when COMMCTRL tries to adjust them, the two adjustments cancel
  87. * out and everybody is happy.
  88. */
  89. for (idlg = 0; idlg < cA(c_rgidd); idlg++) {
  90. HRSRC hrsrc = FindResource(g_hinst, (PV)(UINT_PTR)c_rgidd[idlg], RT_DIALOG);
  91. if (hrsrc) {
  92. HGLOBAL hglob = LoadResource(g_hinst, hrsrc);
  93. if (hglob) {
  94. LPDLGTEMPLATE ptmp = LockResource(hglob);
  95. if (ptmp) {
  96. short *psi;
  97. DWORD dwScratch;
  98. if (ptmp->style == 0xFFFF0001) {
  99. PDLGTEMPLATEEX pdex = (PV)ptmp;
  100. psi = &pdex->cx;
  101. } else {
  102. psi = &ptmp->cx;
  103. }
  104. VirtualProtect(psi, 2 * sizeof(short),
  105. PAGE_READWRITE, &dwScratch);
  106. psi[0] = (short)MulDiv(psi[0], tmDlg.tmAveCharWidth,
  107. tmShell.tmAveCharWidth);
  108. psi[1] = (short)MulDiv(psi[1], tmDlg.tmHeight,
  109. tmShell.tmHeight);
  110. }
  111. }
  112. }
  113. }
  114. done:;
  115. ReleaseDC(hdlg, hdc);
  116. return fRc;
  117. }