|
MFC的DLL可以办到!但是你要在UG里运行的话最好是UIStyler结合上MFC,MFC调用ACCESS! L& q' W* f4 m4 {& | o
下面是部分代码:(我这是一套的,代码很多也很杂,给你下面部分)0 ?# _3 O! P* K7 {3 E9 p% Q
BOOL Database_main::OnInitDialog()
: p* q. g0 t0 T. D8 D5 y/ O- [" z: e; ?{2 b& d, ~6 s6 J/ Y
CDialog::OnInitDialog();
$ Z' b! t* L8 I$ B 2 G* ?$ p/ X3 n2 v
// TODO: Add extra initialization here
3 l3 k% W: S3 B' e! o% V8 X- u try{
/ ?# s0 G; i/ C8 A& r m_pdatabase=new CDatabase();) C* A7 ^. J/ u1 x X
m_pset=new CRecordset();3 F) b! I* o1 X1 Z
m_pdatabase->Open(_T("data"),FALSE,FALSE,_T("ODBC;DSN=data"),FALSE);
& U# m. z3 l+ e& k, u X5 W+ l m_pset->m_pDatabase=m_pdatabase;
$ N# s8 n( F. R }/ e) c( c5 f, s* G$ d: t: ^# o
catch(CDBException* e){
+ }0 E; g) N$ f5 W$ h; I" B e->ReportError();
7 h Q e; F, q* ` e->Delete();
) b+ H6 T7 h$ O delete m_pset;& n( x/ D; U; ~/ L; s
delete m_pdatabase;: @4 \3 k6 U. f) f: F; P) }
return TRUE;}9 A: M9 f( V' x+ w9 c1 o
DataShow("data");
9 ?" ^+ Y+ y1 A& D# J return TRUE; // return TRUE unless you set the focus to a control
) F' s0 x8 G4 _0 F6 j // EXCEPTION: OCX Property Pages should return FALSE: E" D9 H' ]6 S! [+ D! C
}
: y, N% p, o+ {9 |1 Y
5 j/ g# A1 l$ a1 {* }# Zvoid Database_main::OnOK() 5 ]" W1 f1 ]6 J l
{
+ P. ]! z0 j/ A% o/ I // TODO: Add extra validation here
$ B, u" m, ?4 `' |; x UINT uSelectedCount=m_list_control.GetSelectedCount();( g! {' e$ q" i5 O7 u6 d5 F
int nItemSel=0;
4 W0 @9 B& _1 K nItemSel=m_list_control.GetNextItem(nItemSel-1,LVNI_SELECTED);+ m* k3 S& j# T( D2 |: f
for(int j=0;j<nFieldCount;j++)
" \/ U, P: V5 J( j/ T7 b str[j]=m_list_control.GetItemText(nItemSel,j);. p4 ?* l/ y. I) \- f
}9 C8 V( @! H# f
B c: Q" \0 s7 k' V( H
3 K% v6 s' u6 U; G" e+ c7 a0 u. V) ] n' T
% [% B5 K4 \/ u0 ]- |9 I
CDialog::OnOK();/ @9 q1 t7 S' Q$ T2 S
}1 F; \! W4 K5 f0 y l
0 ^4 y( E4 Z$ E* [6 G8 M
void Database_main::ClearList()9 W1 Y. I2 D, D
{
! b' r" n. h9 P! A: Y //m_list_control.SetExtendedStyle(LVS_EX_FULLROWSELECT);
8 b7 a4 }3 n: {, }- ?' \ //m_list_control.SetExtendedStyle(LVS_EX_GRIDLINES);
d1 ]( Z. a) c% [7 Z- A* X m_list_control.DeleteAllItems();% q# ^$ j; k0 h) g! `+ x5 ]
while(m_list_control.DeleteColumn(0));
: |0 |4 t( ^' L! J UpdateWindow();
- T& i. F7 L0 ~8 V}
0 {, C6 P8 y) _* O8 W# j$ _//////////////////////////////////////////////////////////////////////////////////// h7 A6 p+ V/ o* \9 ~! f
void Database_main:ataShow(CString table_name)6 m" y! O; E7 L* v% |% }' g
{
% Y" c+ @. g1 h& M$ F+ [ ClearList();5 b' k! z ]: }8 c2 V
CString strSQL;
0 U# d1 s: @' C$ p- t* A strSQL="select * from "+table_name;
/ d h" {6 k' ~5 H ShowInformation(strSQL);$ g$ N4 l7 d { i5 Y, |/ U( l) u
}5 M* ]7 ~1 E' x; k# V t2 X' w( Y5 P
$ O! {$ k( Z h k# `4 |
BOOL Database_main::ShowInformation(CString strSQL)
3 ?2 z, n( y9 @0 K6 k" t{ y* P0 ^: x3 F N& e$ c3 b! O
if(!m_pdatabase->IsOpen()) return FALSE;
2 ~' J2 x7 w7 F2 w! W# a& I if(!m_pset) return FALSE;* B( _0 i2 F9 C2 S+ }3 ~
try{
! Z0 m% v! W& @" G9 _ BeginWaitCursor();
( A+ _: u+ a6 T- i/ l0 s if(m_pset->IsOpen()) m_pset->Close();9 c2 z5 u* \, q% e4 S
m_pset->Open(CRecordset::dynaset,strSQL);, }, q2 _. c. A5 I% l0 D' O6 ^# `
if(!m_pset->IsEOF())7 S) h% j# G; f$ ~& z- U3 d
{m_pset->MoveLast();" Y' C8 \1 q: Z* H( `7 q7 i
m_pset->MoveFirst();}: C2 n# F3 J$ l8 l1 s- o1 \, r, H
nFieldCount=m_pset->GetODBCFieldCount();' R) E0 \7 v0 c
CODBCFieldInfo fieldinfo;; e) p# r7 c% ~7 D" C
for(int n=0;n<nFieldCount;n++){2 r9 O6 P- E8 X% @% o
m_pset->GetODBCFieldInfo(n,fieldinfo);
1 H- B1 z* l6 ]0 z( p$ `4 }2 N int nWidth=m_list_control.GetStringWidth(fieldinfo.m_strName)+35;
# Q$ L3 x8 L4 C( f m_list_control.InsertColumn(n,fieldinfo.m_strName,LVCFMT_RIGHT,nWidth);. P% `% q' g1 B# ~) S0 w
}" c- {; {: z5 D+ `7 z0 u
CString strValue;- a3 o5 s. L. e6 E6 P5 X; }+ x
m_pset->MoveFirst();
7 I Z2 ~( b M7 R int nCount=0;
; O/ C8 V0 G6 M' z/ V) S2 z# S4 o while(!m_pset->IsEOF()){
7 F' Q3 H3 M& n |9 y8 H9 e m_list_control.InsertItem(nCount,strValue);
, k5 a0 A% m2 m for(int j=0;j<nFieldCount;j++){
) c9 G1 |0 j0 \ m_pset->GetFieldValue(j,strValue);) X" A U) l" W% Z
m_list_control.SetItemText(nCount,j,strValue);
4 F' E) X) V1 z3 u# D }
# e, N8 G( E+ Q) J6 Y% N; L: p# J4 g m_pset->MoveNext();
' s I$ x4 E$ r$ [2 ]; ^6 x nCount++;
( _6 t& c% C, x: L, B }
5 a5 E- j3 r0 ~2 y# r9 @0 e, f EndWaitCursor();
( }$ v/ M& \8 M- ~6 W H. a }
F1 ~1 n( U0 |* q% |+ D catch(CDBException *e){; P0 a$ D' f, D1 |8 I" `
e->Delete();0 \, b" _& k; {8 Z
EndWaitCursor();0 c4 h! Z: E" `* ~
return FALSE;
I1 B. k8 @/ Q& E2 k! s4 k7 U }% W1 }5 K. c4 h
return TRUE;" x1 b: t& ~5 d1 m
} |
|