⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lmscopedlg.cpp

📁 一个简单示波器的源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    ID_INDICATOR_STATUS);

    //
    // Set the background color
    //
    m_csbStatusBar.GetStatusBarCtrl().SetBkColor(SCOPE_COLOR_DLG_BACKGROUND);

    //
    // Set the initial status text.
    //
    m_csbStatusBar.SetPaneTextByResource(0, IDS_STATUS_SEARCHING, TRUE);

    //
    // Remember that we are not connected to the scope yet.
    //
    m_bConnected = FALSE;

    //
    // Set the ranges of the various sliders on the dialog.
    //
    m_cChannel1PosSlider.SetRange(POS_SLIDER_MIN, POS_SLIDER_MAX, FALSE);
    m_cChannel2PosSlider.SetRange(POS_SLIDER_MIN, POS_SLIDER_MAX, FALSE);
    m_cTriggerPosSlider.SetRange(TRIGGER_POS_SLIDER_MIN, TRIGGER_POS_SLIDER_MAX,
                                 FALSE);
    m_cTriggerLevelSlider.SetRange(TRIGGER_LEVEL_SLIDER_MIN,
                                   TRIGGER_LEVEL_SLIDER_MAX, FALSE);

    m_cTriggerPosSlider.SetPos(
             (TRIGGER_POS_SLIDER_MAX - TRIGGER_POS_SLIDER_MIN) / 2);
    m_cChannel1PosSlider.SetPos((POS_SLIDER_MAX - POS_SLIDER_MIN) / 2);
    m_cChannel2PosSlider.SetPos((POS_SLIDER_MAX - POS_SLIDER_MIN) / 2);
    m_cTriggerLevelSlider.SetPos(
             (TRIGGER_LEVEL_SLIDER_MAX - TRIGGER_LEVEL_SLIDER_MIN) / 2);

    //
    // Set the choices available in the various comboboxes
    //
    InitComboBoxContents();

    //
    // Update the enable/disable state of the various controls
    //
    UpdateControlEnables();

    //
    // Initialize the waveform display custom control.
    //
    m_cWaveform.InitBitmap();

    //
    // Initialize the scope control module
    //
    ScopeControlInit(m_hWnd);

    return TRUE;  // return TRUE unless you set the focus to a control
}

//
// Handle the commands we added to the system menu.
//
void ClmscopeDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
    switch(nID & 0xFFF0)
    {
        case IDM_ABOUTBOX:
        {
            CAboutDlg dlgAbout;
            dlgAbout.DoModal();
        }
        break;

        case IDM_DISPLAYOPTS:
        {
                CDisplayOptions dlgDisplay;
                dlgDisplay.SelectWaveform(&m_cWaveform);
                dlgDisplay.DoModal();
        }
        break;

        case IDM_SAVEASBMP:
        {
            CString strFileName;
            INT_PTR iRet;
            CFileDialog FileDlg(FALSE, NULL, NULL, OFN_OVERWRITEPROMPT,
                                L"Bitmaps (*.bmp)|*.bmp||");

            iRet = FileDlg.DoModal();

            strFileName = FileDlg.GetPathName();

            if(iRet == IDOK)
            {
                m_cWaveform.SaveAsBMP(&strFileName);
            }
        }
        break;

        case IDM_SAVEASCSV:
        {
            CString strFileName;
            INT_PTR iRet;
            CFileDialog FileDlg(FALSE, NULL, NULL, OFN_OVERWRITEPROMPT,
                                L"Comma Separated Values (*.csv)|*.csv||");

            iRet = FileDlg.DoModal();

            strFileName = FileDlg.GetPathName();

            if(iRet == IDOK)
            {
                m_cWaveform.SaveAsCSV(&strFileName);
            }
        }
        break;

        case IDM_SHOWHELP:
        {
            CWinApp *theApp = AfxGetApp();
            CString strHelpFile = theApp->m_pszHelpFilePath;

            ::HtmlHelp(::GetDesktopWindow(), (LPCWSTR)strHelpFile,
                   HH_DISPLAY_TOPIC, NULL);
        }
        break;

        default:
        {
            CDialog::OnSysCommand(nID, lParam);
        }
        break;
    }
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void ClmscopeDlg::OnPaint()
{
    if (IsIconic())
    {
        CPaintDC dc(this); // device context for painting

        SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

        // Center icon in client rectangle
        int cxIcon = GetSystemMetrics(SM_CXICON);
        int cyIcon = GetSystemMetrics(SM_CYICON);
        CRect rect;
        GetClientRect(&rect);
        int x = (rect.Width() - cxIcon + 1) / 2;
        int y = (rect.Height() - cyIcon + 1) / 2;

        // Draw the icon
        dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
        CDialog::OnPaint();
    }
}

// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR ClmscopeDlg::OnQueryDragIcon()
{
    return static_cast<HCURSOR>(m_hIcon);
}

// The system calls this function when any horizontal scroll bar or slider is
// moved.
void ClmscopeDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar)
{
    //
    // We only have 1 horizontal slider in this application so this must be
    // the trigger position. Update the trigger position if this notification
    // related to a new position.
    //
    if(nSBCode != SB_ENDSCROLL)
    {
        ScopeControlSetTriggerPos(nPos);
    }
}

// The system calls this function when any vertical scroll bar or slider is
// moved.
void ClmscopeDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar)
{
    CSliderCtrl *pSlider = (CSliderCtrl *)pScrollBar;
    long lPos;

    //
    // Ignore ENDSCROLL notifications.
    //
    if(nSBCode == SB_ENDSCROLL)
    {
        return;
    }

    //
    // We have several vertical sliders in the application so we need to
    // determine which one generated this message and handle it
    // appropriately.
    //
    if(pSlider->m_hWnd == m_cTriggerLevelSlider.m_hWnd)
    {
        //
        // Update the trigger level.
        //

        lPos = REVERSE_SLIDER(nPos, TRIGGER_LEVEL_SLIDER_MAX,
                             TRIGGER_LEVEL_SLIDER_MIN);
        lPos = ROUND(lPos, 100);
        ScopeControlSetTriggerLevel(lPos);
    }

    if(pScrollBar->m_hWnd == m_cChannel1PosSlider.m_hWnd)
    {
        //
        // Update the channel 1 position
        //
        lPos = REVERSE_SLIDER(nPos, POS_SLIDER_MAX, POS_SLIDER_MIN);
        lPos = ROUND(lPos, 100);
        ScopeControlSetPosition(SCOPE_CHANNEL_1, lPos);
    }

    if(pScrollBar->m_hWnd == m_cChannel2PosSlider.m_hWnd)
    {
        //
        // Update the channel 2 position
        //
        lPos = REVERSE_SLIDER(nPos, POS_SLIDER_MAX, POS_SLIDER_MIN);
        lPos = ROUND(lPos, 100);
        ScopeControlSetPosition(SCOPE_CHANNEL_2, lPos);
    }
}


//***************************************************************************
//
// Start or stop automatic capture of oscilloscope waveforms.
//
//***************************************************************************
void ClmscopeDlg::OnBnClickedStartStop()
{
    //
    // Ask the scope control module to either start or stop automatic capture.
    //
    ScopeControlStartStop(!m_bStarted);
}

//***************************************************************************
//
// Perform a 1-shot capture
//
//***************************************************************************
void ClmscopeDlg::OnBnClickedCapture()
{
    //
    // Ask the scope control module to capture a single waveform.
    //
    ScopeControlCapture();
}

//***************************************************************************
//
// Find the channel 2 signal, reposition and rescale to make it appear
// visible on the screen.
//
//***************************************************************************
void ClmscopeDlg::OnBnClickedChannel2Find()
{
    // Ask the scope to find the channel 2 waveform for us.
    ScopeControlFind(SCOPE_CHANNEL_2);
}

