BOOL CloseComPort() { if(gComPortInfo.bIsOpen == FALSE) { return TRUE; } if(CloseSerialPort(gComPortInfo.ComID) == FALSE) { return FALSE; } gComPortInfo.bIsOpen = FALSE; EnableComboBox(TRUE); return TRUE; }
BOOL SetupComPort() { if(gComPortInfo.bIsOpen == TRUE) { return TRUE; } if(gComPortInfo.bIsConnect == FALSE) { return FALSE; } if(InitSerialPort(gComPortInfo.ComID) == FALSE) { return FALSE; } gComPortInfo.bIsOpen = TRUE; EnableComboBox(FALSE); return TRUE; }
BOOL CALLBACK AppDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { wchar_t resultStr[255]; int iCbSelectionType, iCbSelectionSize; DWORD dr0Result = 0, dr1Result = 0, dr2Result = 0, dr3Result = 0, globalResult = 0; //WORD b = 0; switch(uMsg) { case WM_INITDIALOG: SetClassLongPtr(hDlg, GCLP_HICON, (long)LoadIcon(0, IDI_APPLICATION)); // Get handles for controls in main windows GetControlHandles(hDlg); // Populates combo boxes PopulateCombos(hDlg); // disable all the combo boxes DisableComboBox(hTypeDr0); DisableComboBox(hTypeDr1); DisableComboBox(hTypeDr2); DisableComboBox(hTypeDr3); DisableComboBox(hSizeDr0); DisableComboBox(hSizeDr1); DisableComboBox(hSizeDr2); DisableComboBox(hSizeDr3); return 1; case WM_COMMAND: if (HIWORD(wParam) == CBN_SELCHANGE) { if (LOWORD(wParam) == TYPE_DR0) { iCbSelectionType = SendMessage(hTypeDr0, CB_GETCURSEL, 0, 0); if (iCbSelectionType != ONEXEC) EnableComboBox(hSizeDr0); else { SendMessage(hSizeDr0, CB_SETCURSEL, 0, 0); DisableComboBox(hSizeDr0); } } //----------------------------------------------------------- if (LOWORD(wParam) == TYPE_DR1) { iCbSelectionType = SendMessage(hTypeDr1, CB_GETCURSEL, 0, 0); if (iCbSelectionType != ONEXEC) EnableComboBox(hSizeDr1); else { SendMessage(hSizeDr1, CB_SETCURSEL, 0, 0); DisableComboBox(hSizeDr1); } } //----------------------------------------------------------- if (LOWORD(wParam) == TYPE_DR2) { iCbSelectionType = SendMessage(hTypeDr2, CB_GETCURSEL, 0, 0); if (iCbSelectionType != ONEXEC) EnableComboBox(hSizeDr2); else { SendMessage(hSizeDr2, CB_SETCURSEL, 0, 0); DisableComboBox(hSizeDr2); } } //----------------------------------------------------------- if (LOWORD(wParam) == TYPE_DR3) { iCbSelectionType = SendMessage(hTypeDr3, CB_GETCURSEL, 0, 0); if (iCbSelectionType != ONEXEC) EnableComboBox(hSizeDr3); else { SendMessage(hSizeDr3, CB_SETCURSEL, 0, 0); DisableComboBox(hSizeDr3); } } //----------------------------------------------------------- } switch(wParam) { case EXIT: CloseHandles(); EndDialog(hDlg, 0); break; case IDCANCEL: CloseHandles(); EndDialog(hDlg, 0); break; case HELP: ShowHelp(hDlg); break; case CHECK_DR0: if(IsDlgButtonChecked(hDlg, CHECK_DR0) == BST_CHECKED) { SendMessage(hTypeDr0, CB_SETCURSEL, 0, 0); SendMessage(hSizeDr0, CB_SETCURSEL, 0, 0); EnableComboBox(hTypeDr0); DisableComboBox(hSizeDr0); } else { DisableComboBox(hSizeDr0); DisableComboBox(hTypeDr0); } break; case CHECK_DR1: if(IsDlgButtonChecked(hDlg, CHECK_DR1) == BST_CHECKED) { SendMessage(hTypeDr1, CB_SETCURSEL, 0, 0); SendMessage(hSizeDr1, CB_SETCURSEL, 0, 0); EnableComboBox(hTypeDr1); DisableComboBox(hSizeDr1); } else { DisableComboBox(hTypeDr1); DisableComboBox(hSizeDr1); } break; case CHECK_DR2: if(IsDlgButtonChecked(hDlg, CHECK_DR2) == BST_CHECKED) { SendMessage(hTypeDr2, CB_SETCURSEL, 0, 0); SendMessage(hSizeDr2, CB_SETCURSEL, 0, 0); EnableComboBox(hTypeDr2); DisableComboBox(hSizeDr2); } else { DisableComboBox(hTypeDr2); DisableComboBox(hSizeDr2); } break; case CHECK_DR3: if(IsDlgButtonChecked(hDlg, CHECK_DR3) == BST_CHECKED) { SendMessage(hTypeDr3, CB_SETCURSEL, 0, 0); SendMessage(hSizeDr3, CB_SETCURSEL, 0, 0); EnableComboBox(hTypeDr3); DisableComboBox(hSizeDr3); } else { DisableComboBox(hTypeDr3); DisableComboBox(hSizeDr3); } break; case CALCULATE: // first, we need to check if there is at least one checkbox selected if((IsDlgButtonChecked(hDlg, CHECK_DR0) == BST_UNCHECKED) && (IsDlgButtonChecked(hDlg, CHECK_DR1) == BST_UNCHECKED) && (IsDlgButtonChecked(hDlg, CHECK_DR2) == BST_UNCHECKED) && (IsDlgButtonChecked(hDlg, CHECK_DR3) == BST_UNCHECKED)) { MessageBox(hDlg, "No selection was made!!!\nYou MUST select at least one register", "No selection :(", MB_ICONERROR); } else { // we must know which checboxes were selected, can be one or more than one // also, we MUST ensure that a selection was made in both combos if(IsDlgButtonChecked(hDlg, CHECK_DR0) == BST_CHECKED) { // we know the user selected DR0 so, we add the corresponding values dr0Result += LOCAL_EXACT_BPM_ENABLED + DR0_LOCAL_EXACT_BPM_ENABLED; // get the DR0_TYPE and DR0_SIZE values iCbSelectionType = SendMessage(hTypeDr0, CB_GETCURSEL, 0, 0); iCbSelectionSize = SendMessage(hSizeDr0, CB_GETCURSEL, 0, 0); // if the user select ONEXEC, then, the unique size for it is 1 // this is a special case so we evaluate it separate if(iCbSelectionType == ONEXEC) { dr0Result += DR0_EXECUTION + DR0_LEN1; } else { // we make sure the user selected Type and Size for the corresponding DR register if((iCbSelectionType != CB_ERR) && (iCbSelectionSize != CB_ERR)) { // switch for the DR type switch(iCbSelectionType) { case ONREAD: dr0Result += DR0_RW; break; case ONWRITE: dr0Result += DR0_W; break; default: break; } // switch for the DR size switch(iCbSelectionSize) { case SIZE1: dr0Result += DR0_LEN1; break; case SIZE2: dr0Result += DR0_LEN2; break; case SIZE4: dr0Result += DR0_LEN4; break; default: break; } } } } // --------------------------------------------------------------- if(IsDlgButtonChecked(hDlg, CHECK_DR1) == BST_CHECKED) { dr1Result += LOCAL_EXACT_BPM_ENABLED + DR1_LOCAL_EXACT_BPM_ENABLED; iCbSelectionType = SendMessage(hTypeDr1, CB_GETCURSEL, 0, 0); iCbSelectionSize = SendMessage(hSizeDr1, CB_GETCURSEL, 0, 0); if(iCbSelectionType == ONEXEC) { dr1Result += DR1_EXECUTION + DR1_LEN1; } else { // we make sure the user selected Type and Size for the corresponding DR register if((iCbSelectionType != CB_ERR) && (iCbSelectionSize != CB_ERR)) { // switch for the DR type switch(iCbSelectionType) { case ONREAD: dr1Result += DR1_RW; break; case ONWRITE: dr1Result += DR1_W; break; default: break; } // switch for the DR size switch(iCbSelectionSize) { case SIZE1: dr1Result += DR1_LEN1; break; case SIZE2: dr1Result += DR1_LEN2; break; case SIZE4: dr1Result += DR1_LEN4; break; default: break; } } } } // --------------------------------------------------------------- if(IsDlgButtonChecked(hDlg, CHECK_DR2) == BST_CHECKED) { dr2Result += LOCAL_EXACT_BPM_ENABLED + DR2_LOCAL_EXACT_BPM_ENABLED; iCbSelectionType = SendMessage(hTypeDr2, CB_GETCURSEL, 0, 0); iCbSelectionSize = SendMessage(hSizeDr2, CB_GETCURSEL, 0, 0); if(iCbSelectionType == ONEXEC) { dr2Result += DR2_EXECUTION + DR2_LEN1; } else { // we make sure the user selected Type and Size for the corresponding DR register if((iCbSelectionType != CB_ERR) && (iCbSelectionSize != CB_ERR)) { // switch for the DR type switch(iCbSelectionType) { case ONREAD: dr2Result += DR2_RW; break; case ONWRITE: dr2Result += DR2_W; break; default: break; } // switch for the DR size switch(iCbSelectionSize) { case SIZE1: dr2Result += DR2_LEN1; break; case SIZE2: dr2Result += DR2_LEN2; break; case SIZE4: dr2Result += DR2_LEN4; break; default: break; } } } } // --------------------------------------------------------------- if(IsDlgButtonChecked(hDlg, CHECK_DR3) == BST_CHECKED) { dr3Result += LOCAL_EXACT_BPM_ENABLED + DR3_LOCAL_EXACT_BPM_ENABLED; iCbSelectionType = SendMessage(hTypeDr3, CB_GETCURSEL, 0, 0); iCbSelectionSize = SendMessage(hSizeDr3, CB_GETCURSEL, 0, 0); if(iCbSelectionType == ONEXEC) { dr3Result += DR3_EXECUTION + DR3_LEN1; } else { // we make sure the user selected Type and Size for the corresponding DR register if((iCbSelectionType != CB_ERR) && (iCbSelectionSize != CB_ERR)) { // switch for the DR type switch(iCbSelectionType) { case ONREAD: dr3Result += DR3_RW; break; case ONWRITE: dr3Result += DR3_W; break; default: break; } // switch for the DR size switch(iCbSelectionSize) { case SIZE1: dr3Result += DR3_LEN1; break; case SIZE2: dr3Result += DR3_LEN2; break; case SIZE4: dr3Result += DR3_LEN4; break; default: break; } } } } // --------------------------------------------------------------- // final result globalResult = dr0Result + dr1Result + dr2Result + dr3Result; wsprintf((LPSTR)resultStr, "0x%X", globalResult); SetDlgItemText(hDlg, EDIT_CALCULATE, (LPCSTR)resultStr); // we make sure the variables are zeroed globalResult = 0; dr0Result = 0; dr1Result = 0; dr2Result = 0; dr3Result = 0; } break; } } return 0; }