非模态对话框

实现可编辑表格

// 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之后对话框的父窗口时主框架,移动位置时要转换一下。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值