Code:
// vLog
void vLog(char* vsText)
{
#if defined gtLOG
char sDateTime[20];
char sTime[20];
char sText[256];
char sLogFile[100]; // store the name of the log file
FILE* hLogFile;
// get the current time
_strtime(sTime);
// append current time to text
sprintf(sText, "%s %s", sTime, vsText);
// add text to list box
//if (SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_GETCOUNT, 0, 0) >= gtMAX_LIST_ITEMS)
if (SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_GETCOUNT, 0, 0) >= 140)
{
SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_DELETESTRING, (WPARAM) 0, 0);
SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) sText);
//SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LVM_ENSUREVISIBLE, (WPARAM) SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_GETCOUNT, 0, 0), FALSE);
//SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LVM_SCROLL, (WPARAM) SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_GETCOUNT, 0, 0), FALSE);
SetWindowPos(u_hDlg, 0, 0, SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_GETCOUNT, 0, 0), 0, 0), 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}
else
{
//SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LVM_ENSUREVISIBLE, (WPARAM) SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_GETCOUNT, 0, 0), FALSE);
//SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LVM_SCROLL, (WPARAM) SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_GETCOUNT, 0, 0), FALSE);
SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) sText);
SetWindowPos(u_hDlg, 0, 0, SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, SendDlgItemMessage(u_hDlg, IDC_EVENTLOG, LB_GETCOUNT, 0, 0), 0, 0), 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}
// create file name based on date
vGetTime(sDateTime, gtDATE);
sprintf(sLogFile, "c:\\sms\\c\\c_%s.log", sDateTime);
// log text to file
if (hLogFile = fopen(sLogFile, "a+"))
{
fprintf(hLogFile, "%s \n", sText);
fflush(hLogFile);
fclose(hLogFile);
}
#endif
}
As you may have noticed ive tried to use the SetWindowPos function to always show the most recent item entered to the listbox. Not sure if this is setup correctly? But it seems easyier to implement than the previous methods we were discussing. If you think i am wrong please say and describe what i can do.