I have a MFC application. I am using CMFCTabCtrl in a dialog.
My requirement is I have to add a checkbox in each tab page of CMFCTabCtrl as below.
Is it possible to add checkbox in each tab page of CMFCTabCtrl ?
I have a MFC application. I am using CMFCTabCtrl in a dialog.
My requirement is I have to add a checkbox in each tab page of CMFCTabCtrl as below.
Is it possible to add checkbox in each tab page of CMFCTabCtrl ?
You can't do this with creating a check box window over the current CMFCTabCtrl
.
My advice would be:
Draw3dFlat
or Draw3dTab
functions. This function should draw the checkbox into the tab surface. AdjustTabs
to resize them to the size you want.OnLButtonDown
handler that tracks if the user clicks into your checkbox...You have all the original source code, it should be possible to implement this in using existing code.
My question was answered in the below link.
The code is
BOOL CMyDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// TODO: Add extra initialization here
CRect rectDummy;
rectDummy.SetRectEmpty();
if(!m_tab.Create(CMFCTabCtrl::STYLE_3D_VS2005, rectDummy, this, 1))
{
TRACE0("Failed to create output tab window\n");
return -1; // fail to create
}
m_tab.SetResizeMode(CMFCTabCtrl::RESIZE_NO);
m_tab.SetLocation(CMFCTabCtrl::LOCATION_TOP);
CRect rc;
GetClientRect(rc);
m_tab.MoveWindow(0, 200, rc.right, 200);
const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL;
if (!m_wndOutputBuild.Create(dwStyle, rectDummy, &m_tab, 2) ||
!m_wndOutputDebug.Create(dwStyle, rectDummy, &m_tab, 3) ||
!m_wndOutputFind.Create(dwStyle, rectDummy, &m_tab, 4))
{
TRACE0("Failed to create output windows\n");
return -1; // fail to create
}
CString strTabName;
BOOL bNameValid;
// Attach list windows to tab:
m_tab.AddTab(&m_wndOutputBuild, L" First", (UINT)0);
m_tab.AddTab(&m_wndOutputDebug, L" Second", (UINT)1);
m_tab.AddTab(&m_wndOutputFind, L" Third", (UINT)2);
m_tab.init();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
} myTabCtrl.h
#pragma once
#include "afxtabctrl.h"
class myTabCtrl : public CMFCTabCtrl
{
public:
myTabCtrl();
~myTabCtrl();
void init();
DECLARE_MESSAGE_MAP()
CButton m_Check1;
CButton m_Check2;
CButton m_Check3;
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
}; myTabCtrl.cpp
#include "stdafx.h"
#include "myTabCtrl.h"
myTabCtrl::myTabCtrl()
{
}
myTabCtrl::~myTabCtrl()
{
}
void myTabCtrl::init()
{
CRect rc1, rc2, rc3;
GetTabRect(0, rc1);
GetTabRect(1, rc2);
GetTabRect(2, rc3);
m_Check1.Create(_T("Chkbox1"), WS_CHILD | WS_VISIBLE | BS_CHECKBOX, CRect(0, 0, 13, 13), this, 1234);
m_Check2.Create(_T("Chkbox2"), WS_CHILD | WS_VISIBLE | BS_CHECKBOX, CRect(0, 0, 13, 13), this, 1235);
m_Check3.Create(_T("Chkbox3"), WS_CHILD | WS_VISIBLE | BS_CHECKBOX, CRect(0, 0, 13, 13), this, 1236);
m_Check1.MoveWindow(rc1.left + 20, rc1.top + 3, 13, 13);
m_Check2.MoveWindow(rc2.left + 20, rc2.top + 3, 13, 13);
m_Check3.MoveWindow(rc3.left + 20, rc3.top + 3, 13, 13);
}
BEGIN_MESSAGE_MAP(myTabCtrl, CMFCTabCtrl)
END_MESSAGE_MAP()
LRESULT myTabCtrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
switch (message)
{
case WM_COMMAND:
if (wParam == 1234)
{
BOOL checked = m_Check1.GetCheck();
m_Check1.SetCheck(!checked);
}
else if (wParam == 1235)
{
BOOL checked = m_Check2.GetCheck();
m_Check2.SetCheck(!checked);
}
else if (wParam == 1236)
{
BOOL checked = m_Check3.GetCheck();
m_Check3.SetCheck(!checked);
}
break;
}
return CMFCTabCtrl::WindowProc(message, wParam, lParam);
}