-
February 11th, 2013, 01:09 AM
#1
How can I identify which of two subclassed controls the mouse is over?
I have a dialog app with two separate static controls. Both controls have been subclassed from CStatic derived class to implement drag and drop and double clicking. The class works just fine, but I cannot figure out which of the controls is being double clicked or dragged and dropped onto because I only have the code below operating. I need some method in the derived class to determine which control is being manipulated.
Code:
// header file
#pragma once
#ifndef __AFXWIN_H__
#error "include 'stdafx.h' before including this file for PCH"
#endif
#include "resource.h" // main symbols
// CMyStaticDragApp:
// See MyStaticDrag.cpp for the implementation of this class
//
class CMyStaticDragApp : public CWinApp
{
public:
CMyStaticDragApp();
// Overrides
public:
virtual BOOL InitInstance();
// Implementation
DECLARE_MESSAGE_MAP()
};
extern CMyStaticDragApp theApp;
// implementation file
#include "stdafx.h"
#include "StaticDragDrop.h"
// CStaticDragDrop
IMPLEMENT_DYNAMIC(CStaticDragDrop, CStatic)
CStaticDragDrop::CStaticDragDrop()
{
}
CStaticDragDrop::~CStaticDragDrop()
{
}
BEGIN_MESSAGE_MAP(CStaticDragDrop, CStatic)
ON_WM_LBUTTONDBLCLK()
ON_WM_RBUTTONDBLCLK()
ON_WM_DROPFILES()
ON_WM_CREATE()
END_MESSAGE_MAP()
// CStaticDragDrop message handlers
void CStaticDragDrop::OnLButtonDblClk(UINT nFlags, CPoint point)
{
MessageBox(_T("You left button double clicked on me"), _T("Left Button Double Click"), MB_ICONINFORMATION);
CStatic::OnLButtonDblClk(nFlags, point);
}// OnLButtonDblClk(UINT nFlags, CPoint point)
void CStaticDragDrop::OnRButtonDblClk(UINT nFlags, CPoint point)
{
MessageBox(_T("You right button double clicked on me"), _T("Right Button Double Click"), MB_ICONINFORMATION);
CStatic::OnRButtonDblClk(nFlags, point);
}// OnRButtonDblClk(UINT nFlags, CPoint point)
void CStaticDragDrop::OnDropFiles(HDROP hDropInfo)
{
TRACE0("*********** OnDropFiles ************************\n");
UINT i = 0;
UINT nFiles = ::DragQueryFile(hDropInfo, (UINT) -1, NULL, 0);
for (i = 0; i < nFiles; i++)
{
TCHAR szFileName[_MAX_PATH];
::DragQueryFile(hDropInfo, i, szFileName, _MAX_PATH);
//ProcessMyFile(szFileName);
TRACE1("%s\n", szFileName);
}
::DragFinish(hDropInfo);
//CFrameWnd::OnDropFiles(hDropInfo);
CStatic::OnDropFiles(hDropInfo);
}
int CStaticDragDrop::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CStatic::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
this->DragAcceptFiles(TRUE);
return 0;
}
You're welcome to tell me how stupid I am and that I should know better. That's OK. But please help. Thanks : )
mpliam
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|