#include #include #include #include #include #include "wsqllib.h" static char host[128]; static char user[128]; static char passwd[128]; static void GetUserPass(void) { FILE *f; char s[4098], *p; int done = 0; strcpy(host, ""); strcpy(user, ""); strcpy(passwd, ""); if ((f = fopen("c:/my.cnf", "rt"))) { while (fgets(s, 4096, f)) { s[strlen(s) - 1] = '\0'; if (! strncmp(s, "user", 4)) { (void)strtok(s, "="); for (p = strtok(NULL, "="); isspace(*p); p++); strcpy(user, p); done++; } if (! strncmp(s, "password", 8)) { (void)strtok(s, "="); for (p = strtok(NULL, "="); isspace(*p); p++); strcpy(passwd, p); done++; } if (done == 2) break; } fclose(f); } } BOOL CALLBACK LoginProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { char s[256]; switch (msg) { case WM_INITDIALOG: if (strlen(user)) { SetDlgItemText(hwndDlg, ID_LOGIN_EDIT2, (LPTSTR)user); } if (strlen(passwd)) { SetDlgItemText(hwndDlg, ID_LOGIN_EDIT3, (LPTSTR)passwd); } if (strlen(user)) { SetFocus(GetDlgItem(hwndDlg, ID_LOGIN_EDIT3)); return FALSE; } return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: GetDlgItemText(hwndDlg, ID_LOGIN_EDIT1, (LPTSTR)host, 127); GetDlgItemText(hwndDlg, ID_LOGIN_EDIT2, (LPTSTR)user, 127); GetDlgItemText(hwndDlg, ID_LOGIN_EDIT3, (LPTSTR)passwd, 127); case IDCANCEL: EndDialog(hwndDlg, wParam); return TRUE; } } return FALSE; } int Login(LOGINDATA *loginData) { int r; GetUserPass(); r = DialogBox(hInst, "loginDlg", NULL, (DLGPROC)LoginProc); if (r != IDOK) return 0; strcpy(loginData->host, host); strcpy(loginData->user, user); strcpy(loginData->passwd, passwd); return 1; } .