|
MFC的DLL可以办到!但是你要在UG里运行的话最好是UIStyler结合上MFC,MFC调用ACCESS: N8 H. p0 i9 N9 |
下面是部分代码:(我这是一套的,代码很多也很杂,给你下面部分)
" Y$ @! ^- p, T: \. J8 m: ?BOOL Database_main::OnInitDialog()
2 k1 P6 l6 C2 ~& f' ^7 ]1 Z Q% U4 M) j{
# k+ i" S( ]7 N, ] CDialog::OnInitDialog();
/ Z! a5 U$ U4 e- t
0 f1 N9 F% v# s6 b1 x( b& _" L // TODO: Add extra initialization here
7 m3 ?: X& _0 Y# P- z Q3 g8 U try{
- w8 ]) ~7 a- u/ ]" R m_pdatabase=new CDatabase();# p3 y W- ?) P& y) @* N
m_pset=new CRecordset();
! z: x+ e: w0 U! w& g m_pdatabase->Open(_T("data"),FALSE,FALSE,_T("ODBC;DSN=data"),FALSE);/ t) O4 `% E8 E. u6 G
m_pset->m_pDatabase=m_pdatabase; ; w7 T0 {6 `6 }7 H* C" O. E8 z
}: x: ^1 p2 R+ ?& W
catch(CDBException* e){& v( C' j4 e3 R: p* v8 }) h
e->ReportError();
" h' y$ B O) K e->Delete();$ Q4 R/ ]8 z0 h
delete m_pset;1 c" y* D8 j8 p: W8 ]3 |
delete m_pdatabase;; {' J$ K0 _2 |3 c- K
return TRUE;} N* y: N; _% h! f0 g
DataShow("data");
' j- W4 {9 ~. Q: T3 H% h return TRUE; // return TRUE unless you set the focus to a control# l, |. G3 k; |" m7 T
// EXCEPTION: OCX Property Pages should return FALSE2 I+ s Q9 a: y: V0 ~
}. B9 Y3 K# p# h" L
- v9 P4 R- I* W
void Database_main::OnOK() - `6 r+ m! W8 M: N' x8 [# o
{
* D6 n: R8 U1 O/ Z+ ~5 E2 Q+ n9 | // TODO: Add extra validation here
! Z, ]& X8 A3 Y! ~ UINT uSelectedCount=m_list_control.GetSelectedCount();
! ]. `% H3 v8 C6 _1 u4 z* C9 b5 Wint nItemSel=0;
4 p1 o4 E- h- t P nItemSel=m_list_control.GetNextItem(nItemSel-1,LVNI_SELECTED);
3 J: |4 W$ |0 n$ I* I" Q. _ for(int j=0;j<nFieldCount;j++), `: Z# H( n6 ]6 r# J+ A
str[j]=m_list_control.GetItemText(nItemSel,j);
% Y4 ]' H0 K) {3 C' r! l: i" S) c }
- U: U ` O" c1 {2 _1 d
) r! J6 H; b- M+ i: |$ J* C* y" B
5 E+ C: p& w5 D s9 I$ S 7 e- `; T2 ?6 H5 z
CDialog::OnOK();
, v4 n8 M0 C" \( L# i} F4 @1 n7 {" b5 L1 q6 E/ x1 j
4 e' D$ h% Y9 L' H( _. Vvoid Database_main::ClearList()9 _& E; H3 T: v( [
{
$ _$ [# H# a2 S9 O1 F //m_list_control.SetExtendedStyle(LVS_EX_FULLROWSELECT);0 a! a$ _9 h2 |" k# a c4 |( h' J3 ~
//m_list_control.SetExtendedStyle(LVS_EX_GRIDLINES);2 o+ x* P5 e3 J9 [0 b
m_list_control.DeleteAllItems();0 b; l, p+ j4 e% x1 U9 P. g
while(m_list_control.DeleteColumn(0));
# L4 F, e4 _* E/ b( K' o UpdateWindow();7 L: B% }8 y8 o% M! S
}- L2 t+ b0 U- M& e) q5 n9 S% |% R
////////////////////////////////////////////////////////////////////////////////////7 ^% k5 M" e- }: J
void Database_main:ataShow(CString table_name)8 y+ [3 p9 A8 z2 o( r2 X2 ~ J
{
" Q" A7 R2 ? k; U! F$ g ClearList();4 n5 j, B5 ~/ ?
CString strSQL;
! `0 |/ E# T n2 O, P/ X strSQL="select * from "+table_name;' @. s% g- W+ p+ H! ?+ m
ShowInformation(strSQL);& K+ q! z# G9 I
}. s, |( R$ y# Y) o: R) ^+ o% J
$ x( W: P+ s# X$ C' ^( |: A7 uBOOL Database_main::ShowInformation(CString strSQL)' k7 F! [) G9 }$ d8 m
{8 y; z1 J* Y9 v$ U7 s
if(!m_pdatabase->IsOpen()) return FALSE;
: l, w' U: l; t if(!m_pset) return FALSE;
/ ^# k7 Q7 D8 g) L' P6 F try{
1 O, o4 ?) x( n BeginWaitCursor();
* A! }$ y3 B5 X# s1 n8 o if(m_pset->IsOpen()) m_pset->Close();
$ y9 N! ^0 j$ @ m_pset->Open(CRecordset::dynaset,strSQL);
) H1 \$ n2 W1 Q4 {' g- @. P if(!m_pset->IsEOF())
; D0 p9 c+ x: r6 d1 S0 E {m_pset->MoveLast();4 L2 h6 ]* H/ F
m_pset->MoveFirst();}; P8 |4 m9 P" z8 e$ M" I: r/ i3 r
nFieldCount=m_pset->GetODBCFieldCount();
. {1 z; W+ {* A: x' o3 g CODBCFieldInfo fieldinfo;
0 M. U5 C6 i; e for(int n=0;n<nFieldCount;n++){
1 A7 A; f: N$ q' \: B0 d* k( r m_pset->GetODBCFieldInfo(n,fieldinfo);
- o- P v$ o ]( o* s, Q+ {! ~# h int nWidth=m_list_control.GetStringWidth(fieldinfo.m_strName)+35;
4 V" ~7 w7 P/ n& b! W m_list_control.InsertColumn(n,fieldinfo.m_strName,LVCFMT_RIGHT,nWidth);
; b- ^; S, X: D4 ? }3 c8 ^, ~ Y$ K! e) Y2 {$ O5 X
CString strValue;
# s9 n" z1 M$ F m_pset->MoveFirst();
5 W' [. a. e1 ]9 G/ a9 T* [ int nCount=0;/ Y' g" [7 [5 O& z6 I2 S
while(!m_pset->IsEOF()){
+ p" H( A& A1 O' f8 u' t m_list_control.InsertItem(nCount,strValue);: a% I& V# j/ h. A3 X7 s
for(int j=0;j<nFieldCount;j++){( _- B8 [. C$ k. B% v
m_pset->GetFieldValue(j,strValue);( B* B8 f7 R0 q
m_list_control.SetItemText(nCount,j,strValue);
2 |- d/ l& Z. H% z$ b1 l; F5 V }7 ~7 T& e+ n) m! x* A
m_pset->MoveNext();
9 q+ X6 P* O, D+ O nCount++;3 s( L; E8 w7 s6 w- p! }
}
$ ]# x8 z1 ~( V EndWaitCursor();
: k9 z7 k% g4 q: a }
D1 W( K7 c4 z5 g% x! D. k Q9 u0 k catch(CDBException *e){
9 X% ]9 u8 O6 }' ~ S e->Delete();9 K& l% B" e8 S0 S
EndWaitCursor();$ H3 {# w* \1 \* V) ~
return FALSE;4 g" Y" y! ?: u" Y$ J" \& p& ^: a
}9 w/ X% ?5 ^% Y h, _
return TRUE;
9 I+ ^; r. W d/ _9 \4 S' O, v+ u} |
|