Desktop Development »
Tabs & Property Pages »
Owner Drawn
Intermediate
A simple tab like dialog control
By Wang Yingwu
CTabDialog bundles buttons and dialogs, so users can add their owner draw buttons and dialogs
|
VC6, VC7, VC7.1, C++Windows, NT4, Win2K, WinXP, Win2003, MFC, VS6, Visual Studio, Dev
Posted: 12 Jun 2003
Updated: 31 Aug 2003
Views: 86,947
Bookmarked: 23 times
|
|
|
|
|

Introduction
Nowadays dialog based applications are becoming more and more popular. To make my future development for dialog based application easier I worked out this CTabDialog, which operates like a Tab control, but gives you more chance to have your owner draw buttons and dialogs added. Hopefully CTabDialog will make your development of dialog based application easier.
Using the code
To use the class
- Include the class to your application
#include
"TabDialog.h"
- Add the
CTabDialog data member to your application: private:
CTabDialog* m_pTabDialog;
- In
OnInitDialog() of your application, initialize the CTabDialog
m_pTabDialog = new CTabDialog(IDD_TABDLG, this);
if (m_pTabDialog->Create(IDD_TABDLG, this) == FALSE)
return FALSE;
m_pTabDialog->SetWindowPos(this, rect.left, rect.top, 0 , 0,
SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
Note: you need to create a dialog resource for the CTabDialog control.
- You then need to add pages to the control
BOOL CTabDialogTestDlg::AddPagesToTabDialog()
{
m_pBtnOne = new CButton();
RECT rectOne;
rectOne.left = BTNONE_LOCATION.x;
rectOne.right = BTNONE_LOCATION.x+BUTTON_WIDTH;
rectOne.top = BTNONE_LOCATION.y;
rectOne.bottom = BTNONE_LOCATION.y+BUTTON_HEIGHT;
m_pBtnOne->Create("One", WS_CHILD | WS_VISIBLE | WS_TABSTOP, rectOne,
m_pTabDialog, BUTTON_ONE);
m_pPageOne = new CPageOneDlg(m_pTabDialog);
if (m_pPageOne->Create(IDD_PAGE_ONE, m_pTabDialog) == FALSE)
return FALSE;
m_pTabDialog->AddPage(m_pPageOne, m_pBtnOne);
m_pBtnTwo = new CButton();
RECT rectTwo;
rectTwo.left = BTNTWO_LOCATION.x;
rectTwo.right = BTNTWO_LOCATION.x+BUTTON_WIDTH;
rectTwo.top = BTNTWO_LOCATION.y;
rectTwo.bottom = BTNTWO_LOCATION.y+BUTTON_HEIGHT;
m_pBtnTwo->Create("Two", WS_CHILD | WS_VISIBLE | WS_TABSTOP, rectTwo,
m_pTabDialog, BUTTON_TWO);
m_pPageTwo = new CPageTwoDlg(m_pTabDialog);
if(m_pPageTwo->Create(IDD_PAGE_TWO, m_pTabDialog) == FALSE)
return FALSE;
m_pTabDialog->AddPage(m_pPageTwo, m_pBtnTwo);
m_pBtnThree = new CButton();
RECT rectThree;
rectThree.left = BTNTHREE_LOCATION.x;
rectThree.right = BTNTHREE_LOCATION.x+BUTTON_WIDTH;
rectThree.top = BTNTHREE_LOCATION.y;
rectThree.bottom = BTNTHREE_LOCATION.y+BUTTON_HEIGHT;
m_pBtnThree->Create("Three", WS_CHILD | WS_VISIBLE | WS_TABSTOP,
rectThree, m_pTabDialog, BUTTON_THREE);
m_pPageThree = new CPageThreeDlg(m_pTabDialog);
if(m_pPageThree->Create(IDD_PAGE_THREE, m_pTabDialog) == FALSE)
return FALSE;
m_pTabDialog->AddPage(m_pPageThree, m_pBtnThree);
return TRUE;
}
- You then need to call
InitPagesShow() member function of CTabDialog to set the default showing of the control.
m_pTabDialog->InitPagesShow();
| You must Sign In to use this message board. |
|
| | Msgs 1 to 17 of 17 (Total in Forum: 17) (Refresh) | FirstPrevNext |
|
|
 |
|
|
//create first button m_pBtnOne = new CButton(); RECT rectOne; rectOne.left = BTNONE_LOCATION.x; rectOne.right = BTNONE_LOCATION.x+BUTTON_WIDTH; rectOne.top = BTNONE_LOCATION.y; rectOne.bottom = BTNONE_LOCATION.y+BUTTON_HEIGHT;
m_pBtnOne->Create("One", WS_CHILD | WS_VISIBLE | WS_TABSTOP, rectOne, m_pTabDialog, BUTTON_ONE);
//create first dialog m_pPageOne = new CSuperCenter8Dlg(m_pTabDialog); if(m_pPageOne->Create(IDD_SUPERCENTER8_DIALOG, m_pTabDialog) == FALSE)// an { ASSERT(::IsWindow(m_hWnd)); ::GetWindowRect(m_hWnd, lpRect); } error occurs here. I change the IDD_SUPERCENTER8_DIALOG style as your demo project,but still get the error.So i come to you for help. tks in advance.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi Wang Yingwu, Thank You very much for this beautifull article. I tried to implement similar type of project. I got problem with set focus. For example, we have 3 edit boxes in the first page. We can set tab order by Ctrl+D. When appication runs the edit box for which we given order as 1 shoul get focus. But here in this application it is not happening. Can we solve this?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
I'm not be able to move the position of your button. If a chage the line in the testconstant.h
const CPoint BTNONE_LOCATION(0,0); const CPoint BTNTWO_LOCATION(0,0); const CPoint BTNTHREE_LOCATION(0,0);
nothing change, i can put any value and nothing change...
if a change const int BUTTON_WIDTH = 73; const int BUTTON_HEIGHT = 62; for other value, the button width and height change...
This is the same case if a change in the program the value of rectOne directly....
What happens, i clean and rebuild the project. //create first button m_pBtnOne = new CButton(); RECT rectOne; rectOne.left = BTNONE_LOCATION.x; rectOne.right = BTNONE_LOCATION.x+BUTTON_WIDTH; rectOne.top = BTNONE_LOCATION.y; rectOne.bottom = BTNONE_LOCATION.y+BUTTON_HEIGHT;
m_pBtnOne->Create("One", WS_CHILD | WS_VISIBLE | WS_TABSTOP, rectOne, m_pTabDialog, BUTTON_ONE);
fred
|
| Sign In·View Thread·PermaLink | 1.33/5 (3 votes) |
|
|
|
 |
|
|
 |
|
|
Chris was right - someone (me), some time (like now) will need this - and I do! Thank you again Yingwu!
Jerry
Always leap before you look ... it keeps life interesting!
|
| Sign In·View Thread·PermaLink | 2.00/5 (2 votes) |
|
|
|
 |
|
|
First, I would like to thank you, the article really give me a lot of idea. When I am using the, I want to change the tab page by programming without really clicking the buttons, but I failed, any suggestion?
|
| Sign In·View Thread·PermaLink | 2.00/5 (2 votes) |
|
|
|
 |
|
|
I also facing the same problem. I want my tab pages to behave like Project Settings in vc++. They should be navigabel using tab keys. If you have got the solution please reply to me.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
Thanks for your remind!
I have informed the web master about this, they are going to change the link.
--- Yingwu Wang Continuing study will bring you continuing growing.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
|
 |
|
|
There are serious memory leaks in this program:
BOOL CTabDialogTestDlg::InitTabDialog() { ... m_pTabDialog = new CTabDialog(IDD_TABDLG, this); // should be recycled. ... }
BOOL CTabDialogTestDlg::AddPagesToTabDialog() { ... CButton* pBtnOne = new CButton(); // should be recycled ... CPageOneDlg* pPageOne = new CPageOneDlg(m_pTabDialog); // should be recycled ... CButton* pBtnTwo = new CButton(); // should be recycled ... CPageTwoDlg* pPageTwo = new CPageTwoDlg(m_pTabDialog); // should be recycled ... CButton* pBtnThree = new CButton(); // should be recycled ... CPageThreeDlg* pPageThree = new CPageThreeDlg(m_pTabDialog); // should be recycled }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks for your correction.
I have updated the article today and sent over to the web master, they will update for me very soon I think.
Welcome for any other suggestion/recommendation.
how is it?
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
There is a use for everything, and somebody will find your sample useful at that right moment!
Good job, and keep aiming for bigger challenges.
William
Fortes in fide et opere!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
That's pretty much reflects my feelings on the article when it was submitted. Thinking back to some of the stuff I've written I thought "yep - someone, somewhere will need something like this".
cheers, Chris Maunder
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
The class has been developed as an introduction of the new framework, however, it seems to be too simple.
Thanks for the encouragement!
I will continue to work and hopefully post more useful and interesting article.
------ Wang Yingwu Study everyday, grow everyday!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
General News Question Answer Joke Rant Admin
|