OptionsKeyBoard.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // OptionsKeyBoard.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CP_Main.h"
  5. #include "OptionsKeyBoard.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // COptionsKeyBoard property page
  13. IMPLEMENT_DYNCREATE(COptionsKeyBoard, CPropertyPage)
  14. COptionsKeyBoard::COptionsKeyBoard() : CPropertyPage(COptionsKeyBoard::IDD)
  15. {
  16. //{{AFX_DATA_INIT(COptionsKeyBoard)
  17. // NOTE: the ClassWizard will add member initialization here
  18. //}}AFX_DATA_INIT
  19. }
  20. COptionsKeyBoard::~COptionsKeyBoard()
  21. {
  22. }
  23. void COptionsKeyBoard::DoDataExchange(CDataExchange* pDX)
  24. {
  25. CPropertyPage::DoDataExchange(pDX);
  26. //{{AFX_DATA_MAP(COptionsKeyBoard)
  27. DDX_Control(pDX, IDC_NAMED_COPY, m_NamedCopy);
  28. DDX_Control(pDX, IDC_HOTKEY, m_HotKey);
  29. //}}AFX_DATA_MAP
  30. }
  31. BEGIN_MESSAGE_MAP(COptionsKeyBoard, CPropertyPage)
  32. //{{AFX_MSG_MAP(COptionsKeyBoard)
  33. //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35. /////////////////////////////////////////////////////////////////////////////
  36. // COptionsKeyBoard message handlers
  37. BOOL COptionsKeyBoard::OnInitDialog()
  38. {
  39. CPropertyPage::OnInitDialog();
  40. m_pParent = (COptionsSheet *)GetParent();
  41. DWORD wHotKey = CGetSetOptions::GetHotKey();
  42. m_HotKey.SetHotKey(LOBYTE(wHotKey),HIBYTE(wHotKey));
  43. //Unregister the hotkey
  44. //Re regester it on cancel or ok
  45. UnregisterHotKey(theApp.m_MainhWnd, theApp.m_atomHotKey);
  46. wHotKey = CGetSetOptions::GetNamedCopyHotKey();
  47. m_NamedCopy.SetHotKey(LOBYTE(wHotKey),HIBYTE(wHotKey));
  48. //Unregister the hotkey
  49. //Re regester it on cancel or ok
  50. UnregisterHotKey(theApp.m_MainhWnd, theApp.m_atomNamedCopy);
  51. m_HotKey.SetFocus();
  52. return FALSE;
  53. }
  54. LRESULT COptionsKeyBoard::OnWizardNext()
  55. {
  56. return CPropertyPage::OnWizardNext();
  57. }
  58. BOOL COptionsKeyBoard::OnWizardFinish()
  59. {
  60. return CPropertyPage::OnWizardFinish();
  61. }
  62. BOOL COptionsKeyBoard::OnApply()
  63. {
  64. DWORD wHotKey = m_HotKey.GetHotKey();
  65. DWORD wNamedCopy = m_NamedCopy.GetHotKey();
  66. if((wHotKey == wNamedCopy) && (wHotKey != 0))
  67. {
  68. MessageBox("Activate Hot Key and Named Copy Hot Key cannot be the same.");
  69. return FALSE;
  70. }
  71. CGetSetOptions::SetNamedCopyHotKey(wNamedCopy);
  72. CGetSetOptions::SetHotKey(wHotKey);
  73. if(wHotKey > 0)
  74. {
  75. if(!CGetSetOptions::RegisterHotKey(theApp.m_MainhWnd, wHotKey, theApp.m_atomHotKey))
  76. {
  77. MessageBox("Error Registering HotKey to Activate Ditto");
  78. return FALSE;
  79. }
  80. }
  81. if(wNamedCopy > 0)
  82. {
  83. if(!CGetSetOptions::RegisterHotKey(theApp.m_MainhWnd, wNamedCopy, theApp.m_atomNamedCopy))
  84. {
  85. MessageBox("Error Registering HotKey for Named Copy");
  86. return FALSE;
  87. }
  88. }
  89. return CPropertyPage::OnApply();
  90. }
  91. BOOL COptionsKeyBoard::ValidateHotKey(WORD wHotKey)
  92. {
  93. ATOM id = GlobalAddAtom("HK_VALIDATE");
  94. BOOL bResult = CGetSetOptions::RegisterHotKey(theApp.m_MainhWnd, wHotKey, FALSE);
  95. if(bResult)
  96. UnregisterHotKey(GetSafeHwnd(), id);
  97. GlobalDeleteAtom(id);
  98. return bResult;
  99. }
  100. void COptionsKeyBoard::OnCancel()
  101. {
  102. if(CGetSetOptions::GetHotKey())
  103. {
  104. if(!CGetSetOptions::RegisterHotKey(theApp.m_MainhWnd,
  105. CGetSetOptions::GetHotKey(),
  106. theApp.m_atomHotKey))
  107. {
  108. MessageBox("Error Registering HotKey to Activate Ditto");
  109. return;
  110. }
  111. }
  112. if(CGetSetOptions::GetNamedCopyHotKey())
  113. {
  114. if(!CGetSetOptions::RegisterHotKey(theApp.m_MainhWnd,
  115. CGetSetOptions::GetNamedCopyHotKey(),
  116. theApp.m_atomNamedCopy))
  117. {
  118. MessageBox("Error Registering HotKey for Named Copy");
  119. return;
  120. }
  121. }
  122. CPropertyPage::OnCancel();
  123. }