home *** CD-ROM | disk | FTP | other *** search
/ PC Administrator / spravce.iso / TaskModule / src / TaskButton.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-10  |  3.4 KB  |  111 lines

  1. // TaskButton.cpp: implementation of the CTaskButton class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4.  
  5. #include "stdafx.h"
  6. #include "TaskButton.h"
  7.  
  8. //////////////////////////////////////////////////////////////////////
  9. // Construction/Destruction
  10. //////////////////////////////////////////////////////////////////////
  11.  
  12. CTaskButton::CTaskButton()
  13. {
  14.     m_imContext = NULL;
  15.     m_bMoveCapture = false;
  16. }
  17.  
  18. CTaskButton::~CTaskButton()
  19. {
  20.     if(m_imContext)
  21.         delete m_imContext;
  22. }
  23.  
  24. LRESULT CTaskButton::WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  25. {
  26.     switch(message)
  27.     { // begin switch
  28.     case WM_CONTEXTMENU:
  29.         OnContextMenu(wParam,lParam);
  30.         break;
  31.     } // end switch
  32.  
  33.     // pass the message to the owner window's WndProc function
  34.     return CButtonImage::WindowProc(hwnd,message,wParam,lParam);
  35. }
  36.  
  37. void CTaskButton::OnContextMenu(WPARAM wParam, LPARAM lParam)
  38. {// begin OnContextMenu
  39.     POINT pt = {LOWORD(lParam),HIWORD(lParam)};
  40.     int nMenuSel = m_imContext->TrackPopupMenu(TPM_LEFTALIGN|TPM_TOPALIGN|TPM_NONOTIFY|TPM_RETURNCMD,pt.x,pt.y,m_hWnd);
  41.     switch(nMenuSel)
  42.     {// begin nMenuSel switch
  43.     case IDM_MENU_CLOSE:
  44.         DestroyWindow(parentWnd);
  45.         break;
  46.     case IDM_MENU_MOVE:
  47.         {
  48.             SetCapture(m_hWnd);            
  49.             m_bMoveCapture = true;
  50.             // initiate drag
  51.             RECT rRect = {NULL};
  52.             GetWindowRect(parentWnd,&rRect);
  53.             SendMessage(parentWnd,WM_NCLBUTTONDOWN,(WPARAM)HTCAPTION,MAKELPARAM(rRect.left+(rRect.right-rRect.left)/2,rRect.top+(rRect.bottom-rRect.top)/2));
  54.         }
  55.         break;
  56.     case IDM_MENU_ABOUT:
  57.         {
  58.             CAbout aDlg;
  59.             aDlg.Init(appInstance,parentWnd,IDD_DIALOG_ABOUT,true);
  60.         }
  61.         break;
  62.     }// end nMenuSel switch
  63. }// end OnContextMenu
  64.  
  65. void CTaskButton::Create(UINT ID,HWND parent,HINSTANCE parentInstance,BYTE imageFlags,SIZE imgSz)
  66. {// begin Create
  67.     CButtonImage::Create(ID,parent,parentInstance,imageFlags,imgSz);
  68.     if(m_imContext)
  69.         delete m_imContext;
  70.     m_imContext = new CImageMenu;
  71.     m_imContext->Init(m_hWnd);
  72.     m_imContext->AppendMenu(IDM_MENU_MOVE,"Move",IDI_ICON_MOVE);
  73.     m_imContext->AppendMenu(IDM_MENU_CLOSE,"Close",IDI_ICON_CLOSE);
  74.     m_imContext->AppendMenu(IDM_MENU_ABOUT,"About",IDI_ICON_ABOUT);
  75. }// end Create
  76.  
  77. void CTaskButton::OnMouseMove(LPARAM lParam)
  78. {// begin OnMouseMove
  79.     if(m_bMoveCapture && GetCapture() == m_hWnd)
  80.     {// begin move window under mouse
  81. /*        POINT pt = {LOWORD(lParam),HIWORD(lParam)};
  82.         ClientToScreen(m_hWnd,&pt);
  83.         const int MAX_SHORT = 0xFFFF;
  84.         if(pt.x > MAX_SHORT)
  85.             pt.x = pt.x-MAX_SHORT;
  86.         if(pt.y > MAX_SHORT)
  87.             pt.y = pt.y-MAX_SHORT;
  88.         RECT rNewRect = {NULL};
  89.         rNewRect.left = pt.x-m_ptMoveCapture.x;
  90.         rNewRect.top = pt.y-m_ptMoveCapture.y;
  91.         rNewRect.right = rNewRect.left+m_szMoveCapture.cx;
  92.         rNewRect.bottom = rNewRect.top+m_szMoveCapture.cy;*/
  93.         RECT rNewRect = {NULL};
  94.         GetWindowRect(parentWnd,&rNewRect);
  95.         // allow the window position to be modified
  96.         SendMessage(parentWnd,WM_MOVING,(WPARAM)0,(LPARAM)&rNewRect);
  97.         // set the new position
  98.         SetWindowPos(parentWnd,NULL,rNewRect.left,rNewRect.top,0,0,SWP_NOSIZE|SWP_NOOWNERZORDER);
  99.     }// end move window under mouse
  100.     CButtonImage::OnMouseMove(lParam);
  101. }// end OnMouseMove
  102.  
  103. void CTaskButton::OnClick(HWND hWnd,LPARAM lParam)
  104. {// begin OnClick
  105.     if(m_bMoveCapture && GetCapture() == hWnd)
  106.     {// begin stop capture
  107.         m_bMoveCapture = false;
  108.         ReleaseCapture();
  109.     }// end stop capture
  110.     CButtonImage::OnClick(hWnd,lParam);
  111. }// end OnClick