void
InsertColumn(
void
)
{
LV_COLUMN lvc;
lvc.mask
=
LVCF_TEXT
|
LVCF_WIDTH;
lvc.pszText
=
"
学号
"
;
lvc.cx
=
60
;
SendMessage(hList, LVM_INSERTCOLUMN,
0
, (
long
)
&
lvc);
lvc.pszText
=
"
姓名
"
;
lvc.cx
=
80
;
SendMessage(hList, LVM_INSERTCOLUMN,
1
, (
long
)
&
lvc);
lvc.pszText
=
"
性别
"
;
lvc.cx
=
40
;
SendMessage(hList, LVM_INSERTCOLUMN,
2
, (
long
)
&
lvc);
lvc.pszText
=
"
年龄
"
;
lvc.cx
=
40
;
SendMessage(hList, LVM_INSERTCOLUMN,
3
, (
long
)
&
lvc);
lvc.pszText
=
"
出生日期
"
;
lvc.cx
=
100
;
SendMessage(hList, LVM_INSERTCOLUMN,
4
, (
long
)
&
lvc);
lvc.pszText
=
"
籍贯
"
;
lvc.cx
=
150
;
SendMessage(hList, LVM_INSERTCOLUMN,
5
, (
long
)
&
lvc);
lvc.pszText
=
"
入学时间
"
;
lvc.cx
=
100
;
SendMessage(hList, LVM_INSERTCOLUMN,
6
, (
long
)
&
lvc);
lvc.pszText
=
"
数学
"
;
lvc.cx
=
40
;
SendMessage(hList, LVM_INSERTCOLUMN,
7
, (
long
)
&
lvc);
lvc.pszText
=
"
英语
"
;
lvc.cx
=
40
;
SendMessage(hList, LVM_INSERTCOLUMN,
8
, (
long
)
&
lvc);
lvc.pszText
=
"
政治
"
;
lvc.cx
=
40
;
SendMessage(hList, LVM_INSERTCOLUMN,
9
, (
long
)
&
lvc);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static
HINSTANCE hInst;
HMENU hMenu;
LV_ITEM lvi;
int
i;
switch
(message) {
case
WM_CREATE:
hInst
=
((LPCREATESTRUCT)lParam)
->
hInstance;
hMenu
=
GetMenu(hwnd);
InitCommonControls();
hList
=
CreateWindowEx(NULL, TEXT(
"
SysListView32
"
), NULL, LVS_REPORT
|
WS_CHILD
|
WS_VISIBLE,
0
,
0
,
0
,
0
, hwnd, NULL, hInst, NULL);
InsertColumn();
SendMessage(hList, LVM_SETTEXTCOLOR,
0
, #ffffff);
SendMessage(hList, LVM_SETBKCOLOR,
0
, #
646464
);
SendMessage(hList, LVM_SETTEXTBKCOLOR,
0
, #
000000
);
Refresh();
break
;
case
WM_COMMAND:
switch
(LOWORD(wParam)) {
case
IDREFRESH:
Refresh();
break
;
case
IDINSERT:
if
(DialogBox(hInst, TEXT(
"
StudInfo
"
), hwnd, InsertDlgProc)) InvalidateRect(hwnd, NULL, TRUE);
break
;
case
IDEDIT:
lvi.iItem
=
SendMessage(hList, LVM_GETNEXTITEM,
-
1
, LVNI_SELECTED);
if
(
-
1
==
lvi.iItem) {
MessageBox(hwnd,
"
请选择一条记录!
"
,
"
Edit Info
"
, MB_OK
|
MB_ICONWARNING);
break
;
}
lvi.mask
=
LVIF_TEXT;
lvi.cchTextMax
=
20
;
for
(i
=
0
; i
<
10
;
++
i) {
lvi.iSubItem
=
i;
lvi.pszText
=
buf[i];
SendMessage(hList, LVM_GETITEM,
0
, (
long
)
&
lvi);
}
if
(DialogBox(hInst, TEXT(
"
StudInfo
"
), hwnd, EditDlgProc)) InvalidateRect(hwnd, NULL, TRUE);
break
;
case
IDDELETE:
lvi.iItem
=
SendMessage(hList, LVM_GETNEXTITEM,
-
1
, LVNI_SELECTED);
if
(
-
1
==
lvi.iItem) {
MessageBox(hwnd,
"
请选择一条记录!
"
,
"
Delete Info
"
, MB_OK
|
MB_ICONWARNING);
break
;
}
SendMessage(hList, LVM_DELETEITEM, lvi.iItem,
0
);
lvi.mask
=
LVIF_TEXT;
lvi.iSubItem
=
0
;
lvi.pszText
=
buf[
0
];
lvi.cchTextMax
=
20
;
SendMessage(hList, LVM_GETITEM,
0
, (
long
)
&
lvi);
sprintf(query,
"
DELETE FROM student WHERE id = %s
"
, buf[
0
]);
ODBCConnect(hwnd);
ODBCQuery(query);
ODBCQueryEnd();
ODBCDisconnect(hwnd);
break
;
case
IDEXIT:
SendMessage(hwnd, WM_CLOSE,
0
,
0
);
break
;
case
IDABOUT:
MessageBox(hwnd,
"
Students Info Administration System Developed by anonymous
"
,
"
About
"
, MB_OK
|
MB_ICONINFORMATION);
}
break
;
case
WM_SIZE:
MoveWindow(hList,
0
,
0
, LOWORD(lParam), HIWORD(lParam), TRUE);
break
;
case
WM_DESTROY:
PostQuitMessage(
0
);
break
;
default
:
return
DefWindowProc(hwnd, message, wParam, lParam);
}
return
0
;
}