home *** CD-ROM | disk | FTP | other *** search
- // TaskButton.cpp: implementation of the CTaskButton class.
- //
- //////////////////////////////////////////////////////////////////////
-
- #include "stdafx.h"
- #include "TaskButton.h"
-
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
-
- CTaskButton::CTaskButton()
- {
- m_imContext = NULL;
- m_bMoveCapture = false;
- }
-
- CTaskButton::~CTaskButton()
- {
- if(m_imContext)
- delete m_imContext;
- }
-
- LRESULT CTaskButton::WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch(message)
- { // begin switch
- case WM_CONTEXTMENU:
- OnContextMenu(wParam,lParam);
- break;
- } // end switch
-
- // pass the message to the owner window's WndProc function
- return CButtonImage::WindowProc(hwnd,message,wParam,lParam);
- }
-
- void CTaskButton::OnContextMenu(WPARAM wParam, LPARAM lParam)
- {// begin OnContextMenu
- POINT pt = {LOWORD(lParam),HIWORD(lParam)};
- int nMenuSel = m_imContext->TrackPopupMenu(TPM_LEFTALIGN|TPM_TOPALIGN|TPM_NONOTIFY|TPM_RETURNCMD,pt.x,pt.y,m_hWnd);
- switch(nMenuSel)
- {// begin nMenuSel switch
- case IDM_MENU_CLOSE:
- DestroyWindow(parentWnd);
- break;
- case IDM_MENU_MOVE:
- {
- SetCapture(m_hWnd);
- m_bMoveCapture = true;
- // initiate drag
- RECT rRect = {NULL};
- GetWindowRect(parentWnd,&rRect);
- SendMessage(parentWnd,WM_NCLBUTTONDOWN,(WPARAM)HTCAPTION,MAKELPARAM(rRect.left+(rRect.right-rRect.left)/2,rRect.top+(rRect.bottom-rRect.top)/2));
- }
- break;
- case IDM_MENU_ABOUT:
- {
- CAbout aDlg;
- aDlg.Init(appInstance,parentWnd,IDD_DIALOG_ABOUT,true);
- }
- break;
- }// end nMenuSel switch
- }// end OnContextMenu
-
- void CTaskButton::Create(UINT ID,HWND parent,HINSTANCE parentInstance,BYTE imageFlags,SIZE imgSz)
- {// begin Create
- CButtonImage::Create(ID,parent,parentInstance,imageFlags,imgSz);
- if(m_imContext)
- delete m_imContext;
- m_imContext = new CImageMenu;
- m_imContext->Init(m_hWnd);
- m_imContext->AppendMenu(IDM_MENU_MOVE,"Move",IDI_ICON_MOVE);
- m_imContext->AppendMenu(IDM_MENU_CLOSE,"Close",IDI_ICON_CLOSE);
- m_imContext->AppendMenu(IDM_MENU_ABOUT,"About",IDI_ICON_ABOUT);
- }// end Create
-
- void CTaskButton::OnMouseMove(LPARAM lParam)
- {// begin OnMouseMove
- if(m_bMoveCapture && GetCapture() == m_hWnd)
- {// begin move window under mouse
- /* POINT pt = {LOWORD(lParam),HIWORD(lParam)};
- ClientToScreen(m_hWnd,&pt);
- const int MAX_SHORT = 0xFFFF;
- if(pt.x > MAX_SHORT)
- pt.x = pt.x-MAX_SHORT;
- if(pt.y > MAX_SHORT)
- pt.y = pt.y-MAX_SHORT;
- RECT rNewRect = {NULL};
- rNewRect.left = pt.x-m_ptMoveCapture.x;
- rNewRect.top = pt.y-m_ptMoveCapture.y;
- rNewRect.right = rNewRect.left+m_szMoveCapture.cx;
- rNewRect.bottom = rNewRect.top+m_szMoveCapture.cy;*/
- RECT rNewRect = {NULL};
- GetWindowRect(parentWnd,&rNewRect);
- // allow the window position to be modified
- SendMessage(parentWnd,WM_MOVING,(WPARAM)0,(LPARAM)&rNewRect);
- // set the new position
- SetWindowPos(parentWnd,NULL,rNewRect.left,rNewRect.top,0,0,SWP_NOSIZE|SWP_NOOWNERZORDER);
- }// end move window under mouse
- CButtonImage::OnMouseMove(lParam);
- }// end OnMouseMove
-
- void CTaskButton::OnClick(HWND hWnd,LPARAM lParam)
- {// begin OnClick
- if(m_bMoveCapture && GetCapture() == hWnd)
- {// begin stop capture
- m_bMoveCapture = false;
- ReleaseCapture();
- }// end stop capture
- CButtonImage::OnClick(hWnd,lParam);
- }// end OnClick