- •The ministry of education and science of ukraine kharkiv national university of radio electronics
- •1. The Basics of Microsoft Foundation Classes
- •Mfc general information
- •A Framework of mfc-program
- •Creating the Application Class
- •Creating the Frame-Window Class
- •Declaring a Message Map and instantiation of application object global instance
- •Defining a Message Map
- •Messages and their processing in mfc-programs
- •Writing Message Map Functions
- •Message boxes and menus in mfc-programs
- •2. Dialog windows
- •2.1 Modal and modeless dialog windows
- •2.2 The control elements of dialog window
- •CListBox::AddString (lpctstr lpszItem ); // Call this member function to add a string (lpszItem) to a list box;
- •3. Additional control elements in mfc-programs. Working with icons, cursors, raster images
- •3.1 Additional control elements
- •Radio buttons
- •Afx_msg void cWnd::OnVScroll( uint nSbCode, uint nPos, cScrollBar* pScrollBar ); afx_msg void cWnd::OnHScroll( uint nSbCode, uint nPos, cScrollBar* pScrollBar );
- •Afx_msg void OnVScroll( uint nSbCode, uint nPos, cScrollBar* pScrollBar );
- •Working with icons, cursors, raster images
- •The icons and cursor registration
- •Icon and cursor loading
- •4. The elements of text processing in mfc
- •The redrawing problem decision
- •5. The Elements of working with graphics
- •5.1 The graphics functions.
- •Working with brushes
- •5.2 The mapping modes and output regions
- •6. Common control elements
- •Windows Common Controls
- •6.2 The toolbar using
- •On resizing, the message wm_size is sent and the standard handler OnSize() is called.
- •The working with Spins
- •The working with slider
- •To set the range (minimum and maximum positions) for the slider in a slider control use the following function:
- •The working with progress bar
- •The tree control using in mfc programs
- •Adding elements to the tree
- •The status bars usage
- •Bool cStatusBarCtrl::SetParts( int nParts, int* pWidths );
- •Tab controls using in mfc-programs
- •Int cTabCtrl::GetCurSel(); To Selects a tab in a tab control use SetCurSel() function:
- •Int cTabCtrl::SetCurSel( int nItem );
- •The property sheets and wizards
- •7. Thread multitasking and it’s implementation in mfc
- •7.1 The basic features of multitasking
- •7.2 The Synchronization
- •7.3 The working with semaphore
- •7. 4 The working with event object
- •8. The concept of Document view
- •8.1 Introduction to document conception
- •The control of documents storing
- •8.2 The dynamic creation of objects
- •The application framework creation
- •The main window and application classes creation
- •Listing 8.1 The example of main window class in Document / View concept
- •Listing 8.2 The example of document class in Document / View concept
- •8.3 The document framework creation
- •8.4 The initiation of application
- •8.5 The standard id’s, used in Document / View concept
- •9. The special types of menu and their implementation in mfc
- •9.1 The description of special menu styles
- •The mechanism to make changes in menus
- •9.2 The dynamic and floating menus implementation
- •CMenu::CreatePopupMenu
- •The example programs to work with dynamic menus
- •10. The system of help
- •10.1 The basic information on help structures
- •The call of help
- •The file of help
- •The Help file creating
- •The example of rtf file
- •10.2 The Help system including to the mfc-program
- •Parameters:
- •Return Values: If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.
- •10.3 The handlers of help messages
- •The processing of help calls
- •Wm_commandhelp message processing
- •10.4 Wm_contextmenu message processing
- •11. Manipulating Device-Independent Bitmaps
- •11.1 The types of bitmap
- •11.2 The structures included to bitmap
- •Introducing the cDib Class
- •11.3 Programming the cDib Class
- •Loading a dib into Memory
- •Other cDib Member Functions
- •Creating ShowDib program
- •Modifying ShowDib's Resources
- •Adding Code to ShowDib
- •Examining the OnFileOpen() Function
- •Examining the OnDraw() Function
- •12. The elements of Database Programming
- •12.1 Understanding Database Concepts
- •Accessing a Database
- •12.2 Mfc odbc Classes
- •Registering the Database
- •Creating the Basic Employee Application
- •Creating the Database Display
- •Adding and Deleting Records
- •12.4 Sorting and Filtering
- •12.5 Odbc versus dao
- •13. Remote Automation
- •13.1 The introduction to Remote Automation
- •13.2 The Remote Automation Connection Manager and user components
- •13.3 Automation
- •Automation Clients
- •13.4 ActiveX
- •ActiveX Document Servers
- •ActiveX Document Containers
- •ActiveX Document Views
- •13.5 ActiveX Documents
- •ActiveX Controls
- •Interaction Between Controls with Windows and ActiveX Control Containers
- •13.6 Optimization of ActiveX Controls
- •13.7 Automation Servers
- •13.8 Connection Points
- •14. Microsoft DirectX and the main items of its using
- •14.2 The Component Object Model
- •IUnknown Interface
- •DirectX com Interfaces
- •DirectDraw Architecture
- •Other DirectDraw Features
- •Width and Pitch
- •14.5 Support for 3d Surfaces in DirectX
- •14.6 Direct3d Integration with DirectDraw
- •Direct3d Device Interface
- •Direct3d Texture Interface
- •The Basics of DirectDraw
- •Step 6: Writing to the Surface.The first half of the wm_timer message in ddex1 is devoted to writing to the back buffer, as shown in the following example:
- •Loading Bitmaps on the Back Buffer
- •Step 1: Creating the Palette. The ddex2 sample first loads the palette into a structure by using the following code:
- •Step 4: Flipping the Surfaces. Flipping surfaces in the ddex2 sample is essentially the same process as that in the first example. Blitting from an Off-Screen Surface
- •Step 1: Creating the Off-Screen Surfaces. The following code is added to the doInit function in ddex3 to create the two off-screen buffers:
- •Color Keys and Bitmap Animation
- •Dynamically Modifying Palettes
- •Optimizations and Customizations
- •Blitting with Color Fill
- •Determining the Capabilities of the Display Hardware
- •Storing Bitmaps in Display Memory
- •Triple Buffering
- •15. General information on OpenGl
- •15.1 Common information
- •Primitives and Commands
- •OpenGl Graphic Control
- •Execution Model
- •15.2 Basic OpenGl Operation
- •OpenGl Correctness Tips
- •15.3 OpenGl example program
- •Ph.D. Assosiate prof. Tsimbal Alexander m. System software, summary of lectures.
Int cTabCtrl::GetCurSel(); To Selects a tab in a tab control use SetCurSel() function:
Int cTabCtrl::SetCurSel( int nItem );
Here, nItem The zero-based index of the item to be selected.
A tab control does not send a TCN_SELCHANGING or TCN_SELCHANGE notification message when a tab is selected using this function. These notifications are sent, using WM_NOTIFY, when the user clicks or uses the keyboard to change tabs.
To retrieve information about a tab in a tab control, use GetItem() function:
BOOL CTabCtrl::GetItem( int nItem, TC_ITEM* pTabCtrlItem ) const;
nItem Zero-based index of the tab.
pTabCtrlItem Pointer to a TC_ITEM structure, used to specify the information to retrieve. Also used to receive information about the tab. This structure is used with the InsertItem, GetItem, and SetItem member functions.
To calculate a tab control's display area given a window rectangle, or calculate the window rectangle that would correspond to a given display area use AdjustRect() function.
void CTabCtrl::AdjustRect( BOOL bLarger, LPRECT lpRect );
Parameters:
bLarger Indicates which operation to perform. If this parameter is TRUE, lpRect specifies a display rectangle and receives the corresponding window rectangle. If this parameter is FALSE, lpRect specifies a window rectangle and receives the corresponding display rectangle.
lpRect Pointer to a RECT structure that specifies the given rectangle and receives the calculated rectangle.
The Tab Control messages
On Tab Controls activation, to the WM_NOTIFY message there are linked three codes:
TCN_SELCHANGE - notifies a tab control’s parent window that the currently selected tab is about to change.
TCN_SELCHANGING - notifies a tab control’s parent window that the currently selected tab is about to change.
TCN_KEYDOWN - notifies a tab control’s parent window that a key has been pressed.
The messages are processed by macro command ON_NOTIFY().
The property sheets and wizards
A property sheet is a special kind of dialog box that is generally used to modify the attributes of some external object, such as the current selection in a view. The property sheet has three main parts: the containing dialog box, one or more property pages shown one at a time, and a tab at the top of each page that the user clicks to select that page. Property sheets are useful for situations where you have a number of similar groups of settings or options to change. An example of a property sheet is the Project Settings dialog box in the integrated development environment. In this case, there are a number of different groups of options that need to be set. The property sheet allows a large amount of information to be grouped in an easily understood fashion.
Objects of class CPropertyPage represent individual pages of a property sheet, otherwise known as a tab dialog box. As with standard dialog boxes, you derive a class from CPropertyPage for each page in your property sheet. To use CPropertyPage-derived objects, first create a CPropertySheet object, and then create an object for each page that goes in the property sheet. Call CPropertySheet::AddPage for each page in the sheet, and then display the property sheet by calling CPropertySheet::DoModal for a modal property sheet, or CPropertySheet::Create for a modeless property sheet.
For the property sheets use #include <afxdlgs.h> preprocessor directive.
You can create a type of tab dialog box called a wizard, which consists of a property sheet with a sequence of property pages that guide the user through the steps of an operation, such as setting up a device or creating a newsletter. In a wizard-type tab dialog box, the property pages do not have tabs, and only one property page is visible at a time. Also, instead of having OK and Apply Now buttons, a wizard-type tab dialog box has a Back button, a Next or Finish button, and a Cancel button.
To use a property sheet in your application, complete the following steps:
Create a dialog template resource for each property page. Keep in mind that the user may be switching from one page to another, so lay out each page as consistently as possible.
The dialog templates for all pages do not have to be the same size. The framework uses the size of the largest page to determine how much space to allocate in the property sheet for the property pages.
When you create the dialog template resource for a property page, you must specify the following styles in the Dialog Properties property sheet:
Set the Caption edit box on the General page to the text you wish to appear in the tab for this page.
Set the Style list box on the Styles page to Child.
Set the Border list box on the Styles page to Thin.
Ensure that the Titlebar check box on the Styles page is selected.
Ensure that the Disabled check box on the More Styles page is selected.
Use ClassWizard to create a CPropertyPage-derived class corresponding to each property page dialog template. To do this, choose ClassWizard from the View menu while the focus is on a particular property page dialog box. Choose CPropertyPage as the base class in ClassWizard.
Using ClassWizard, create member variables to hold the values for this property page. The process for adding member variables to a property page is exactly the same as adding member variables to a dialog box, because a property page is a specialized dialog box.
Construct a CPropertySheet object in your source code. Usually, you construct the CPropertySheet object in the handler for the command that displays the property sheet. This object represents the entire property sheet. If you create a modal property sheet with the DoModal function, the framework supplies three command buttons by default: OK, Cancel, and Apply. The framework creates no command buttons for modeless property sheets created with the Create function. You do not need to derive a class from CPropertySheet unless you want to either add other controls (such as a preview window) or display a modeless property sheet. This step is necessary for modeless property sheets because they do not contain any default controls that could be used to close the property sheet.
For each page to be added to the property sheet, do the following:
Construct one object for each CPropertyPage-derived class that you created using ClassWizard earlier in this process.
Call CPropertySheet::AddPage for each page.
Typically, the object that creates the CPropertySheet also creates the CPropertyPage objects in this step. However, if you implement a CPropertySheet-derived class, you can embed the CPropertyPage objects in the CPropertySheet object and call AddPage for each page from the CPropertySheet-derived class constructor. AddPage adds the CPropertyPage object to the property sheet's list of pages but does not actually create the window for that page. Therefore, it is not necessary to wait until creation of the property sheet window to call AddPage; you can call AddPage from the property sheet's constructor.
Call CPropertySheet::DoModal or Create to display the property sheet. Call DoModal to create a property sheet as a modal dialog box. Call Create to create the property sheet as a modeless dialog box.
Exchange data between property pages and the owner of the property sheet.
To establish a property page as a wizard call CPropertySheet::SetWizardMode(). Call SetWizardMode before calling DoModal. After you call SetWizardMode, DoModal will return either ID_WIZFINISH (if the user closes with the Finish button) or IDCANCEL.
SetWizardMode sets the PSF_WIZARD flag.
On Pic. 6.2 There is the interface view for program with different control elements.
Pic 6.2. The view of control elements for listing 6.4.
Listing 6.4 the example program with common control elements
// t1.h: interface for the cmain class.
Class CMain : public CFrameWnd
{public:
void OnTab();
void OnTreeThange(NMHDR *hdr, lresult *notused);
void OnPaint();
void OnExpand();
void OneExpandAll();
void OnCollapse();
void InitTree();
void OnDialog();
void OnTtip(UINT idnotused, NMHDR *hdr,lresult *resultnotused);
void InitToolBar();
void OnExit();
CMain();
declare_message_map()
Private:
CTreeCtrl m_tree;
CToolBarCtrl m_tb;
};
Class CApp : public CWinApp
{public:
BOOL InitInstance();
};
Class CSDialog : public CDialog
{public:
void OnTabChange();
void OnNodeDelete();
void OnaAddNode();
void OnTreeChange(nmhdr *hdr,lresult *notused);
void OnPaint();
void InitTree();
void OnHScroll(uint sbcode,uint pos, CScrollBar *sb);
void OnVScroll(uint sbcode,uint pos, CScrollBar *sb);
bool OnInitDialog();
void OnTtip1(nmhdr *hdr,lresult *result);
csdialog(uint id,cwnd *owner):cdialog(id,owner){}
declare_message_map()
Private:
cstatusBarCtrl m_status;
cbutton *bt2;
cedit *edd2;
cbutton *bt1;
cedit *edd;
ctreeCtrl *tr;
cprogressctrl *pc;
csliderCtrl *slay;
cspinbuttonctrl m_spin;
};
Class ctabdialog1 : public cdialog
{public:
bool OnInitDialog();
ctabdialog1():cdialog(){}
declare_message_map()
Private:
cedit *edd;
};
Class ctabdialog2 : public cdialog
{public:
bool oninitdialog();
ctabdialog2():cdialog(){}
declare_message_map()
Private:
cedit *edd;
};
Class ctabdialog3 : public cdialog
{public:
bool oninitdialog();
ctabdialog3():cdialog(){}
declare_message_map()
Private:
cedit *edd;
};
Class csdialog2 : public cdialog
{public:
void ontabChange();
bool onInitDialog();
csdialog2(uint id, cwnd *owner):cdialog(id,owner){}
declare_message_map()
Private:
ctabctrl *tbc;
};
// t1.cpp: implementation of the classes.
#include <afxwin.h>
#include <afxcmn.h>
#include "t1.h"
#include "resource.h"
#define NUMBUTTONS 6
#define IDC_SPIN1 400001
#define ID_TREE 400002
#define IDD_STATUS 400003
#define NUM 5
#define NUMPARTS 3
CMain::CMain()
{Create(NULL,"Tool bar & MFC", WS_OVERLAPPEDWINDOW, rectDefault, NULL, MAKEINTRESOURCE(IDR_MENU1));
InitCommonControls();
InitToolBar();
RECT r;
r.left=r.top=30;
r.right=220;r.bottom=200;
m_Tree.Create(WS_VISIBLE | WS_CHILD | WS_BORDER |
TVS_EDITLABELS | TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT,
r,this,ID_TREE);
InitTree();
}
BEGIN_MESSAGE_MAP(CMain,CFrameWnd)
ON_COMMAND(ID_FIRST_EXIT,OnExit)
ON_COMMAND(ID_DIALOG,OnDialog)
ON_COMMAND(ID_SECOND_MESSAGE,OnMessage)
ON_COMMAND(ID_TAB,OnTab)
ON_WM_PAINT()
ON_NOTIFY(TVN_SELCHANGED,ID_TREE,OnTreeChange)
ON_NOTIFY_RANGE(TTN_NEEDTEXT,0,IDR_TOOLBAR1,OnTTip)
ON_COMMAND(ID_TREE_EXPAND,OnExpand)
ON_COMMAND(ID_TREE_EXPANDALL,OnExpandAll)
ON_COMMAND(ID_TREE_COLLAPSE,OnCollapse)
END_MESSAGE_MAP()
BOOL CApp::InitInstance()
{m_pMainWnd = new CMain;
m_pMainWnd -> ShowWindow(m_nCmdShow);
m_pMainWnd -> UpdateWindow();
return TRUE;
}
void CMain::OnExit()
{SendMessage(WM_CLOSE);
}
CApp App;
void CMain::InitToolBar()
{RECT r;
r.left=r.top=r.right=r.bottom=0;
TBBUTTON tbButton[4];
m_TB.Create(WS_VISIBLE | WS_CHILD |
TBSTYLE_TOOLTIPS,r,this,
IDR_TOOLBAR1);
tbButton[0].iBitmap=0;
tbButton[0].idCommand=ID_FIRST_EXIT;
tbButton[0].fsState=TBSTATE_ENABLED;
tbButton[0].fsStyle=TBSTYLE_BUTTON;
tbButton[0].dwData=0;
tbButton[0].iString=0;
tbButton[1].iBitmap=1;
tbButton[1].idCommand=ID_SECOND_MESSAGE;
tbButton[1].fsState=TBSTATE_ENABLED;
tbButton[1].fsStyle=TBSTYLE_CHECKGROUP;
tbButton[1].dwData=0;
tbButton[1].iString=0;
tbButton[2].iBitmap=2;
tbButton[2].idCommand=0;
tbButton[2].fsState=TBSTATE_INDETERMINATE;
tbButton[2].fsStyle=TBSTYLE_CHECKGROUP;
tbButton[2].dwData=0;
tbButton[2].iString=0;
tbButton[3].iBitmap=3;
tbButton[3].idCommand=ID_SECOND_MESSAGE;
tbButton[3].fsState=TBSTATE_ENABLED;
tbButton[3].fsStyle=TBSTYLE_CHECK;
tbButton[3].dwData=0;
tbButton[3].iString=0;
m_TB.AddButtons(4,tbButton);
m_TB.AddBitmap(4,IDR_TOOLBAR1);
}
void CMain::OnTTip(UINT idNotUsed,NMHDR *hdr,LRESULT *ResultNotUsed)
{switch(hdr->idFrom)
{case ID_FIRST_EXIT:
((TOOLTIPTEXT *)hdr)->lpszText="Exit"; break;
case ID_SECOND_MESSAGE:
((TOOLTIPTEXT *)hdr)->lpszText="SECOND MESSAGE: all carriers Of United Kingdom are avaliable"; break;
}
}
void CMain::OnDialog()
{CSDialog a(IDD_DIALOG1,this);
a.DoModal();
}
BEGIN_MESSAGE_MAP(CSDialog,CDialog)
ON_NOTIFY(NM_SETFOCUS,IDOK,OnTTip1)
ON_WM_HSCROLL()
ON_NOTIFY(TVN_SELCHANGED,IDC_TREE1,OnTreeChange)
ON_WM_VSCROLL()
ON_WM_PAINT()
ON_COMMAND(IDC_BUTTON1,OnAddNode)
ON_COMMAND(IDC_BUTTON2,OnNodeDelete)
END_MESSAGE_MAP()
void CSDialog::OnTTip1(NMHDR *hdr,LRESULT *result)
{char str[255];
wsprintf(str,"%ld",hdr->idFrom);
CClientDC dc(this);
dc.TextOut(1,1,str,15);
*result=0;
}
BOOL CSDialog::OnInitDialog()
{RECT r;
int i;
int parts[NUMPARTS];
CDialog::OnInitDialog();
GetClientRect(&r);
m_Spin.Create(WS_VISIBLE | WS_CHILD | WS_BORDER | UDS_SETBUDDYINT | UDS_ALIGNRIGHT,
r,this,IDC_SPIN1);
slay=(CSliderCtrl*)GetDlgItem(IDC_SLIDER1);
bt1=(CButton*)GetDlgItem(IDC_BUTTON1);
edd2=(CEdit*)GetDlgItem(IDC_EDIT1);
bt2=(CButton*)GetDlgItem(IDC_BUTTON2);
pc=(CProgressCtrl*)GetDlgItem(IDC_PROGRESS1);
tr=(CTreeCtrl*)GetDlgItem(IDC_TREE1);
m_Spin.SetBuddy(GetDlgItem(IDC_EDIT2));
m_Spin.SetRange(0,100);
m_Spin.SetPos(5);
slay->SetRange(0,100);
slay->SetPos(15);
for(i=1;i<=NUMPARTS;i++)
parts[i-1]=r.right/NUMPARTS*i;
m_Status.Create(WS_VISIBLE | WS_CHILD,r,this,IDD_STATUS);
m_Status.SetParts(NUMPARTS,parts);
m_Status.SetText("Spin Ctrl: 10",0,0);
m_Status.SetText("Option 1 : ",1,0);
m_Status.SetText("Option 2 : 10",2,0);
InitTree();
return TRUE;
}
void CSDialog::OnHScroll(UINT SBCode, UINT Pos, CScrollBar * SB)
{if(SB==(CScrollBar *)slay)
{m_Spin.SetPos(slay->GetPos());
pc->SetPos(slay->GetPos());
char str3[40];
wsprintf(str3,"Slider position %d",slay->GetPos());
m_Status.SetText(str3,1,0);
}
}
void CSDialog::OnVScroll(UINT SBCode, UINT Pos, CScrollBar * SB)
{if(SB=(CScrollBar *)&m_Spin)
{slay->SetPos(m_Spin.GetPos());
pc->SetPos(m_Spin.GetPos());
char str3[40];
wsprintf(str3,"Spin position %d",m_Spin.GetPos());
m_Status.SetText(str3,2,SBT_POPOUT);
}
}
HTREEITEM hTreeCtrl[30];
HTREEITEM hTreeCurrent;
int i;
void CSDialog::InitTree()
{TV_INSERTSTRUCT tvs;
TV_ITEM tvi;
tvs.hInsertAfter=TVI_LAST;
tvi.mask=TVIF_TEXT;
tvi.pszText="One";
tvs.hParent=TVI_ROOT;
tvs.item=tvi;
hTreeCtrl[0]=tr->InsertItem(&tvs);
hTreeCurrent=hTreeCtrl[0];
tvi.pszText="Two";
tvs.hParent=hTreeCtrl[0];
tvs.item=tvi;
hTreeCtrl[1]=tr->InsertItem(&tvs);
tvi.pszText="Three";
tvs.hParent=hTreeCtrl[1];
tvs.item=tvi;
hTreeCtrl[2]=tr->InsertItem(&tvs);
tvi.pszText="Four";
tvs.hParent=hTreeCtrl[2];
tvs.item=tvi;
hTreeCtrl[3]=tr->InsertItem(&tvs);
tvi.pszText="Five";
tvs.hParent=hTreeCtrl[2];
tvs.item=tvi;
hTreeCtrl[4]=tr->InsertItem(&tvs);
}
void CSDialog::OnPaint()
{CPaintDC dc(this);
TV_ITEM tvi;
char str1[40];
char str2[40];
tvi.hItem = hTreeCurrent;
tvi.pszText = str1;
tvi.cchTextMax = sizeof(str1)-1;
tvi.mask=TVIF_TEXT | TVIF_HANDLE;
tr->GetItem(&tvi);
wsprintf(str2,"Current Selection %s",tvi.pszText);
dc.TextOut(2,120,str2,strlen(str2));
}
void CMain::InitTree()
{TV_INSERTSTRUCT tvs;
TV_ITEM tvi;
tvs.hInsertAfter=TVI_LAST;
tvi.mask=TVIF_TEXT;
tvi.pszText="One";
tvs.hParent=TVI_ROOT;
tvs.item=tvi;
hTreeCtrl[0]=m_Tree.InsertItem(&tvs);
hTreeCurrent=hTreeCtrl[0];
tvi.pszText="Two";
tvs.hParent=hTreeCtrl[0];
tvs.item=tvi;
hTreeCtrl[1]=m_Tree.InsertItem(&tvs);
tvi.pszText="Three";
tvs.hParent=hTreeCtrl[1];
tvs.item=tvi;
hTreeCtrl[2]=m_Tree.InsertItem(&tvs);
tvi.pszText="Four";
tvs.hParent=hTreeCtrl[2];
tvs.item=tvi;
hTreeCtrl[3]=m_Tree.InsertItem(&tvs);
tvi.pszText="Five";
tvs.hParent=hTreeCtrl[2];
tvs.item=tvi;
hTreeCtrl[4]=m_Tree.InsertItem(&tvs);
i=5;
}
void CSDialog::OnAddNode()
{if(!tr->GetSelectedItem())
MessageBox("Node isn't selected","");
else {i++;
char str[20];
edd2->GetWindowText(str,sizeof(str));
if(strlen(str))
{ hTreeCurrent=tr->GetSelectedItem();
TV_INSERTSTRUCT tvs;
TV_ITEM tvi;
tvs.hInsertAfter=TVI_LAST;
tvi.mask=TVIF_TEXT;
tvi.pszText=str;
tvs.hParent=hTreeCurrent;
tvs.item=tvi;
hTreeCtrl[i]=tr->InsertItem(&tvs);
hTreeCurrent=hTreeCtrl[i];
InvalidateRect(NULL);
}
else MessageBox("You should set unzero name ","");
}
}
void CMain::OnTreeChange(NMHDR * hdr, LRESULT * NotUsed)
{hTreeCurrent = m_Tree.GetSelectedItem();
InvalidateRect(NULL);
}
void CSDialog::OnTreeChange(NMHDR * hdr, LRESULT * NotUsed)
{hTreeCurrent = tr->GetSelectedItem();
InvalidateRect(NULL);
}
void CSDialog::OnNodeDelete()
{if(!tr->GetSelectedItem())
MessageBox("Node isn't selected","");
else {hTreeCurrent=tr->GetSelectedItem();
if(!tr->GetParentItem(hTreeCurrent))
MessageBox("You can't delete the root","");
else
{tr->DeleteItem(hTreeCurrent);
i--;
hTreeCurrent=hTreeCtrl[i--];
InvalidateRect(NULL);
}
}
}
void CMain::OnPaint()
{CPaintDC dc(this);
TV_ITEM tvi;
char str1[40];
char str2[40];
tvi.hItem = hTreeCurrent;
tvi.pszText = str1;
tvi.cchTextMax = sizeof(str1)-1;
tvi.mask=TVIF_TEXT | TVIF_HANDLE;
m_Tree.GetItem(&tvi);
wsprintf(str2,"Current Selection %s",tvi.pszText);
dc.TextOut(2,350,str2,strlen(str2));
}
void CMain::OnExpand()
{m_Tree.Expand(hTreeCurrent,TVE_EXPAND);
}
void CMain::OnExpandAll()
{int i;
for(i=0;i<NUM;i++)
{m_Tree.Expand(hTreeCtrl[i],TVE_EXPAND);}
}
void CMain::OnCollapse()
{m_Tree.Expand(hTreeCurrent,TVE_COLLAPSE);
}
CTabDialog1 DiagOb1;
CTabDialog2 DiagOb2;
CTabDialog3 DiagOb3;
CDialog *CurDialog;
BOOL CTabDialog1::OnInitDialog()
{CDialog::OnInitDialog();
edd=(CEdit*)GetDlgItem(IDC_EDIT1);
CClientDC dc(this);
dc.TextOut(0,0,"Invincible",20);
return TRUE;
}
BOOL CTabDialog2::OnInitDialog()
{CDialog::OnInitDialog();
edd=(CEdit*)GetDlgItem(IDC_EDIT1);
CClientDC dc(this);
dc.TextOut(10,40,"Illustrious",20);
return TRUE;
}
BOOL CTabDialog3::OnInitDialog()
{CDialog::OnInitDialog();
edd=(CEdit*)GetDlgItem(IDC_EDIT1);
CClientDC dc(this);
dc.TextOut(10,40,"Arc Royal",20);
return TRUE;
}
void CSDialog2::OnTabChange()
{ char str[30];
wsprintf(str,"Selected tab: %d",tbc->GetCurFocus());
CClientDC dc(this);
if(CurDialog)CurDialog->DestroyWindow();
dc.TextOut(0,0,str);
switch(tbc->GetCurSel())
{case 0: DiagOb1.Create(IDD_DIALOG3,this);
CurDialog=&DiagOb1;
break;
case 1: DiagOb2.Create(IDD_DIALOG4,this);
CurDialog=&DiagOb2;
break;
case 2: DiagOb3.Create(IDD_DIALOG5,this);
CurDialog=&DiagOb3;
break;
}
}
BEGIN_MESSAGE_MAP(CTabDialog1,CDialog)
END_MESSAGE_MAP()
BEGIN_MESSAGE_MAP(CTabDialog2,CDialog)
END_MESSAGE_MAP()
BEGIN_MESSAGE_MAP(CTabDialog3,CDialog)
END_MESSAGE_MAP()
BEGIN_MESSAGE_MAP(CSDialog2,CDialog)
ON_NOTIFY(TCN_SELCHANGING,IDC_TAB1,OnTabChange)
END_MESSAGE_MAP()
BOOL CSDialog2::OnInitDialog()
{CDialog::OnInitDialog();
tbc=(CTabCtrl*)GetDlgItem(IDC_TAB1);
TC_ITEM tci;
tci.mask=TCIF_TEXT;
tci.iImage=-1;
tci.pszText="Invincible";
tbc->InsertItem(0,&tci);
tci.pszText="Illustrious";
tbc->InsertItem(1,&tci);
tci.pszText="Arc Royal";
tbc->InsertItem(2,&tci);
CurDialog=&DiagOb1;
DiagOb1.Create(IDD_DIALOG3,this);
return TRUE;
}
void CMain::OnTab()
{CSDialog2 a(IDD_DIALOG2,this);
a.DoModal();
}
