GfxProperty.cpp
上传用户:wujian85
上传日期:2010-04-08
资源大小:227k
文件大小:12k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // GfxProperty.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "printformeditor.h"
  5. #include "GfxProperty.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CGfxProperty dialog
  13. static HHOOK hk_hHookProc = NULL;
  14. static CGfxProperty * pOneAndOnlyProperty = NULL;
  15. bool   bLockingProperty = false;
  16. LRESULT CALLBACK KillFocusHookProc(int nCode, WPARAM wParam, LPARAM lParam)
  17. {
  18. if (pOneAndOnlyProperty)
  19. {
  20. CWPRETSTRUCT * pRet = (CWPRETSTRUCT *) lParam;
  21. /* if (pRet->message == WM_KEYDOWN)
  22. {
  23. if ((int) pRet->wParam == VK_RETURN) pOneAndOnlyProperty->DoIt();
  24. }
  25. else if (pRet->message == WM_KEYUP)
  26. {
  27. if ((int) pRet->wParam == VK_RETURN) pOneAndOnlyProperty->DoIt();
  28. }
  29. else if (pRet->message == WM_CHAR)
  30. {
  31. if ((int) pRet->wParam == VK_RETURN) pOneAndOnlyProperty->DoIt();
  32. }
  33. else */
  34. if (!bLockingProperty && pRet->message == WM_SETFOCUS)
  35. {
  36. HWND pFocusing = (HWND) pRet->wParam;
  37. if (pFocusing == pOneAndOnlyProperty->GetSafeHwnd() || ::IsChild(pOneAndOnlyProperty->GetSafeHwnd(), pFocusing))
  38. {
  39. if (!(pRet->hwnd == pOneAndOnlyProperty->GetSafeHwnd() || ::IsChild(pOneAndOnlyProperty->GetSafeHwnd(), pRet->hwnd)))
  40. {
  41. if (pOneAndOnlyProperty->wndPin.bCheckStatus == false)
  42. {
  43. pOneAndOnlyProperty->DestroyWindow();
  44. ASSERT(pOneAndOnlyProperty == NULL);
  45. }
  46. }
  47. }
  48. }
  49. }
  50. return CallNextHookEx(hk_hHookProc, nCode, wParam, lParam);
  51. }
  52. void CGfxProperty::InstallHook(BOOL bInstall)
  53. {
  54. if(bInstall && hk_hHookProc == NULL)
  55. {
  56. hk_hHookProc = ::SetWindowsHookEx(WH_CALLWNDPROCRET, (HOOKPROC) KillFocusHookProc, NULL, ::GetCurrentThreadId()); 
  57. }
  58. else if(!bInstall && hk_hHookProc != NULL)
  59. {
  60. ::UnhookWindowsHookEx(hk_hHookProc);
  61. hk_hHookProc = NULL;
  62. }
  63. }
  64. CGfxProperty::CGfxProperty(CWnd* pParent /*=NULL*/)
  65. : CDialog(CGfxProperty::IDD, pParent)
  66. {
  67. //{{AFX_DATA_INIT(CGfxProperty)
  68. // NOTE: the ClassWizard will add member initialization here
  69. //}}AFX_DATA_INIT
  70. COLORREF cr = RGB(192,192,192);
  71. wndPin.SetBitmap(IDB_PROPPIN1, &cr);
  72. wndPin.SetBitmap(IDB_PROPPIN2, &cr, true);
  73. wndPin.SetBitmapCheckPress(IDB_PROPPIN3, &cr);
  74. wndPin.EnableCheckMode();
  75. wndHelp.SetBitmap(IDB_PROPHELP, &cr);
  76. iActSel = -1;
  77. pTabRect = NULL;
  78. pDocument = NULL;
  79. pWnd = NULL;
  80. }
  81. CGfxProperty::~CGfxProperty()
  82. {
  83. ASSERT(hk_hHookProc == NULL);
  84. ASSERT(pOneAndOnlyProperty == NULL);
  85. if (hk_hHookProc) InstallHook(false);
  86. pOneAndOnlyProperty = NULL;
  87. if (pTabRect) GlobalFree((HGLOBAL) pTabRect);
  88. pTabRect = NULL;
  89. csTabArray.RemoveAll();
  90. pPages.RemoveAll();
  91. }
  92. void CGfxProperty::DoDataExchange(CDataExchange* pDX)
  93. {
  94. CDialog::DoDataExchange(pDX);
  95. //{{AFX_DATA_MAP(CGfxProperty)
  96. DDX_Control(pDX, IDOK, wndOk);
  97. DDX_Control(pDX, IDC_BT_PIN, wndPin);
  98. DDX_Control(pDX, IDC_BT_HELP, wndHelp);
  99. //}}AFX_DATA_MAP
  100. }
  101. BEGIN_MESSAGE_MAP(CGfxProperty, CDialog)
  102. //{{AFX_MSG_MAP(CGfxProperty)
  103. ON_WM_KILLFOCUS()
  104. ON_BN_CLICKED(IDC_BT_HELP, OnBtHelp)
  105. ON_BN_CLICKED(IDC_BT_PIN, OnBtPin)
  106. ON_WM_LBUTTONDOWN()
  107. ON_WM_PAINT()
  108. ON_WM_DESTROY()
  109. ON_WM_CLOSE()
  110. ON_WM_SHOWWINDOW()
  111. //}}AFX_MSG_MAP
  112. END_MESSAGE_MAP()
  113. /////////////////////////////////////////////////////////////////////////////
  114. // CGfxProperty message handlers
  115. void CGfxProperty::OnCancel() 
  116. {
  117. // TODO: Add extra cleanup here
  118. CDialog::OnCancel();
  119. }
  120. void CGfxProperty::OnOK() 
  121. {
  122. for (int t = 0; t < pPages.GetSize(); t++)
  123. {
  124. CDialog * d = (CDialog *) pPages.GetAt(t);
  125. d->UpdateData();
  126. }
  127. if (pOneAndOnlyProperty->wndPin.bCheckStatus == false)
  128. CDialog::OnOK();
  129. }
  130. void CGfxProperty::DoIt()
  131. {
  132. for (int t = 0; t < pPages.GetSize(); t++)
  133. {
  134. CDialog * d = (CDialog *) pPages.GetAt(t);
  135. d->UpdateData();
  136. }
  137. // OnOK();
  138. }
  139. BOOL CGfxProperty::OnInitDialog() 
  140. {
  141. CDialog::OnInitDialog();
  142. ASSERT(pOneAndOnlyProperty == NULL);
  143. pOneAndOnlyProperty = this;
  144. // TODO: Add extra initialization here
  145. return TRUE;  // return TRUE unless you set the focus to a control
  146.               // EXCEPTION: OCX Property Pages should return FALSE
  147. }
  148. void CGfxProperty::OnKillFocus(CWnd* pNewWnd) 
  149. {
  150. CDialog::OnKillFocus(pNewWnd);
  151. }
  152. void CGfxProperty::InvalidateTab(const int idx)
  153. {
  154. if (idx >= 0 && idx < csTabArray.GetSize())
  155. {
  156. InvalidateRect(pTabRect[idx], false);
  157. }
  158. }
  159. void CGfxProperty::OnBtHelp() 
  160. {
  161. // CString path = csAppDir;
  162. CString path("WAtsProp.hlp");
  163. DWORD base = 10;
  164. int nline = 8;
  165. nline = 2;
  166. base = 60;
  167. CString toWin = path;
  168. toWin += ">subtopic";
  169. ::WinHelp(GetSafeHwnd(), (const char *) toWin, HELP_CONTEXT, base);
  170. HANDLE hhwi;
  171. LPHELPWININFO lphwi;
  172. WORD wSize;
  173. char *szWndName = "subtopic";
  174. wSize = sizeof(HELPWININFO) + lstrlen(szWndName);
  175. hhwi = GlobalAlloc(GHND, wSize);
  176. lphwi = (LPHELPWININFO)GlobalLock(hhwi);
  177. lphwi->wStructSize = wSize;
  178. lphwi->x           = 654;
  179. lphwi->y           = 10;;
  180. lphwi->dx          = 364;
  181. lphwi->dy          = nline*26+80;
  182. lphwi->wMax        = SW_SHOW;
  183. lstrcpy(lphwi->rgchMember, szWndName);
  184. ::WinHelp(GetSafeHwnd(), (const char *) path, HELP_SETWINPOS, (DWORD) lphwi);
  185. GlobalUnlock(hhwi);
  186. GlobalFree(hhwi);
  187. }
  188. void CGfxProperty::OnBtPin() 
  189. {
  190. // TODO: Add your control notification handler code here
  191. }
  192. void CGfxProperty::OnLButtonDown(UINT nFlags, CPoint point) 
  193. {
  194. for (int t = 0; t < csTabArray.GetSize(); t++)
  195. if (pTabRect[t].PtInRect(point))
  196. SetCurSel(t);
  197. break;
  198. }
  199. }
  200. CDialog::OnLButtonDown(nFlags, point);
  201. }
  202. void CGfxProperty::OnPaint() 
  203. {
  204. CPaintDC dc(this);
  205. CRect irc;
  206. GetClientRect(&irc);
  207. irc.InflateRect(-5,-5);
  208. irc.top += (CG_TAB_HEIGHT-2);
  209. dc.Draw3dRect(&irc, GetSysColor(COLOR_3DLIGHT), GetSysColor(COLOR_3DSHADOW));
  210. irc.InflateRect(-1, -1);
  211. dc.Draw3dRect(&irc, GetSysColor(COLOR_3DHILIGHT), RGB(0,0,0));
  212. irc.InflateRect(-1, -1);
  213. CFont *ofn = dc.SelectObject(CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT)));
  214. int obk = dc.SetBkMode(TRANSPARENT);
  215. if (pTabRect)
  216. {
  217. for (int t = 0; t < csTabArray.GetSize(); t++)
  218. if (t != iActSel)
  219. DrawTabRect(&dc, &pTabRect[t], false);
  220. dc.TextOut(pTabRect[t].left+7,pTabRect[t].top+3, csTabArray.GetAt(t));
  221. }
  222. }
  223. for (t = 0; t < csTabArray.GetSize(); t++)
  224. if (t == iActSel)
  225. DrawTabRect(&dc, &pTabRect[t], true);
  226. dc.TextOut(pTabRect[t].left+6,pTabRect[t].top+3, csTabArray.GetAt(t));
  227. }
  228. }
  229. }
  230. else
  231. {
  232. static char cNoProp[] = "Nessuna propriet