Code:
case IDC_SEARCH:
BOOL bSuccess;
if(bSuccess)
{
int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_SEARCHFIELD));
if(len > 0)
{
// Now we allocate, and get the string into our buffer
int i;
char* buf;
buf = (char*)GlobalAlloc(GPTR, len + 1);
GetDlgItemText(hwnd, IDC_SEARCHFIELD, buf, len + 1);
int index = SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)buf);
MYSQL *pConnection;
MYSQL_RES *pResult; //pointer to the result set structure
MYSQL_ROW Row;
pConnection = mysql_init(NULL);
SendDlgItemMessage(hwnd, IDC_SHOWCOUNT, LB_ADDSTRING, 0, (LPARAM)TEXT("Attempting to Connect to Database...."));
//SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)TEXT("Attempting to Connect to"));
//SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)TEXT("Database......."));
mysql_real_connect(pConnection, "localhost", "username","password","database",0,NULL,0);
SetDlgItemText(hwnd, IDC_SHOWCOUNT, "Attempting To Connect To Database....");
mysql_query(pConnection,"SELECT * FROM products"); //query the database
pResult = mysql_store_result(pConnection);
TCHAR szBuffer[50];
wsprintf (szBuffer, TEXT ("%d"), mysql_num_rows (pResult));
SetDlgItemText(hwnd, IDC_SHOWCOUNT, "Connected....Please Wait!");
while ((Row = mysql_fetch_row(pResult)))
{
TCHAR szProducts[100];
wsprintf(szProducts, "%s.....%s.....%s.....%s....%s", Row[1], Row[4], Row[5], Row[7], Row[9]);
SendDlgItemMessage (hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)szProducts);
}
SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)TEXT("Total # of Products In Database:"));
SendDlgItemMessage (hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)szBuffer);
//printf("\n\nThe Number Of products in the database: %d\n\n",mysql_num_rows(pResult));
SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)TEXT("______________________"));
SetDlgItemText(hwnd, IDC_SHOWCOUNT, "Done");
mysql_free_result(pResult);
// Dont' forget to free the memory!
GlobalFree((HANDLE)buf);
}
}
break;
This is the part I'm having a problem with: