CTitleOverlayProp.cpp
上传用户:hhs829
上传日期:2022-06-17
资源大小:586k
文件大小:10k
源码类别:

DirextX编程

开发平台:

Visual C++

  1. //
  2. // CTitleOverlayProp.cpp
  3. //
  4. #include <streams.h>
  5. // Eliminate two expected level 4 warnings from the Microsoft compiler.
  6. // The class does not have an assignment or copy operator, and so cannot
  7. // be passed by value.  This is normal.  This file compiles clean at the
  8. // highest (most picky) warning level (-W4).
  9. #pragma warning(disable: 4511 4512)
  10. #include <windowsx.h>
  11. #include <commctrl.h>
  12. #include <olectl.h>
  13. #include <memory.h>
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <tchar.h>
  17. #include "Resource.h"            // ids used in the dialog
  18. #include "CTitleOverlayProp.h"    // our own class
  19. #include "OverlayDefs.h"
  20. //
  21. // CreateInstance
  22. //
  23. // Override CClassFactory method.
  24. // Set lpUnk to point to an IUnknown interface on a new NullIPProperties object
  25. // Part of the COM object instantiation mechanism
  26. //
  27. CUnknown * WINAPI CTitleOverlayProp::CreateInstance(LPUNKNOWN lpunk, HRESULT *phr)
  28. {
  29. CUnknown *punk = new CTitleOverlayProp(lpunk, phr);
  30. if (punk == NULL) 
  31. {
  32. *phr = E_OUTOFMEMORY;
  33. }
  34. return punk;
  35. }
  36. // Constructs and initialises a object
  37. CTitleOverlayProp::CTitleOverlayProp(LPUNKNOWN pUnk, HRESULT *phr)
  38.     : CBasePropertyPage(NAME("Title Overlay Property Page"),pUnk,
  39.         IDD_FILTER_PROP, IDS_INFO)
  40. {
  41. ASSERT(phr);
  42. mIOverlay      = NULL;
  43. mIsFontChanged = FALSE;
  44. } // CGraphInfoProp
  45. // Override CBasePropertyPage method.
  46. // Handles the messages for our property window
  47. BOOL CTitleOverlayProp::OnReceiveMessage(HWND hwnd,
  48.                                         UINT uMsg,
  49.                                         WPARAM wParam,
  50.                                         LPARAM lParam)
  51. {
  52.     switch (uMsg)
  53.     {
  54.         case WM_INITDIALOG:
  55.         {
  56. // Get windows' handles
  57. m_hOverlayType    = GetDlgItem(hwnd, IDC_COMBO_OVERLAY_TYPE);
  58. m_hEditTilte      = GetDlgItem(hwnd, IDC_EDIT_TITLE);
  59. m_hEditStartX     = GetDlgItem(hwnd, IDC_EDIT_STARTX);
  60. m_hEditStartY     = GetDlgItem(hwnd, IDC_EDIT_STARTY);
  61. m_hEditStartTime  = GetDlgItem(hwnd, IDC_EDIT_STARTTIME);
  62. m_hEditEndTime    = GetDlgItem(hwnd, IDC_EDIT_ENDTIME);
  63. m_hEditColorR     = GetDlgItem(hwnd, IDC_EDIT_COLORR);
  64. m_hEditColorG     = GetDlgItem(hwnd, IDC_EDIT_COLORG);
  65. m_hEditColorB     = GetDlgItem(hwnd, IDC_EDIT_COLORB);
  66. break;
  67.         }
  68.         case WM_COMMAND:
  69.         {
  70. if (HIWORD(wParam) == BN_CLICKED)
  71. {
  72. switch (LOWORD(wParam))
  73. {
  74. case IDC_BUTTON_CHANGE_FONT:
  75. OnButtonChangeFont();
  76. break;
  77. }
  78. }
  79. SetDirty();
  80.             break;
  81.         }
  82.     }
  83.     return CBasePropertyPage::OnReceiveMessage(hwnd,uMsg,wParam,lParam);
  84. } // OnReceiveMessage
  85. // Override CBasePropertyPage method.
  86. // Notification of which object this property page should display.
  87. // We query the object for the IFltTrace interface.
  88. HRESULT CTitleOverlayProp::OnConnect(IUnknown *pUnknown)
  89. {
  90. HRESULT hr = pUnknown->QueryInterface(IID_ITitleOverlay, (void **) &mIOverlay);
  91. if (FAILED(hr))
  92. {
  93. return E_NOINTERFACE;
  94. }
  95. ASSERT(mIOverlay);
  96. return NOERROR;
  97. } // OnConnect
  98. // Override CBasePropertyPage method.
  99. // Release the private interface, release the upstream pin.
  100. HRESULT CTitleOverlayProp::OnDisconnect()
  101. {
  102. // Release of Interface
  103. if (mIOverlay == NULL)
  104. return E_UNEXPECTED;
  105. mIOverlay->Release();
  106. mIOverlay = NULL;
  107. return NOERROR;
  108. } // OnDisconnect
  109. // We are being activated
  110. HRESULT CTitleOverlayProp::OnActivate()
  111. {
  112. FillOverlayTypeComboBox();
  113. ReflectOverlayType();
  114. ReflectOverlayStyle();
  115. ReflectTitle();
  116. ReflectTitleStartPosition();
  117. ReflectTitleDuration();
  118. ReflectTitleColor();
  119. ReflectTitleFont();
  120. return NOERROR;
  121. } // Activate
  122. // Changes made should be kept
  123. HRESULT CTitleOverlayProp::OnApplyChanges()
  124. {
  125. EnterOverlayType();  // This must be first invoked!!
  126. EnterOverlayStyle();
  127. EnterTitle();
  128. EnterTitleStartPosition();
  129. EnterTitleDuration();
  130. EnterTitleColor();
  131. EnterTitleFont();
  132. return NOERROR;
  133. } // OnApplyChanges
  134. //
  135. // Sets m_hrDirtyFlag and notifies the property page site of the change
  136. void CTitleOverlayProp::SetDirty()
  137. {
  138.     m_bDirty = TRUE;
  139.     if (m_pPageSite)
  140.     {
  141.         m_pPageSite->OnStatusChange(PROPPAGESTATUS_DIRTY);
  142.     }
  143. } // SetDirty
  144. void CTitleOverlayProp::FillOverlayTypeComboBox(void)
  145. {
  146. const char * szType[] = 
  147. {
  148. "None", "Static", "System Time", "Scroll Top", "Scroll Bottom"
  149. };
  150. int enType[] = 
  151. {
  152. OT_NONE, OT_STATIC, OT_SYSTIME, OT_SCROLL_TOP, OT_SCROLL_BOTTOM
  153. };
  154. const int nCount = sizeof(szType) / sizeof(szType[0]);
  155. // Reset the combo box content
  156. SendMessage(m_hOverlayType, CB_RESETCONTENT, 0, 0);
  157. for (int i = 0; i < nCount; i++)
  158. {
  159. SendMessage(m_hOverlayType, CB_ADDSTRING, 0, (LPARAM)szType[i]);
  160. SendMessage(m_hOverlayType, CB_SETITEMDATA, i, (LPARAM)enType[i]);
  161. }
  162. }
  163. int CTitleOverlayProp::GetOverlayTypeComboIndex(int inType)
  164. {
  165. // Set the first item selected
  166. int  nCount = SendMessage(m_hOverlayType, CB_GETCOUNT, 0, 0);
  167. for (int i = 0; i < nCount; i++)
  168. {
  169. int nItemData = (int) SendMessage(m_hOverlayType, CB_GETITEMDATA, i, 0);
  170. if (nItemData == inType)
  171. {
  172. return i;
  173. }
  174. }
  175. return 0;
  176. }
  177. void CTitleOverlayProp::ReflectOverlayType(void)
  178. {
  179. long   overlayType = 0;
  180. mIOverlay->get_TitleOverlayType(&overlayType);
  181. SendMessage(m_hOverlayType, CB_SETCURSEL, GetOverlayTypeComboIndex(overlayType), 0);
  182. }
  183. void CTitleOverlayProp::ReflectOverlayStyle(void)
  184. {
  185. BOOL  usingCover = TRUE;
  186. mIOverlay->get_TitleOverlayStyle(&usingCover);
  187. CheckRadioButton(m_hwnd, IDC_RADIO_BYCOVER, IDC_RADIO_BYREVERSE, 
  188. usingCover ? IDC_RADIO_BYCOVER : IDC_RADIO_BYREVERSE);
  189. }
  190. void CTitleOverlayProp::ReflectTitle(void)
  191. {
  192. int  titleLength = 0;
  193. mIOverlay->get_Title(NULL, &titleLength);
  194. if (titleLength > 0)
  195. {
  196. char * szTitle = new char[titleLength];
  197. mIOverlay->get_Title(szTitle, &titleLength);
  198. SetWindowText(m_hEditTilte, szTitle);
  199. delete[] szTitle;
  200. }
  201. }
  202. void CTitleOverlayProp::ReflectTitleStartPosition(void)
  203. {
  204. POINT   startPos;
  205. mIOverlay->get_TitleStartPosition(&startPos);
  206. char    szPoint[100];
  207. sprintf(szPoint, "%d", startPos.x);
  208. SetWindowText(m_hEditStartX, szPoint);
  209. sprintf(szPoint, "%d", startPos.y);
  210. SetWindowText(m_hEditStartY, szPoint);
  211. }
  212. void CTitleOverlayProp::ReflectTitleDuration(void)
  213. {
  214. double  startTime = 0, endTime = 0; 
  215. mIOverlay->get_TitleDuration(&startTime, &endTime);
  216. char    szDuration[100];
  217. sprintf(szDuration, "%.2f", startTime);
  218. SetWindowText(m_hEditStartTime, szDuration);
  219. sprintf(szDuration, "%.2f", endTime);
  220. SetWindowText(m_hEditEndTime, szDuration);
  221. }
  222. void CTitleOverlayProp::ReflectTitleColor(void)
  223. {
  224. BYTE  colorR, colorG, colorB;
  225. mIOverlay->get_TitleColor(&colorR, &colorG, &colorB);
  226. char  szColor[100];
  227. sprintf(szColor, "%d", colorR);
  228. SetWindowText(m_hEditColorR, szColor);
  229. sprintf(szColor, "%d", colorG);
  230. SetWindowText(m_hEditColorG, szColor);
  231. sprintf(szColor, "%d", colorB);
  232. SetWindowText(m_hEditColorB, szColor);
  233. mTitleColor = RGB(colorR, colorG, colorB);
  234. }
  235. void CTitleOverlayProp::ReflectTitleColor(BYTE inR, BYTE inG, BYTE inB)
  236. {
  237. char  szColor[100];
  238. sprintf(szColor, "%d", inR);
  239. SetWindowText(m_hEditColorR, szColor);
  240. sprintf(szColor, "%d", inG);
  241. SetWindowText(m_hEditColorG, szColor);
  242. sprintf(szColor, "%d", inB);
  243. SetWindowText(m_hEditColorB, szColor);
  244. }
  245. void CTitleOverlayProp::ReflectTitleFont(void)
  246. {
  247. mIOverlay->get_TitleFont(&mTitleFont);
  248. }
  249. void CTitleOverlayProp::EnterOverlayType(void)
  250. {
  251. int nSelected = SendMessage(m_hOverlayType, CB_GETCURSEL, 0, 0);
  252. int nType     = SendMessage(m_hOverlayType, CB_GETITEMDATA, nSelected, 0);
  253. mIOverlay->put_TitleOverlayType(nType);
  254. }
  255. void CTitleOverlayProp::EnterOverlayStyle(void)
  256. {
  257. int  nChecked = IsDlgButtonChecked(m_hwnd, IDC_RADIO_BYCOVER);
  258. mIOverlay->put_TitleOverlayStyle(nChecked);
  259. }
  260. void CTitleOverlayProp::EnterTitle(void)
  261. {
  262. char szTitle[2000];
  263. if (GetWindowText(m_hEditTilte, szTitle, 2000))
  264. {
  265. mIOverlay->put_Title(szTitle, strlen(szTitle));
  266. }
  267. else
  268. {
  269. mIOverlay->put_Title("", 0);
  270. }
  271. }
  272. void CTitleOverlayProp::EnterTitleStartPosition(void)
  273. {
  274. POINT   startPos;
  275. char    szPos[100];
  276. GetWindowText(m_hEditStartX, szPos, 100);
  277. startPos.x = atoi(szPos);
  278. GetWindowText(m_hEditStartY, szPos, 100);
  279. startPos.y = atoi(szPos);
  280. mIOverlay->put_TitleStartPosition(startPos);
  281. }
  282. void CTitleOverlayProp::EnterTitleDuration(void)
  283. {
  284. char    szDuration[100];
  285. GetWindowText(m_hEditStartTime, szDuration, 100);
  286. double startTime = atof(szDuration);
  287. GetWindowText(m_hEditEndTime, szDuration, 100);
  288. double endTime   = atof(szDuration);
  289. mIOverlay->put_TitleDuration(startTime, endTime);
  290. }
  291. void CTitleOverlayProp::EnterTitleColor(void)
  292. {
  293. BYTE  colorR = 0, colorG = 0, colorB = 0;
  294. char  szColor[100];
  295. GetWindowText(m_hEditColorR, szColor, 100);
  296. colorR = atoi(szColor);
  297. GetWindowText(m_hEditColorG, szColor, 100);
  298. colorG = atoi(szColor);
  299. GetWindowText(m_hEditColorB, szColor, 100);
  300. colorB = atoi(szColor);
  301. mIOverlay->put_TitleColor(colorR, colorG, colorB);
  302. }
  303. void CTitleOverlayProp::EnterTitleFont(void)
  304. {
  305. if (mIsFontChanged)
  306. {
  307. mIOverlay->put_TitleFont(mTitleFont);
  308. }
  309. }
  310. void CTitleOverlayProp::OnButtonChangeFont(void)
  311. {
  312. // Update the RGB values
  313. BYTE  colorR = 0, colorG = 0, colorB = 0;
  314. char  szColor[100];
  315. GetWindowText(m_hEditColorR, szColor, 100);
  316. colorR = atoi(szColor);
  317. GetWindowText(m_hEditColorG, szColor, 100);
  318. colorG = atoi(szColor);
  319. GetWindowText(m_hEditColorB, szColor, 100);
  320. colorB = atoi(szColor);
  321. mTitleColor = RGB(colorR, colorG, colorB);
  322. CHOOSEFONT    cf;
  323. // Initialize CHOOSEFONT
  324. ZeroMemory(&cf, sizeof(CHOOSEFONT));
  325. cf.lStructSize = sizeof(CHOOSEFONT);
  326. cf.hInstance   = g_hInst;
  327. cf.hwndOwner   = m_hwnd;
  328. cf.lpLogFont   = &mTitleFont;
  329. cf.rgbColors   = mTitleColor;
  330. cf.Flags       = CF_SCREENFONTS | CF_EFFECTS | CF_INITTOLOGFONTSTRUCT;
  331. if (ChooseFont(&cf)) 
  332. {
  333. mIsFontChanged = TRUE;
  334. // Update the text color
  335. mTitleColor    = cf.rgbColors;
  336. ReflectTitleColor(GetRValue(mTitleColor), GetGValue(mTitleColor), GetBValue(mTitleColor));
  337. }
  338. }