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.

131 lines
3.4 KiB

  1. #include "pch.h"
  2. #pragma pack(push, 2)
  3. typedef struct tagDLGTEMPLATEEX {
  4. WORD dlgVer;
  5. WORD signature;
  6. DWORD helpID;
  7. DWORD exStyle;
  8. DWORD style;
  9. WORD cDlgItems;
  10. short x;
  11. short y;
  12. short cx;
  13. short cy;
  14. } DLGTEMPLATEEX, *PDLGTEMPLATEEX;
  15. typedef const DLGTEMPLATEEX* PCDLGTEMPLATEEX;
  16. #pragma pack(pop)
  17. BOOL loadDialogTemplate (HINSTANCE hinstDlg, UINT nID, PVOID *ppvDT, PDWORD pcbDT);
  18. HRESULT PrepareDlgTemplate(HINSTANCE hInst, UINT nDlgID, DWORD dwStyle, PVOID *ppvDT)
  19. {
  20. PCDLGTEMPLATEEX pdt2;
  21. LPCDLGTEMPLATE pdt; // for some weird reason there is no PCDLGTEMPLATE
  22. PVOID pvDlg;
  23. HRESULT hr;
  24. DWORD cbDlg;
  25. BOOL fResult;
  26. //----- Initialization and parameter validation -----
  27. if (hInst == NULL || nDlgID == 0)
  28. return E_INVALIDARG;
  29. if (ppvDT == NULL)
  30. return E_POINTER;
  31. *ppvDT = NULL;
  32. //----- Resource allocation -----
  33. fResult = loadDialogTemplate(hInst, nDlgID, &pvDlg, &cbDlg);
  34. if (!fResult)
  35. return E_FAIL;
  36. *ppvDT = CoTaskMemAlloc(cbDlg);
  37. if (*ppvDT == NULL)
  38. return E_OUTOFMEMORY;
  39. ZeroMemory(*ppvDT, cbDlg);
  40. CopyMemory(*ppvDT, pvDlg, cbDlg);
  41. hr = S_OK;
  42. //----- Parse through Dialog Template -----
  43. UINT nStyleOffset;
  44. pdt = NULL;
  45. pdt2 = (PCDLGTEMPLATEEX)pvDlg; // assume extended style
  46. if (pdt2->signature == 0xFFFF) {
  47. if (pdt2->dlgVer != 1)
  48. return E_UNEXPECTED; // Chicago sanity check
  49. nStyleOffset = (UINT) ((PBYTE)&pdt2->style - (PBYTE)pdt2);
  50. }
  51. else {
  52. pdt = (LPCDLGTEMPLATE)pvDlg;
  53. pdt2 = NULL;
  54. nStyleOffset = (UINT) ((PBYTE)&pdt->style - (PBYTE)pdt);
  55. }
  56. // let party on it now, style is DWORD
  57. // BUGBUG: (andrewgu) the code below regarding to styles was figured out by experement. if you
  58. // can't understand it just believe in it and pray that it works. the idea is to preserve
  59. // extended style bits from the old style if new style doesn't have any. on the other hand, if
  60. // the new style has extended bits in it, i assume the caller knows what he's doing and i let
  61. // it through.
  62. PDWORD pdwOldStyle;
  63. DWORD dwNewStyle;
  64. pdwOldStyle = (PDWORD)((PBYTE)*ppvDT + nStyleOffset);
  65. dwNewStyle = dwStyle;
  66. if (dwNewStyle == 0)
  67. dwNewStyle = WS_CHILD | DS_CONTROL;
  68. if ((dwNewStyle & 0x0000FFFF) == 0)
  69. dwNewStyle |= *pdwOldStyle & 0x0000FFFF;
  70. *pdwOldStyle = dwNewStyle;
  71. return hr;
  72. }
  73. /////////////////////////////////////////////////////////////////////////////
  74. // Implementation helpers routines (private)
  75. BOOL loadDialogTemplate(HINSTANCE hinstDlg, UINT nID, PVOID *ppvDT, PDWORD pcbDT)
  76. {
  77. PVOID p;
  78. HANDLE h;
  79. if (hinstDlg == NULL)
  80. return FALSE;
  81. if (ppvDT == NULL)
  82. return FALSE;
  83. *ppvDT = NULL;
  84. if (pcbDT == NULL)
  85. return FALSE;
  86. *pcbDT = 0;
  87. h = FindResource(hinstDlg, MAKEINTRESOURCE(nID), RT_DIALOG);
  88. if (h == NULL)
  89. return FALSE;
  90. *pcbDT = SizeofResource(hinstDlg, (HRSRC)h);
  91. if (*pcbDT == 0)
  92. return FALSE;
  93. h = LoadResource(hinstDlg, (HRSRC)h);
  94. if (h == NULL)
  95. return FALSE;
  96. p = LockResource(h);
  97. if (p == NULL)
  98. return FALSE;
  99. *ppvDT = p;
  100. return TRUE;
  101. }