主对话框类为: CTest1Dlg
d出对话框类为: CDary
主对话框里面加 combobox 控件,相关control变量为: m_BoxControl
主对话框里面加一个button, 里面写:
void CTest1Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
CDary test
test.testDlg = this
test.DoModal()
}
d出对话框类的头文件里面包含旅李毕下主对话框的头文件,并加个主类的指针变量:
public:
CTest1Dlg* testDlg
d出对话框类里面加个button, 代码写成
void CDary::OnButton1()
{
// TODO: Add your control notification handler code here
testDlg->m_BoxControl.AddString("daryxiong")
}
/////////////////////////////////////////////
主对话框扰余头文件:
// test1Dlg.h : header file
//
#if !defined(AFX_TEST1DLG_H__1AA3DA4E_67CA_4095_86DF_49A30BC9653C__INCLUDED_)
#define AFX_TEST1DLG_H__1AA3DA4E_67CA_4095_86DF_49A30BC9653C__INCLUDED_
#if _MSC_VER >1000
#pragma once
#endif // _MSC_VER >1000
/////拆芹////////////////////////////////////////////////////////////////////////
// CTest1Dlg dialog
class CTest1Dlg : public CDialog
{
// Construction
public:
CTest1Dlg(CWnd* pParent = NULL)// standard constructor
// Dialog Data
//{{AFX_DATA(CTest1Dlg)
enum { IDD = IDD_TEST1_DIALOG }
CComboBox m_BoxControl
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTest1Dlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX)// DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon
// Generated message map functions
//{{AFX_MSG(CTest1Dlg)
virtual BOOL OnInitDialog()
afx_msg void OnSysCommand(UINT nID, LPARAM lParam)
afx_msg void OnPaint()
afx_msg HCURSOR OnQueryDragIcon()
afx_msg void OnButton1()
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
}
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_TEST1DLG_H__1AA3DA4E_67CA_4095_86DF_49A30BC9653C__INCLUDED_)
主对话框CPP文件:
// test1Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "test1.h"
#include "test1Dlg.h"
#include "Dary.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()
/////////////////////////////////////////////////////////////////////////////
// CTest1Dlg dialog
CTest1Dlg::CTest1Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CTest1Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTest1Dlg)
// 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)
}
void CTest1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX)
//{{AFX_DATA_MAP(CTest1Dlg)
DDX_Control(pDX, IDC_COMBO1, m_BoxControl)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTest1Dlg, CDialog)
//{{AFX_MSG_MAP(CTest1Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTest1Dlg message handlers
BOOL CTest1Dlg::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
// TODO: Add extra initialization here
return TRUE // return TRUE unless you set the focus to a control
}
void CTest1Dlg::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 CTest1Dlg::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 CTest1Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon
}
void CTest1Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
CDary test
test.testDlg = this
test.DoModal()
}
d出对话框头文件:
#if !defined(AFX_DARY_H__EC699B44_E662_4D1B_9722_99E4EBB337FE__INCLUDED_)
#define AFX_DARY_H__EC699B44_E662_4D1B_9722_99E4EBB337FE__INCLUDED_
#if _MSC_VER >1000
#pragma once
#endif // _MSC_VER >1000
// Dary.h : header file
//
#include "test1Dlg.h"
/////////////////////////////////////////////////////////////////////////////
// CDary dialog
class CDary : public CDialog
{
// Construction
public:
CDary(CWnd* pParent = NULL) // standard constructor
// Dialog Data
//{{AFX_DATA(CDary)
enum { IDD = IDD_DIALOG1 }
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDary)
protected:
virtual void DoDataExchange(CDataExchange* pDX) // DDX/DDV support
//}}AFX_VIRTUAL
public:
CTest1Dlg* testDlg
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CDary)
afx_msg void OnButton1()
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
}
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_DARY_H__EC699B44_E662_4D1B_9722_99E4EBB337FE__INCLUDED_)
d出对话框CPP文件
// Dary.cpp : implementation file
//
#include "stdafx.h"
#include "test1.h"
#include "Dary.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__
#endif
/////////////////////////////////////////////////////////////////////////////
// CDary dialog
CDary::CDary(CWnd* pParent /*=NULL*/)
: CDialog(CDary::IDD, pParent)
{
//{{AFX_DATA_INIT(CDary)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CDary::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX)
//{{AFX_DATA_MAP(CDary)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDary, CDialog)
//{{AFX_MSG_MAP(CDary)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDary message handlers
void CDary::OnButton1()
{
// TODO: Add your control notification handler code here
testDlg->m_BoxControl.AddString("daryxiong")
}
这样还不行的话偶也就没办法了.
可使用ON_CONTROL_RANGE1. 打开 resource.h,将你的ComboBox控件ID进行族培租连续编号,例如1001,1002...
2. 在对话框类的头中卜文件中添加公有成员函数:afx_msg void OnUpdateCombo(UINT uID)
3. 在对话框类的cpp文兆兆件中BEGIN_MESSAGE_MAP(CTestDlg, CDialog) 的 //}}AFX_MSG_MAP下添加代码 ON_CONTROL_RANGE(CBN_EDITUPDATE,1001,1002,OnUpdateCombo)
4. 然后在cpp文件中添加函数void CTestDlg::OnUpdateCombo(UINT uID) {}
5. 在函数内判断 uID,来确定用户在哪个ComboBox里进行了输入,并作相应处理。
业精于勤,荒于戏。行成于思,毁于随。
1、衫罩把定制的窗口放到QComboBox的下液塌含拉框中,代码如下。
2、接下来我就解释闹笑下父窗口的eventFIlter方法。代码比较简单。
3、ConstructList列表实现,代码如下。
4、最后重写了QCheckBox,头文件代码如下所示。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)