// drag_and_drop_cbitmapbuttonDlg.cpp : implementation file
// main dialog
//
#include "stdafx.h"
#include "drag_and_drop_cbitmapbutton.h"
#include "drag_and_drop_cbitmapbuttonDlg.h"
#include "dragdropbitmapbutton.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int WM_DRAGBUTTON = RegisterWindowMessage (_T("WM_DRAGBUTTON"));
/////////////////////////////////////////////////////////////////////////////
// CDrag_and_drop_cbitmapbuttonDlg dialog
CDrag_and_drop_cbitmapbuttonDlg::CDrag_and_drop_cbitmapbuttonDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDrag_and_drop_cbitmapbuttonDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDrag_and_drop_cbitmapbuttonDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDrag_and_drop_cbitmapbuttonDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDrag_and_drop_cbitmapbuttonDlg)
DDX_Control(pDX, IDC_BUTTON3_VOLUME, m_btnVolume);
DDX_Control(pDX, IDC_BUTTON4_HOME, m_btnHome);
DDX_Control(pDX, IDC_BUTTON2_SAVE, m_btnSave);
DDX_Control(pDX, IDC_BUTTON1_CAMERA, m_btnCamera);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDrag_and_drop_cbitmapbuttonDlg, CDialog)
//{{AFX_MSG_MAP(CDrag_and_drop_cbitmapbuttonDlg)
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_REGISTERED_MESSAGE(WM_DRAGBUTTON, OnDragButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDrag_and_drop_cbitmapbuttonDlg message handlers
BOOL CDrag_and_drop_cbitmapbuttonDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
m_btnCamera.LoadBitmaps(IDB_CAMERA, IDB_CAMERA_DOWN,
IDB_CAMERA_FOCUS, IDB_CAMERA_DISABLE);
m_btnCamera.SizeToContent();
m_btnSave.LoadBitmaps(IDB_SAVE, IDB_SAVE_DOWN,
IDB_SAVE_FOCUS, IDB_SAVE_DISABLE);
m_btnSave.SizeToContent();
m_btnVolume.LoadBitmaps(IDB_VOLUME, IDB_VOLUME_DOWN,
IDB_VOLUME_FOCUS, IDB_VOLUME_DISABLE);
m_btnVolume.SizeToContent();
m_btnHome.LoadBitmaps(IDB_HOME, IDB_HOME_DOWN,
IDB_HOME_FOCUS, IDB_HOME_DISABLE);
m_btnHome.SizeToContent();
BOOL bRet = m_imgl.Create(48, 48, ILC_MASK|ILC_COLOR8, 1, 1);
ASSERT(bRet);
m_bButtonDragging = FALSE;
return TRUE; // return TRUE unless you set the focus to a control
}
void CDrag_and_drop_cbitmapbuttonDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bButtonDragging)
{
m_imgl.DragMove(point);
}
else
{
// just trying different things to try to alter the behavior
CDialog::OnMouseMove(nFlags, point);
}
//CDialog::OnMouseMove(nFlags, point);
}
void CDrag_and_drop_cbitmapbuttonDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnLButtonDown(nFlags, point);
}
void CDrag_and_drop_cbitmapbuttonDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
OutputDebugString(_T("L-button UP\n"));
if(m_bButtonDragging)
{
(void)ReleaseCapture();
m_imgl.DragLeave(this);
m_imgl.EndDrag();
// Delete the image list and verify.
//m_imgl.DeleteImageList();
//ASSERT(m_imgl.GetSafeHandle() == NULL);
//SetTimer(TIMER_ID_AUTO_HIDE, AUTO_HIDE_TIMEOUT, NULL);
OutputDebugString(_T("dragging done\n"));
}
m_bButtonDragging = FALSE;
CDialog::OnLButtonUp(nFlags, point);
}
void CDrag_and_drop_cbitmapbuttonDlg::OnDragButton(WPARAM wParam, LPARAM lParam)
{
OutputDebugString(_T("button dragging has started!\n"));
COLORREF rgbTransparentColor=RGB(0, 0, 0);
// Set up your transparent color as appropriate
// crTransparentColor[i] = GetPixel( hdc, x + 1, y + 1 );
CPoint cp;
(void)GetCursorPos(&cp);
// Add the bitmap into the image list
// for(int i=0; i<m_imgl.GetImageCount(); i++)
// {
// m_imgl.Remove(i);
// OutputDebugString(_T("removing image objs\n"));
// }
//if(m_imgl.GetImageCount() == 0)
// m_imgl.Add(((CDragDropBitmapButton*)lParam)->GetDragImage(), rgbTransparentColor);
m_imgl.BeginDrag(0, CPoint(0,0)); // roughly center of bitmap
m_imgl.DragEnter(this, cp);
m_bButtonDragging = TRUE;
SetCapture();
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* end of file */
// drag_and_drop_cbitmapbuttonDlg.h : header file
//
#if !defined(AFX_DRAG_AND_DROP_CBITMAPBUTTONDLG_H__45A20897_80A8_4FF3_8B01_35214FC4B2B5__INCLUDED_)
#define AFX_DRAG_AND_DROP_CBITMAPBUTTONDLG_H__45A20897_80A8_4FF3_8B01_35214FC4B2B5__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
#include "dragdropbitmapbutton.h"
/////////////////////////////////////////////////////////////////////////////
// CDrag_and_drop_cbitmapbuttonDlg dialog
class CDrag_and_drop_cbitmapbuttonDlg : public CDialog
{
// Construction
public:
CDrag_and_drop_cbitmapbuttonDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CDrag_and_drop_cbitmapbuttonDlg)
enum { IDD = IDD_DRAG_AND_DROP_CBITMAPBUTTON_DIALOG };
CDragDropBitmapButton m_btnVolume;
CBitmapButton m_btnHome;
CBitmapButton m_btnSave;
CBitmapButton m_btnCamera;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDrag_and_drop_cbitmapbuttonDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
CImageList m_imgl;
BOOL m_bButtonDragging;
// Generated message map functions
//{{AFX_MSG(CDrag_and_drop_cbitmapbuttonDlg)
virtual BOOL OnInitDialog();
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnDragButton(WPARAM wParam, LPARAM lParam);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft eMbedded Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_DRAG_AND_DROP_CBITMAPBUTTONDLG_H__45A20897_80A8_4FF3_8B01_35214FC4B2B5__INCLUDED_)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// DragDropBitmapButton.cpp : implementation file
// My derived button class (from CBitmapButton)
#include "stdafx.h"
//#include "proof_mfc.h"
#include "DragDropBitmapButton.h"
#include "WinUser.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDragDropBitmapButton
CDragDropBitmapButton::CDragDropBitmapButton()
{
m_bDragging = FALSE;
m_bDown = FALSE;
m_WM_DRAGBUTTON = RegisterWindowMessage (_T("WM_DRAGBUTTON"));
}
CDragDropBitmapButton::~CDragDropBitmapButton()
{
}
BEGIN_MESSAGE_MAP(CDragDropBitmapButton, CBitmapButton)
//{{AFX_MSG_MAP(CDragDropBitmapButton)
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDragDropBitmapButton message handlers
void CDragDropBitmapButton::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bDown)
{
// m_bDragging flag is used to skip the first time
// the mouse button is pressed, otherwise a simple press of the
// button would cause the WM_DRAGBUTTON message to be sent
if(m_bDragging)
{
m_bDown = FALSE;
m_bDragging = FALSE;
GetParent()->SendMessage(
m_WM_DRAGBUTTON,
(WPARAM) 0,
(LPARAM) this);
}
else
m_bDragging = TRUE; // for next time through
}
CString x;
x.Format(_T("*DragBtn mouse: %d,%d\n"), point.x, point.y);
OutputDebugString((LPCTSTR(x)));
CBitmapButton::OnMouseMove(nFlags, point);
}
void CDragDropBitmapButton::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_bDown = TRUE;
m_bDragging = FALSE;
OutputDebugString(_T("*DragBtn Left-down\n"));
CBitmapButton::OnLButtonDown(nFlags, point);
}
void CDragDropBitmapButton::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_bDown = FALSE;
m_bDragging = FALSE;
OutputDebugString(_T("*DragBtn Left-up\n"));
CBitmapButton::OnLButtonUp(nFlags, point);
}
CBitmap * CDragDropBitmapButton::GetSelectedBitmap()
{
return &m_bitmapSel;
}
/* end of file */
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_DRAGDROPBITMAPBUTTON_H__7AA290F9_95BC_46FB_8A23_CB373D7D0CD9__INCLUDED_)
#define AFX_DRAGDROPBITMAPBUTTON_H__7AA290F9_95BC_46FB_8A23_CB373D7D0CD9__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// DragDropBitmapButton.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CDragDropBitmapButton window
class CDragDropBitmapButton : public CBitmapButton
{
// Construction
public:
CDragDropBitmapButton();
// Attributes
public:
// Operations
public:
CBitmap * GetDragImage() { return &m_bitmap; };
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDragDropBitmapButton)
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CDragDropBitmapButton();
// Generated message map functions
protected:
BOOL m_bDown;
BOOL m_bDragging;
CImageList m_imgl;
UINT m_WM_DRAGBUTTON;
CBitmap * GetSelectedBitmap();
//{{AFX_MSG(CDragDropBitmapButton)
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_DRAGDROPBITMAPBUTTON_H__7AA290F9_95BC_46FB_8A23_CB373D7D0CD9__INCLUDED_)
>>Does that mean you don't yet know how to or that it is disallowed in this project?
It is because I am using WinCE 5.0, and the version of MFC does not support some of the OLE classes that are normally available to the desktop.
I tried the outline you listed and it mostly works. I ran into the problem where I drag the button bitmap and it disappears behind several controls ( you helped me with a similar problem before). This is minor, so I might try to fix this later.
The next issue related to the current task is that I need to high-light the target CBitmapButton object.
In your outline:
OnMouseMove
CImageList::DragMove
CImageList::DragShowNolock
tree->HitTest -- see if over a drop target ( replace with my hittest code
tree->SelectDropTarget -- and highlight it ( I not sure how to change the bitmap of the CBitmapButton object to look high-lighted?)
CImageList::DragShowNolock
Also, if the user moves away from the target, how do I change the CBitmapButton back to its normal bitmap??
Thanks, for all your help.