VC++ Dialog Application

Trace() send the debug message to the debug window Assert(bool) evaluates it argument ,if it is false diagnostic error message displayed Assert valid(object) evaluates it object ,if it is null diagnostic error message displayed(run time object state)

Failed dialog box .

var STRUCTURE • MFC structure names in Full caps • Ex: LOGFONT.MFC Naming Conventions CLASS MFC class names start with ‘C’ CXXXX Ex:Cfile.COLORREF METHOD Initial letter of the method name also having caps (not like java) Ex:WriteString() .CDialog MEMBER VARIABLE • MFC Variable always starts with m_xxx • User defined variable no need to start with m_ Ex:m_var.

} . Byte blue. Byte green.MFC Structures… Struct COLORREF{ Byte red.

}. int nEscapement. int nWidth. BYTE nClipPrecision. BYTE cStrikeOut. BYTE nCharSet. . BYTE bUnderline. int nOrientation. BYTE nPitchAndFamily. BYTE nQuality. int nWeight. BYTE bItalic. String lpszFacename. BYTE nOutPrecision.MFC Structures… Struct LOGFONT{ int nHeight.

CWnd::UpdateData() • UpdateData(true). • Validate or update the dialog data . Retrive dialog data • UpdateData(false).

menu and etc are called resource • Every dialog control component have names(caption and id) • Id will be used more for run time dialog controls (ex: IDC_EDIT) • Control id is a integer value • Int id=IDC_EDIT .Dialog controls • Dialog.

..CWnd* GetDlgItem(control id) Ex: CEdit* e=(CEdit*)GetDlgItem(IDC_EDIT) And then call the methods with object and use it.Runtime control We can access the controls via control object created using application wizard or get the control object reference using the method 1.

Control component Object .

int){ • //change the color for resource control • //If we want to change color for particular dialog controls like edit box1(IDC_EDIT1) • //use getdlgctrlid method //Ex: Int id=w->GetDlgCtrlID().WM_CTLCOLOR • Wm_ctlcolor is a window message.cwnd* w. If(id==IDC_EDIT1){ //logic } } .it will be used to change the color of the components • OnCtlcolor(cdc *.

Class Hierarchy Cobject | CWnd | CDialog .

CFileDialog Etc.invoked using DoModal method . Modelless dialog Modal dialog are easy.MFC Dialog Dialog Modal dialog Ex: 1.CFileDialog 4.Dialog based Application 2.CFontDialog 3.

d. File save dialog Ex: CFileDialog d(false).CFileDialog  Constructor is overloaded and it work differently Fileopendialog Ex: CFileDialog d(true). d.DoModal().DoModal(). .

• It return the selected file name in the file dialog • Cstring GetPathName(). • It return the selected file name with full path in the file dialog .CFileDialog Methods.. • Cstring GetFileName().

Using onctlcolor method to change the color of the controls Note: Rgb method also return the colorref .CColorDialog Ex: CColorDialog d.DoModal(). D. Methods: COLORREF GetColor().

Method: GetCurrentFont(LOGFONT) This method fill the log font structure member values. //LOGFONT lf. .CFontDialog Ex: CFontDialog d.DoModal().. d.

Change Font… • Using logfont value use either one of the font creating method and create a font object and use it. • Cfont CreateFontIndirect(LOGFONT) • Or • Cfont CreatePointFontIndirect(LOGFONT) .

1.cstdiofile). • File handling done with to mfc classes(cfile..Cfile Member variables • Cfile::modeRead • Cfile::modeWrite • Cfile::modeCreate .File Handling in MFC..

int falg members. Methods: Open(string file. } .CStdioFile • • • • Ex: CStdioFile f.exception) Exception CFileException CException Try{} Catch(Cexception *e){ e->ReportError().

//for reading a file • Open(“abc.Cfile::modeRead.CFileExceptio n e). • F..writeString(line).Open(“abc. • F.//for reading a file • F.txt”.ReadString(line).CStdioFile.Cfile::modeWrite.txt”.//for writing a file .CFileExcepti on e).//for writing a file Methods: • Cstring line.

CEdit Methods. • • • • • • Void cut() Void copy() Void paste() Void clear() Bool undo() Void SetSel(int end) .

. • SetFont(CFont) .CEdit.

SetMenu(&menu1).CMenu • Add menu bar to the dialog • Normally two ways . .one is run time code another use property window. menu1. CMenu menu1.LoadMenu(IDR_MENU1)..