DUCKDOER.CPP
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:3k
源码类别:

Windows编程

开发平台:

Visual C++

  1. // DuckDoer.cpp : Implementation of CDuckDoer
  2. //
  3. // This is a part of the Active Template Library.
  4. // Copyright (C) 1996-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Active Template Library Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Active Template Library product.
  12. #include "stdafx.h"
  13. #include "atlduck.h"
  14. #include "DuckDoer.h"
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CDuckDoer
  17. const IID IID_IDuckInt = {0x120B72AE,0x65BF,0x11D0,{0x9D,0xDC,0x00,0xA0,0xC9,0x03,0x48,0x92}};
  18. // static class members
  19. CDuckDoerDlg* CDuckDoer::m_pDlg = NULL;
  20. STDMETHODIMP CDuckDoer::Advise(IUnknown* pUnk, DWORD* pdwCookie)
  21. {
  22. if (!m_bLocked)  // lock the server on the first advise received
  23. {
  24. ((IDuckDoer*)this)->AddRef();
  25. m_bLocked = TRUE;
  26. }
  27. HRESULT hr = CProxyIDuckInt<CDuckDoer>::Advise(pUnk, pdwCookie);
  28. if (SUCCEEDED(hr))
  29. {
  30. TCHAR szCookieItem[50];
  31. _stprintf(szCookieItem, _T("Cookie %9d.t(pUnk = %p)"), *pdwCookie, *pUnk);
  32. _ASSERT(m_pDlg != NULL);
  33. if (!m_pDlg->IsWindowVisible())
  34. m_pDlg->ShowWindow(SW_SHOWNORMAL);
  35. HWND hwndListBox = m_pDlg->GetDlgItem(IDC_LISTCONNPTS);
  36. SendMessage(hwndListBox, LB_ADDSTRING, 0, (LPARAM)(TCHAR*)szCookieItem);
  37. m_pDlg->RecalcListboxExtent(szCookieItem);
  38. // enable all the dialog buttons for connection points
  39. _ASSERT(m_pDlg != NULL);
  40. ::EnableWindow(m_pDlg->GetDlgItem(IDC_QUACK), TRUE);
  41. ::EnableWindow(m_pDlg->GetDlgItem(IDC_FLAP), TRUE);
  42. ::EnableWindow(m_pDlg->GetDlgItem(IDC_PADDLE), TRUE);
  43. ::EnableWindow(m_pDlg->GetDlgItem(IDC_WALK), TRUE);
  44. ::EnableWindow(m_pDlg->GetDlgItem(IDOK), FALSE);
  45. }
  46. return hr;
  47. }
  48. STDMETHODIMP CDuckDoer::Unadvise(DWORD dwCookie)
  49. {
  50. HRESULT hr = CProxyIDuckInt<CDuckDoer>::Unadvise(dwCookie);
  51. if (SUCCEEDED(hr))
  52. {
  53. TCHAR szCookieItem[50];
  54. _stprintf(szCookieItem, _T("Cookie %9d."), dwCookie);
  55. _ASSERT(m_pDlg != NULL);
  56. HWND hwndListBox = m_pDlg->GetDlgItem(IDC_LISTCONNPTS);
  57. int nIndex = SendMessage(hwndListBox, LB_FINDSTRING, -1, (LPARAM)szCookieItem);
  58. _ASSERT(nIndex != LB_ERR);  // the entry has to be in the listbox.
  59. SendMessage(hwndListBox, LB_GETTEXT, nIndex, (LPARAM)szCookieItem);
  60. SendMessage(hwndListBox, LB_DELETESTRING, nIndex, 0);
  61. m_pDlg->RecalcListboxExtent(szCookieItem, FALSE/*bAdded*/);
  62. int nItems = SendMessage(hwndListBox, LB_GETCOUNT, 0, 0);
  63. _ASSERT(nItems != LB_ERR);
  64. if (nItems == 0)  // the listbox is empty change button settings
  65. {
  66. _ASSERT(m_pDlg != NULL);
  67. ::EnableWindow(m_pDlg->GetDlgItem(IDC_QUACK), FALSE);
  68. ::EnableWindow(m_pDlg->GetDlgItem(IDC_FLAP), FALSE);
  69. ::EnableWindow(m_pDlg->GetDlgItem(IDC_PADDLE), FALSE);
  70. ::EnableWindow(m_pDlg->GetDlgItem(IDC_WALK), FALSE);
  71. ::EnableWindow(m_pDlg->GetDlgItem(IDOK), TRUE);
  72. }
  73. }
  74. return hr;
  75. }