实现可编辑表格
// DlgGridEdit.cpp : 实现文件
//
#include "stdafx.h"
#include "DlgGridEdit.h"
#include "..\DuInclude\DuMessage.h"
// CDlgGridEdit 对话框
IMPLEMENT_DYNAMIC(CDlgGridEdit, CDialog)
CDlgGridEdit::CDlgGridEdit(CWnd* pParent /*=NULL*/)
: CDialog(CDlgGridEdit::IDD, pParent)
{
m_nRow = 0;
m_nCol = 0;
m_hWndSendMessage = NULL;
}
CDlgGridEdit::~CDlgGridEdit()
{
}
void CDlgGridEdit::DoDataExchange(CDataExchange* pDX)
{
__super::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CDlgGridEdit, CDialog)
ON_BN_CLICKED(IDC_BUTTON_OK, OnButtonOK)
ON_WM_DESTROY()
ON_WM_ACTIVATE()
ON_WM_SIZE()
END_MESSAGE_MAP()
// CDlgGridEdit 消息处理程序
BOOL CDlgGridEdit::OnInitDialog()
{
__super::OnInitDialog();
CEdit * pEdit = (CEdit*)GetDlgItem(IDC_EDIT_TEXT);
pEdit->SetWindowText(m_strText);
pEdit->SetSel(0, -1);
return TRUE;
}
void CDlgGridEdit::OnButtonOK()
{
SendMessage(WM_DESTROY, NULL, NULL);
}
void CDlgGridEdit::OnDestroy()
{
GetDlgItem(IDC_EDIT_TEXT)->GetWindowText(m_strText);
::SendMessage(m_hWndSendMessage, WM_GRID_EDIT_DESTROY, (WPARAM)this, NULL);
__super::OnDestroy();
delete this;
}
void CDlgGridEdit::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
__super::OnActivate(nState, pWndOther, bMinimized);
if (WA_INACTIVE == nState)
SendMessage(WM_DESTROY, NULL, NULL);
}
void CDlgGridEdit::OnSize(UINT nType, int cx, int cy)
{
__super::OnSize(nType, cx, cy);
if (NULL == GetDlgItem(IDC_EDIT_TEXT) || NULL == GetDlgItem(IDC_EDIT_TEXT)->GetSafeHwnd())
return;
GetDlgItem(IDC_EDIT_TEXT)->MoveWindow(0, 0, cx - cy, cy);
GetDlgItem(IDC_BUTTON_OK)->MoveWindow(cx - cy, 0, cy, cy);
}
#pragma once
#include "..\Resource.h"
// CDlgGridEdit 对话框
class CDlgGridEdit : public CDialog
{
DECLARE_DYNAMIC(CDlgGridEdit)
public:
CDlgGridEdit(CWnd* pParent = NULL); // 标准构造函数
virtual ~CDlgGridEdit();
// 对话框数据
enum { IDD = IDD_0_DLG_GRID_EDIT };
int m_nRow;
int m_nCol;
CString m_strText;
HWND m_hWndSendMessage;
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
virtual BOOL OnInitDialog();
afx_msg void OnButtonOK();
afx_msg void OnDestroy();
afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
afx_msg void OnSize(UINT nType, int cx, int cy);
DECLARE_MESSAGE_MAP()
};
对话框风格 Popup,如果选择Child会收不到消息ON_WM_ACTIVATE(),无法实现单击非模态对话框以外区域就销毁对话框的功能,设置Popup之后对话框的父窗口时主框架,移动位置时要转换一下。