Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to Understand the macro ON_ONCTROL_RANGE

How to Understand the macro ON_ONCTROL_RANGE

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpdebuggingtutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cnhnyu
    wrote on last edited by
    #1

    I wrote a test mfc project based on dialog, just one main dialog, three check boxes on it. in .h file I define a bool var. BOOL m_fCheck[3]; and a function: afx_msg void OnCheck(); in .cpp file : (1) in constructor: for ( int i = 0; i < 3; i++ ) m_fCheck[i] = FALSE; (2) in DoDataExchange void CTestDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CTestDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP for ( int i=0; i<3; i++ ) DDX_Check(pDX, IDC_CHECK1 + i, m_fCheck[i]); } (3) On Message Map ON_CONTROL_RANGE(BN_CLICKED, IDC_CHECK1, IDC_CHECK3, OnCheck) (4) OnCheck() function void CTestDlg::OnCheck() { } ???: When I run this test program in debug mode, I click any check box and has no error. But when I run this program in release mode: A fatal error occured: First-chance exception in ChtVCData.exe: 0xC0000096: Privileged Instruction. I do one test today. I change macro ON_CONTROL_RANGE(BN_CLICKED, IDC_CHECK1, IDC_CHECK3, OnCheck) to : ON_BN_CLICKED(IDC_CHECK1, OnCheck) ON_BN_CLICKED(IDC_CHECK2, OnCheck) ON_BN_CLICKED(IDC_CHECK3, OnCheck) And then I run in debug an release mode, no error found again. Now I can asure that the problem is on the macro ON_CONTROL_RANGE(BN_CLICKED, IDC_CHECK1, IDC_CHECK3, OnCheck) it equals the three macro ON_BN_CLICKED(IDC_CHECK1, OnCheck) ON_BN_CLICKED(IDC_CHECK2, OnCheck) ON_BN_CLICKED(IDC_CHECK3, OnCheck) YES OR NO ?

    ---------------------------------------- Don't let habit prevent you from trying something new.

    M 1 Reply Last reply
    0
    • C cnhnyu

      I wrote a test mfc project based on dialog, just one main dialog, three check boxes on it. in .h file I define a bool var. BOOL m_fCheck[3]; and a function: afx_msg void OnCheck(); in .cpp file : (1) in constructor: for ( int i = 0; i < 3; i++ ) m_fCheck[i] = FALSE; (2) in DoDataExchange void CTestDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CTestDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP for ( int i=0; i<3; i++ ) DDX_Check(pDX, IDC_CHECK1 + i, m_fCheck[i]); } (3) On Message Map ON_CONTROL_RANGE(BN_CLICKED, IDC_CHECK1, IDC_CHECK3, OnCheck) (4) OnCheck() function void CTestDlg::OnCheck() { } ???: When I run this test program in debug mode, I click any check box and has no error. But when I run this program in release mode: A fatal error occured: First-chance exception in ChtVCData.exe: 0xC0000096: Privileged Instruction. I do one test today. I change macro ON_CONTROL_RANGE(BN_CLICKED, IDC_CHECK1, IDC_CHECK3, OnCheck) to : ON_BN_CLICKED(IDC_CHECK1, OnCheck) ON_BN_CLICKED(IDC_CHECK2, OnCheck) ON_BN_CLICKED(IDC_CHECK3, OnCheck) And then I run in debug an release mode, no error found again. Now I can asure that the problem is on the macro ON_CONTROL_RANGE(BN_CLICKED, IDC_CHECK1, IDC_CHECK3, OnCheck) it equals the three macro ON_BN_CLICKED(IDC_CHECK1, OnCheck) ON_BN_CLICKED(IDC_CHECK2, OnCheck) ON_BN_CLICKED(IDC_CHECK3, OnCheck) YES OR NO ?

      ---------------------------------------- Don't let habit prevent you from trying something new.

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      See here[^]. Your message handler is wrong. The handler for a *_RANGE macro has one UINT parameter, which is the control ID.

      --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?

      C 1 Reply Last reply
      0
      • M Michael Dunn

        See here[^]. Your message handler is wrong. The handler for a *_RANGE macro has one UINT parameter, which is the control ID.

        --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?

        C Offline
        C Offline
        cnhnyu
        wrote on last edited by
        #3

        Thank you very much for reply. I have already solved this problem. You said right, The handler for a *_RANGE macro has one UINT parameter, which is the control ID.

        ---------------------------------------- Don't let habit prevent you from trying something new.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups