void CDriverFilterDialog::UpdateButtons() { ExcludeButton().EnableWindow(IncludedList().GetCurSel() != LB_ERR); IncludeButton().EnableWindow(ExcludedList().GetCurSel() != LB_ERR); NoneButton().EnableWindow(IncludedList().GetCount() != 0); AllButton().EnableWindow(ExcludedList().GetCount() != 0); OkButton().EnableWindow(IncludedList().GetCount() != 0); }
LRESULT CommDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam) { LPDIALOG_INFO lpDlgInfo = NULL; HWND hBox; switch (Msg) { case WM_INITDIALOG: { WCHAR wstr[255]; RECT rc, rcDlg, rcOwner; HWND hOwner; INT i; lpDlgInfo = (LPDIALOG_INFO)lParam; SetWindowLongPtrW(hDlg, DWL_USER, (LONG_PTR)lpDlgInfo); /* Set title */ if(LoadStringW(hDllInstance, IDS_TITLE, wstr, sizeof(wstr) / sizeof(wstr[0]))) { SetWindowTextW(hDlg, wstr); } /* FIXME - this won't work correctly systems with multiple monitors! */ if(!(hOwner = GetParent(hDlg))) hOwner = GetDesktopWindow(); /* Position dialog in the center of owner window */ GetWindowRect(hOwner, &rcOwner); GetWindowRect(hDlg, &rcDlg); CopyRect(&rc, &rcOwner); OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top); OffsetRect(&rc, -rc.left, -rc.top); OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom); SetWindowPos(hDlg, HWND_TOP, rcOwner.left + (rc.right / 2), rcOwner.top + (rc.bottom / 2), 0, 0, SWP_NOSIZE); /* Initialize baud rate combo */ if(!(hBox = GetDlgItem(hDlg, IDC_BAUDRATE))) EndDialog(hDlg, ERROR_CANCELLED); for(i = 0; Bauds[i]; i++) { wsprintf(wstr, L"%d", Bauds[i]); SendMessageW(hBox, CB_INSERTSTRING, (WPARAM)i, (LPARAM)wstr); if(Bauds[i] == lpDlgInfo->lpCC->dcb.BaudRate) SendMessageW(hBox, CB_SETCURSEL, (WPARAM)i, 0); } if(SendMessageW(hBox, CB_GETCURSEL, 0, 0) == CB_ERR) SendMessageW(hBox, CB_SETCURSEL, DEFAULT_BAUD_INDEX, 0); /* Initialize byte size combo */ if(!(hBox = GetDlgItem(hDlg, IDC_BYTESIZE))) EndDialog(hDlg, ERROR_CANCELLED); for(i = 0; ByteSizes[i]; i++) { wsprintf(wstr, L"%d", Bauds[i]); SendMessageW(hBox, CB_INSERTSTRING, (WPARAM)i, (LPARAM)wstr); if(ByteSizes[i] == lpDlgInfo->lpCC->dcb.ByteSize) SendMessageW(hBox, CB_SETCURSEL, (WPARAM)i, 0); } if(SendMessageW(hBox, CB_GETCURSEL, 0, 0) == CB_ERR) SendMessageW(hBox, CB_SETCURSEL, DEFAULT_BYTESIZE_INDEX, 0); /* Initialize parity combo */ if(!(hBox = GetDlgItem(hDlg, IDC_PARITY))) EndDialog(hDlg, ERROR_CANCELLED); for(i = 0; Parities[i].StrId; i++) { if(LoadStringW(hDllInstance, Parities[i].StrId, wstr, sizeof(wstr) / sizeof(wstr[0]))) { SendMessageW(hBox, CB_INSERTSTRING, (WPARAM)i, (LPARAM)wstr); if(Parities[i].Parity == lpDlgInfo->lpCC->dcb.Parity) SendMessageW(hBox, CB_SETCURSEL, (WPARAM)i, 0); } } if(SendMessageW(hBox, CB_GETCURSEL, 0, 0)==CB_ERR) SendMessageW(hBox, CB_SETCURSEL, DEFAULT_PARITY_INDEX, 0); /* Initialize stop bits combo */ if(!(hBox = GetDlgItem(hDlg, IDC_STOPBITS))) EndDialog(hDlg, ERROR_CANCELLED); for(i = 0; StopBits[i].StrId; i++) { if(LoadStringW(hDllInstance, StopBits[i].StrId, wstr, sizeof(wstr) / sizeof(wstr[0]))) { SendMessageW(hBox, CB_INSERTSTRING, (WPARAM)i, (LPARAM)wstr); if(StopBits[i].StopBit == lpDlgInfo->lpCC->dcb.StopBits) SendMessageW(hBox, CB_SETCURSEL, (WPARAM)i, 0); } } if(SendMessageW(hBox, CB_GETCURSEL, 0, 0)==CB_ERR) SendMessageW(hBox, CB_SETCURSEL, DEFAULT_STOPBITS_INDEX, 0); /* Initialize flow control combo */ if(!(hBox = GetDlgItem(hDlg, IDC_FLOW))) EndDialog(hDlg, ERROR_CANCELLED); if(LoadStringW(hDllInstance, IDS_FC_NO, wstr, sizeof(wstr) / sizeof(wstr[0]))) { SendMessageW(hBox, CB_INSERTSTRING, 0, (LPARAM)wstr); SendMessageW(hBox, CB_SETCURSEL, 0, 0); lpDlgInfo->InitialFlowIndex = 0; } if(LoadStringW(hDllInstance, IDS_FC_CTSRTS, wstr, sizeof(wstr) / sizeof(wstr[0]))) { SendMessageW(hBox, CB_INSERTSTRING, 1, (LPARAM)wstr); if(lpDlgInfo->lpCC->dcb.fRtsControl == RTS_CONTROL_HANDSHAKE || lpDlgInfo->lpCC->dcb.fOutxCtsFlow == TRUE) { SendMessageW(hBox, CB_SETCURSEL, 1, 0); lpDlgInfo->InitialFlowIndex = 1; } } if(LoadStringW(hDllInstance, IDS_FC_XONXOFF, wstr, sizeof(wstr) / sizeof(wstr[0]))) { SendMessageW(hBox, CB_INSERTSTRING, 2, (LPARAM)wstr); if(lpDlgInfo->lpCC->dcb.fOutX || lpDlgInfo->lpCC->dcb.fInX) { SendMessageW(hBox, CB_SETCURSEL, 2, 0); lpDlgInfo->InitialFlowIndex = 2; } } /* Set focus */ SetFocus(GetDlgItem(hDlg, IDC_OKBTN)); return FALSE; } /* WM_INITDIALOG */ case WM_COMMAND: { switch(wParam) { case IDC_CANCELBTN: EndDialog(hDlg, ERROR_CANCELLED); break; case IDC_OKBTN: OkButton(hDlg); EndDialog(hDlg, ERROR_SUCCESS); break; } return TRUE; } /* WM_COMMAND */ case WM_CLOSE: { EndDialog(hDlg, ERROR_CANCELLED); return TRUE; } /* WM_CLOSE */ default: return FALSE; } }