//***************************************************************************
//
// Find the channel 1 signal, reposition and rescale to make it appear
// visible on the screen.
//
//***************************************************************************
void ClmscopeDlg::OnBnClickedChannel1Find()
{
    // Ask the scope to find the channel 1 waveform for us.
    ScopeControlFind(SCOPE_CHANNEL_1);
}

//***************************************************************************
//
// Enable or disable channel 2 capture.
//
//***************************************************************************
void ClmscopeDlg::OnBnClickedEnableCh2()
{
    //
    // Is the button checked or not?
    //
    m_cChannel2Enable.GetCheck();

    //
    // Ask the scope control module to enable or disable channel 2.
    //
    ScopeControlEnableChannel2(m_cChannel2Enable.GetCheck() ? true : false);
}

//***************************************************************************
//
// The user has changed the channel 1 scale combo box selection.
//
//***************************************************************************
void ClmscopeDlg::OnCbnSelchangeChannel1Scale()
{
    unsigned long ulValue;

    //
    // Get the trigger type control selection and ask the scope to change
    // to this setting.
    //
    ulValue = (unsigned long)m_cChannel1Scale.GetItemData(
                                        m_cChannel1Scale.GetCurSel());

    //
    // Ask the scope to change to the new setting.
    //
    ScopeControlSetScale(SCOPE_CHANNEL_1, ulValue);
}

//***************************************************************************
//
// The user has changed the channel 2 scale combo box selection.
//
//***************************************************************************
void ClmscopeDlg::OnCbnSelchangeChannel2Scale()
{
    unsigned long ulValue;

    //
    // Get the trigger type control selection and ask the scope to change
    // to this setting.
    //
    ulValue = (unsigned long)m_cChannel2Scale.GetItemData(
                                        m_cChannel2Scale.GetCurSel());

    //
    // Ask the scope to change to the new setting.
    //
    ScopeControlSetScale(SCOPE_CHANNEL_2, ulValue);

}

//***************************************************************************
//
// The user has changed the trigger type combo box selection.
//
//***************************************************************************
void ClmscopeDlg::OnCbnSelchangeTriggerType()
{
    unsigned long ulValue;
    unsigned char ucChannel;

    //
    // Get the trigger type control selection and ask the scope to change
    // to this setting.
    //
    ulValue = (unsigned long)m_cTriggerType.GetItemData(
                                        m_cTriggerType.GetCurSel());
    ucChannel = m_cTriggerCh1.GetCheck() ? SCOPE_CHANNEL_1 : SCOPE_CHANNEL_2;
    ScopeControlSetTrigger(ucChannel, ulValue);
}

//***************************************************************************
//
// The user has changed the timebase combo box selection.
//
//***************************************************************************
void ClmscopeDlg::OnCbnSelchangeTimebase()
{
    unsigned long ulValue;

    //
    // Get the timebase control selection and ask the scope to change
    // to this setting.
    //
    ulValue = (unsigned long)m_cTimebase.GetItemData(m_cTimebase.GetCurSel());

    //
    // Pass on the change to the device.
    //
    ScopeControlSetTimebase(ulValue);
}

//***************************************************************************
//
// The user has requested triggering on channel 1.
//
//***************************************************************************
void ClmscopeDlg::OnBnClickedTriggerCh1()
{
    unsigned long ulValue;
    unsigned char ucChannel;

    //
    // Get the trigger type control selection and ask the scope to change
    // to this setting.
    //
    ulValue = (unsigned long)m_cTriggerType.GetItemData(
                                        m_cTriggerType.GetCurSel());
    ucChannel = m_cTriggerCh1.GetCheck() ? SCOPE_CHANNEL_1 : SCOPE_CHANNEL_2;
    ScopeControlSetTrigger(ucChannel, ulValue);
}

//***************************************************************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -