// sortlistDlg.cpp : implementation file
//
#include "stdafx.h"
#include "sortlist.h"
#include "sortlistDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSortlistDlg dialog
CSortlistDlg::CSortlistDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSortlistDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSortlistDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_bDragging = FALSE;
}
void CSortlistDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSortlistDlg)
DDX_Control(pDX, IDC_LIST2, m_clistctrl2);
DDX_Control(pDX, IDC_LIST1, m_clistctrl);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSortlistDlg, CDialog)
//{{AFX_MSG_MAP(CSortlistDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
ON_NOTIFY(NM_DBLCLK, IDC_LIST2, OnDblclkList2)
//}}AFX_MSG_MAP
ON_NOTIFY(LVN_BEGINDRAG, IDC_LIST1, OnBeginDrag)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSortlistDlg message handlers
BOOL CSortlistDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
//List Ctrl stuff
m_cimagelist.Create(IDB_BITMAP1, 10, 1, RGB(100,100,100));
m_clistctrl.SetImageList(&m_cimagelist, LVSIL_SMALL);
m_clistctrl2.SetImageList(&m_cimagelist, LVSIL_NORMAL);
LV_COLUMN lvcol;
lvcol.mask = LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
lvcol.pszText = "#";
lvcol.iSubItem = 0;
lvcol.cx = 130;
m_clistctrl.InsertColumn(0, &lvcol);
LV_COLUMN lvcol2;
lvcol2.mask = LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
lvcol2.pszText = "ID";
lvcol2.iSubItem = 1;
lvcol2.cx = 130;
m_clistctrl.InsertColumn(1, &lvcol2);
int i = 0;
int iImage = 0;
for (int ii = 1000; ii < 1030; ii++, i++)
{
LV_ITEM lvi;
lvi.mask = LVIF_TEXT | LVIF_IMAGE;
char sz[20];
_itoa(i, sz, 10);
lvi.iItem = 0;
lvi.iSubItem = 0;
lvi.pszText = sz;
lvi.iImage = iImage;
if (iImage == 0)
{
iImage++;
}
else
{
iImage--;
}
int iii = m_clistctrl.InsertItem(&lvi);
LV_ITEM lvi2;
lvi2.mask = LVIF_TEXT;
char sz2[20];
_itoa(ii, sz2, 10);
m_clistctrl.SetItemText(iii, 1, sz2);
}
ListView_SetExtendedListViewStyle
(m_clistctrl.m_hWnd, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP);
return TRUE; // return TRUE unless you set the focus to a control
}
void CSortlistDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CSortlistDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSortlistDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSortlistDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
if( m_bDragging )
{
//RELEASE THE MOUSE CAPTURE AND END THE DRAGGING
::ReleaseCapture();
m_bDragging = FALSE;
m_pDragImage->DragLeave(GetDesktopWindow());
m_pDragImage->EndDrag();
delete m_pDragImage;
//GET THE WINDOW UNDER THE DROP POINT
CPoint pt(point);
ClientToScreen(&pt);
m_pDropWnd = WindowFromPoint(pt);
//DROP THE ITEM ON THE LIST
/*
if( m_pDropWnd->IsKindOf(RUNTIME_CLASS(CListCtrl)) )
DropItemOnList();
*/
POINT pt1;
::GetCursorPos(&pt1);
CRect iRect;
m_clistctrl.GetWindowRect(iRect);
// this->GetWindowRect(iRect);
if(iRect.PtInRect(pt))
DropItemOnList();//确定鼠标移动到了合适的位置
m_clistctrl2.GetWindowRect(iRect);
if(iRect.PtInRect(pt))
DropItemOnList2();//确定鼠标移动到了合适的位置
}
CDialog::OnLButtonUp(nFlags, point);
}
void CSortlistDlg::OnBeginDrag(NMHDR* pnmhdr, LRESULT* pResult)
{
//RECORD THE INDEX OF THE ITEM BEIGN DRAGGED AS m_nDragIndex
m_nDragIndex = ((NM_LISTVIEW *)pnmhdr)->iItem;
//CREATE A DRAG IMAGE FROM THE CENTER POINT OF THE ITEM IMAGE
POINT pt;
pt.x = 8;
pt.y = 8;
m_pDragImage = m_clistctrl.CreateDragImage(m_nDragIndex, &pt);
m_pDragImage->BeginDrag(0, CPoint (8, 8));
m_pDragImage->DragEnter(
GetDesktopWindow(), ((NM_LISTVIEW *)pnmhdr)->ptAction);
//SET THE FLAGS INDICATING A DRAG IN PROGRESS
m_bDragging = TRUE;
m_nDropIndex = -1;
m_pDropWnd = &m_clistctrl;
//CAPTURE ALL MOUSE MESSAGES IN CASE THE USER DRAGS OUTSIDE OF THE VIEW
SetCapture();
}
void CSortlistDlg::OnMouseMove(UINT nFlags, CPoint point)
{
if( m_bDragging )
{
m_ptDropPoint = point;
ClientToScreen(&m_ptDropPoint);
MFC List控件间拖动
4星 · 超过85%的资源 需积分: 9 132 浏览量
2011-04-19
21:28:47
上传
评论 2
收藏 1.81MB RAR 举报
jy02904595
- 粉丝: 13
- 资源: 1
最新资源
- 2022年各城市PM2.5, PM10, SO2, NO2等环境空气质量数据
- Golang:通过Gin框架+Redis+责任链,实现一个简单的钉钉机器人,进行消息处理 ps:多应用版
- 2021年各城市PM2.5, PM10, SO2, NO2等环境空气质量数据
- CORRUPT.navicat150-premium-cs-x64.exe
- centos7 ssh 升级至 9.6p1
- DriverMax Pro .exe
- PHP端通过modbus协议跟第三方设备进行数据通信
- navicat安装包亲测可用
- 算法部署-使用OpenVINO部署MobileStyleGAN轻量化高保真图像合成算法-项目源码-优质项目实战.zip
- 基于java实现远程采集华为逆变器使用modbus tcp协议进行通讯的设备数据
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