vc++_2
-
Upload
sbalajisathya -
Category
Documents
-
view
214 -
download
0
Transcript of vc++_2
-
7/28/2019 vc++_2
1/41
VC++
Splitter Windows & DLL
-
7/28/2019 vc++_2
2/41
Splitter Window
A frame window splitted into several view panes
Class: CSplitterWnd
Types:
1. Static splitter window(it can split the window atthe time of window is created, after splitting we
cannot change the size of the window)2. Dynamic splitter window(split the window atany time ,after splitting we can change the sizeof the window also)
-
7/28/2019 vc++_2
3/41
CsplitterWnd Methods..
Bool CreateStatic (
Cwnd *parentwnd,// parent frame window
Int rows,//number of rows
Int cols, //no of cols
);
This method is used to create static splitterwindow
-
7/28/2019 vc++_2
4/41
CSplitterWnd methods
Bool create(
Cwnd* parentwnd,//parent frame window
Int rows, //no of rows
Int cols,//no of cols
Size s, //size of the paneCcreatecontext * p
//str variable it hold cruntime class member
Which is responsible for dynamic splitting
);
This method used to create dynamic splitter window
-
7/28/2019 vc++_2
5/41
Steps: Dynamic splitter window
-
7/28/2019 vc++_2
6/41
Select advanced button
-
7/28/2019 vc++_2
7/41
Enable use split window option in window style tab
-
7/28/2019 vc++_2
8/41
View menu split option added use it.
Drag the adjust the size of the window
-
7/28/2019 vc++_2
9/41
MainFrm.cpp -
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
CCreateContext* pContext)
{
return m_wndSplitter.Create(this,//main window
2, //adjust row2, //adjust col
CSize(10, 10), //adjust size of the pane
pContext //ccreatecontext str var
);
}
If we want to add any text to the window add text to theondrawmethod present in the view.cpp class file
-
7/28/2019 vc++_2
10/41
Dynamic linked library
Library
1.Static library
In the linking file linked with all associated
library file and create a executable file withlinked libraries (before loading into thememory all libraries are linked)
2.Dynamic libraryAt the time loading into the memory the library
will be linked
-
7/28/2019 vc++_2
11/41
Dynamic Linked Libraries
DLL program(MFC app wizard dll)
create dll file
Another program (MFC app wizard exe)
- use that dll file in the dialog or other appln
-
7/28/2019 vc++_2
12/41
DLL
Dll program..
A MFC dll program can export a methods ,variables class methods, class variables into dll file
Mark the function prototype ( if it is class function constructor and destructor also marked)usingdll export directive
__declspec(dllexport) export directive marked as a function that are exported into dll file
Ex:
__declspec(dllexport)intadd(int a,int b);
The directive should be added before the function prototype..
Execute dll program.. It will produce dll file and lib file in debug folder.
Copied into folder in which program we can use the dll file
-
7/28/2019 vc++_2
13/41
Dll
Program1:
Dll program generate Dll file & lib fileProgram2:
copied dll file into that debug folder and
use it
-
7/28/2019 vc++_2
14/41
Program1: create dll
-
7/28/2019 vc++_2
15/41
Select regular dll using shared mfc dll
-
7/28/2019 vc++_2
16/41
Insert->new class->Create generic class
In this program we export class method and variables..so add our user defined class
-
7/28/2019 vc++_2
17/41
Add method and member variable
Add dll di i h f i
-
7/28/2019 vc++_2
18/41
Add dll export directive to the function
prototype
-
7/28/2019 vc++_2
19/41
Implement the function
E t f ti ill b t d
-
7/28/2019 vc++_2
20/41
Execute program function will be exported
in the dll file(debug folder)
-
7/28/2019 vc++_2
21/41
Program2:
-
7/28/2019 vc++_2
22/41
Add components to that form
-
7/28/2019 vc++_2
23/41
Cont..
1.place the dll and library file to that diloag programdebug folder
2. place class header file area.h(copied from dllprogram) place it to dialog program folder(avoidcompilation error)
3.Add header file info dlg.h
#include area.h
4 P j t > tti >li k t b > t t/lib
-
7/28/2019 vc++_2
24/41
4.Project ->settings->link tab->output/lib
modules(add lib file path)
-
7/28/2019 vc++_2
25/41
Call the dll function use it
void CTestclientDlg::OnButton1()
{
// TODO: Add your control notification handler code here
UpdateData(true);
Carea obj; // we invoke class method so we need to create object
//rad and result are dialog variables
result=obj.circle_area(rad);
UpdateData(false);
}
-
7/28/2019 vc++_2
26/41
Database access through odbc
MFC Class used :
CrecordSet Cdatabase
-
7/28/2019 vc++_2
27/41
Crecordset methods
Add new()
Edit()
Update()
Delete()
Moveprev()
Movenext()
Movelast()
Movefirst()
-
7/28/2019 vc++_2
28/41
Cdatabase
Crecordset(
Cdatabase *pdatabase=NULL;
)
BeginTrans();
Executesql(string sql query);
Committrans()
Rollback()
-
7/28/2019 vc++_2
29/41
Cont..
Create msaccess database file
Use obcdad32 assign dsn name for that
Two columns
Table name book
Bname,cost
-
7/28/2019 vc++_2
30/41
Use app wizard
-
7/28/2019 vc++_2
31/41
Select sdi and doc view architecture
-
7/28/2019 vc++_2
32/41
Select database view with file support
Selet datasource button add table using
-
7/28/2019 vc++_2
33/41
Selet datasource button add table using
odbc dsn name
Following table member will be added
-
7/28/2019 vc++_2
34/41
Following table member will be added
automatically we can use it(..set.h)
Cdbaseset object also created inView h
-
7/28/2019 vc++_2
35/41
Cdbaseset object also created inView.h
we use it..
-
7/28/2019 vc++_2
36/41
Add
Add(){
Updatedata(true);
M_pset->addnew();
M_pset->m_bname=val1
M_pset->cost=val2;
M_pset->update();
}
-
7/28/2019 vc++_2
37/41
edit
edit(){
Updatedata(true);
M_pset->edit();
M_pset->m_bname=val1
M_pset->cost=val2;
M_pset->update();
}
-
7/28/2019 vc++_2
38/41
delete
delete(){
Updatedata(true);
M_pset->delete(); M_pset->m_bname=val1
M_pset->cost=val2;
}
-
7/28/2019 vc++_2
39/41
movefirst
movefirst(){
M_pset->movefirst();
Val1=M_pset->m_bname;
Val2=M_pset->cost;
UpdateData(false);
}
Similar way prev,next,last
-
7/28/2019 vc++_2
40/41
Execute sql
Sql(){
M_pset->m_pdatabase->begintrans();
M_pset->m_pdatabase->executesql(insert
into book values(java,100));
M_pset->m_pdatabase->committrans();
M_pset->m_pdatabase->rollback();//catchblock use it for undo
}
-
7/28/2019 vc++_2
41/41