7,787
社区成员
发帖
与我相关
我的任务
分享Dim Cnn1 As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim cnnstr As String
Dim SqlStr As String
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Const SWP_NOSIZE = &H1
Const SWP_NOZORDER = &H4
Const SWP_NOMOVE = &H2
Const SWP_DRAWFRAME = &H20
Const GWL_STYLE = (-16)
Const WS_THICKFRAME = &H40000
Private Const SWP_FRAMECHANGED = &H20
Private Const WS_DLGFRAME = &H400000
Private Sub Command1_Click()
ResizeControl DataGrid1, Form1
End Sub
Private Sub Form_Load()
cnnstr = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=" & App.Path & "\db1.mdb"
SqlStr = "Select * From 学生"
Cnn1.CursorLocation = adUseClient
Cnn1.Open cnnstr
With rst
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open SqlStr, cnnstr, , , adCmdText
End With
Set DataGrid1.DataSource = rst
DataGrid1.Caption = "共" & rst.RecordCount & "条记录"
End Sub
Function ResizeControl(ControlName As Control, FormName As Form)
Dim NewStyle As Long
NewStyle = GetWindowLong(ControlName.hwnd, GWL_STYLE)
NewStyle = NewStyle Or WS_THICKFRAME
' NewStyle = NewStyle Or WS_DLGFRAME
NewStyle = SetWindowLong(ControlName.hwnd, GWL_STYLE, NewStyle)
SetWindowPos ControlName.hwnd, FormName.hwnd, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_FRAMECHANGED
End Function