回复 6楼 bin92571
上面第二个图的列表视图控件C语言代码如下:
hwndlistCtrl=CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW,"",
WS_CHILD | LVS_REPORT | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT
,
900, 200, hwndlistWindow,
(HMENU)ID_LISTCTRL,
hInst, NULL );
if ( hwndlistCtrl )
{
LV_COLUMN col;
col.mask=LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
col.fmt = LVCFMT_LEFT;
col.cx
= 100;
col.pszText
= "Variable";
col.iSubItem = 0;
ListView_InsertColumn( hwndlistCtrl, 0, &col );
col.pszText
= "Value";
col.iSubItem = 1;
col.cx = 300;
ListView_InsertColumn( hwndlistCtrl, 1, &col );
}
/*......
.
.
case WM_COMMAND:
switch(wParam)
{
case IDB_FS_CAXUN:
InitColumnInfo(hwndlistCtrl);
.
.
......*/
void InitColumnInfo(HWND hwndlist)
{
//test
LV_ITEM item;
int
nRow = 0;
LPTSTR
lpValue;
LPTSTR
lpTemp = GetEnvironmentStrings();
ListView_DeleteAllItems( hwndlist );
item.mask = LVIF_TEXT;
while ( *lpTemp )
{
lpValue = strstr( lpTemp+1, "=" );
if ( lpValue )
{
*lpValue = '\0';
lpValue++;
}
item.iItem = nRow;
item.iSubItem = 0;
item.pszText = lpTemp;
ListView_InsertItem( hwndlist, &item );
item.iSubItem = 1;
item.pszText = lpValue;
ListView_SetItem( hwndlist, &item );
lpTemp += strlen(lpTemp)+1+strlen(lpValue)+1;
}
//endtest
SQLRETURN retcode;
SQLHANDLE henv,hdbc;
HSTMT hstmt;
SDWORD cbData;
retcode=SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&henv);
if((retcode!=SQL_SUCCESS)&&(retcode!=SQL_SUCCESS_WITH_INFO))
{
MessageBox(hwndlist,"分配环境变量失败!","ERROR",MB_OK);
return;
}
retcode=SQLSetEnvAttr(henv,SQL_ATTR_ODBC_VERSION,(void*)SQL_OV_ODBC3,0);
if((retcode!=SQL_SUCCESS)&&(retcode!=SQL_SUCCESS_WITH_INFO))
{
MessageBox(hwndlist,"设置ODBC版本失败!","ERROR",MB_OK);
return;
}
retcode=SQLAllocHandle(SQL_HANDLE_DBC,henv,&hdbc);
if((retcode!=SQL_SUCCESS)&&(retcode!=SQL_SUCCESS_WITH_INFO))
{
MessageBox(hwndlist,"分配连接句柄失败!","ERROR",MB_OK);
return;
}
retcode=SQLConnect(hdbc,(SQLTCHAR*)"Gfrsmall",SQL_NTS,NULL,0,NULL,0);
if((retcode!=SQL_SUCCESS)&&(retcode!=SQL_SUCCESS_WITH_INFO))
{
MessageBox(hwndlist,"连接数据库失败!","ERROR",MB_OK);
return;
}
retcode=SQLAllocStmt(hdbc,&hstmt);
if((retcode!=SQL_SUCCESS)&&(retcode!=SQL_SUCCESS_WITH_INFO))
{
MessageBox(hwndlist,"HSTMT fail..","ERROR",MB_OK);
return;
}
retcode=SQLExecDirect(hstmt,(SQLTCHAR*)"SELECT DistrictName,CityName,AreaName FROM Area",SQL_NTS);
if((retcode!=SQL_SUCCESS)&&(retcode!=SQL_SUCCESS_WITH_INFO))
{
MessageBox(hwndlist,"SQLExecDirect fail...","ERROR",MB_OK);
SQLFreeStmt(hstmt,SQL_DROP);
SQLDisconnect(hdbc);
SQLFreeConnect(hdbc);
SQLFreeEnv(henv);
return;
}
for(retcode=SQLFetch(hstmt);retcode==SQL_SUCCESS;retcode=SQLFetch(hstmt))
{
SQLGetData(hstmt,1,SQL_C_CHAR,szData,sizeof(szData),&cbData);
LVITEM lvi;
lvi.mask = LVIF_TEXT;
lvi.pszText = (LPSTR)szData;
lvi.cchTextMax = MAX_PATH;
lvi.iItem = 0;
lvi.iSubItem = 0;
lvi.state = 0;
lvi.stateMask = 0;
lvi.iImage = 0;
lvi.lParam = 0;
int nItem = ListView_InsertItem(hwndlist, &lvi);
if ( nItem == -1 )
continue;
SQLGetData(hstmt,2,SQL_C_CHAR,szData,sizeof(szData),&cbData);
ListView_SetItemText(hwndlist, nItem, 1, (LPSTR)szData);
SQLGetData(hstmt,3,SQL_C_CHAR,szData,sizeof(szData),&cbData);
ListView_SetItemText(hwndlist, nItem, 2, (LPSTR)szData);
}
ShowWindow(hwndlistCtrl,1);
}