在mydlg.h中声明了
// Implementation
protected:
    

// Generated message map functions
//{{AFX_MSG(CDigitalDlg)
virtual void OnOK();
virtual void OnCancel();
afx_msg void OnChangeCtrlWord(UINT id, NMHDR * pNotifyStruct, LRESULT * result );//id为你当前点中的控件ID值
//}}AFX_MSG
在mydlg.cpp中
ON_NOTIFY_RANGE(BN_CLICKED,IDC_STATIC_CTRLWORD33/*起始控件的id*/,IDC_STATIC_CTRLWORD64/*结束控件的id*/,OnChangeCtrlWord)成员函数的实现
void mydlg::OnChangeCtrlWord(UINT id, NMHDR * pNotifyStruct, LRESULT * result )
{
CString str;
str.Format("%d",id);
AfxMessageBox(str);}
我原来设想的是在成员函数中根据我点击控件的id做不同的处理,可问题是我不管点击那个控件,id值都是一样的。如果谁能帮我解决了,分不是问题,先给个200分

解决方案 »

  1.   

    设一个3维数组
    int ctrl[34][2][1]
    ctrl[控件总数][控件位置x,控件位置y][控件ID]
    用HOOK拦截鼠标 单击消息 查询数组 判断鼠标是否在控件位置x,y范围内,之后取控件ID
      

  2.   

    楼主的代码详细贴出来会比较好理解你的问题还有就是//{{AFX_ 跟 //}}AFX_  的语句之间最好都不要加东西。
      

  3.   

    ON_CONTROL_RANGE 是一样的,id值没变化
      

  4.   


    我试了可以 我的代码.h文件
    afx_msg void OnButtonClicked(UINT Id);.cpp文件
    ON_CONTROL_RANGE(BN_CLICKED,   IDC_BUTTON2-20,   IDC_BUTTON4,   OnButtonClicked)
    void   CXXDlg::OnButtonClicked(UINT   Id)   
    {   
    CString   message;   
    message.Format("你所选择的按钮ID是%d",Id);   
    AfxMessageBox(message);   

      

  5.   

    BN_CLICKED与NM_CLICK、ON_CONTROL_RANGE 和ON_NOTIFY_RANGE都组合过,id值就是不变化,统统一样
      

  6.   

    楼主对没有响应的控件单独使用ON_BN_CLICKED试一试
    比如 ON_BN_CLICKED(IDC_STATIC_***, OnClick***)
      

  7.   


    // 11Dlg.h : header file
    //#if !defined(AFX_11DLG_H__4FC61D10_D831_4481_BA70_DE2077BA3066__INCLUDED_)
    #define AFX_11DLG_H__4FC61D10_D831_4481_BA70_DE2077BA3066__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000/////////////////////////////////////////////////////////////////////////////
    // CMy11Dlg dialogclass CMy11Dlg : public CDialog
    {
    // Construction
    public:
    CMy11Dlg(CWnd* pParent = NULL); // standard constructor// Dialog Data
    //{{AFX_DATA(CMy11Dlg)
    enum { IDD = IDD_MY11_DIALOG };
    // NOTE: the ClassWizard will add data members here
    //}}AFX_DATA // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CMy11Dlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected:
    HICON m_hIcon; // Generated message map functions
    //{{AFX_MSG(CMy11Dlg)
    virtual BOOL OnInitDialog();
    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    afx_msg void OnButton1(UINT nID);                  //这里是你添加的消息,参数nID
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };//{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_11DLG_H__4FC61D10_D831_4481_BA70_DE2077BA3066__INCLUDED_)这里是.cpp文件
    // 11Dlg.cpp : implementation file
    //#include "stdafx.h"
    #include "11.h"
    #include "11Dlg.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog
    {
    public:
    CAboutDlg();// Dialog Data
    //{{AFX_DATA(CAboutDlg)
    enum { IDD = IDD_ABOUTBOX };
    //}}AFX_DATA // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CAboutDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected:
    //{{AFX_MSG(CAboutDlg)
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
    {
    //{{AFX_DATA_INIT(CAboutDlg)
    //}}AFX_DATA_INIT
    }void CAboutDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CAboutDlg)
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    //{{AFX_MSG_MAP(CAboutDlg)
    // No message handlers
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CMy11Dlg dialogCMy11Dlg::CMy11Dlg(CWnd* pParent /*=NULL*/)
    : CDialog(CMy11Dlg::IDD, pParent)
    {
    //{{AFX_DATA_INIT(CMy11Dlg)
    // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }void CMy11Dlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CMy11Dlg)
    // NOTE: the ClassWizard will add DDX and DDV calls here
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CMy11Dlg, CDialog)
    //{{AFX_MSG_MAP(CMy11Dlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
            //再加上这里就OK了,你的ID值是要有规律的,最好是连续的才行,
    比如说IDC_BUTTON1的ID值是1001,IDC_BUTTON11002,类推。那么IDC_BUTTON6是1006

    ON_CONTROL_RANGE(BN_CLICKED,IDC_BUTTON1,IDC_BUTTON6,OnButton1) 
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CMy11Dlg message handlersBOOL CMy11Dlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
    } // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon

    // TODO: Add extra initialization here

    return TRUE;  // return TRUE  unless you set the focus to a control
    }void CMy11Dlg::OnSysCommand(UINT nID, LPARAM lParam)
    {
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
    CAboutDlg dlgAbout;
    dlgAbout.DoModal();
    }
    else
    {
    CDialog::OnSysCommand(nID, lParam);
    }
    }// 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 CMy11Dlg::OnPaint() 
    {
    if (IsIconic())
    {
    CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (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 to obtain the cursor to display while the user drags
    //  the minimized window.
    HCURSOR CMy11Dlg::OnQueryDragIcon()
    {
    return (HCURSOR) m_hIcon;
    }void CMy11Dlg::OnButton1(UINT nID)    //点击消息
    {
    // TODO: Add your control notification handler code here
    CString str;
    str.Format("%d",nID);
    AfxMessageBox(str);
    }
      

  8.   

    或者把
    ON_CONTROL_RANGE(BN_CLICKED,IDC_BUTTON1,IDC_BUTTON6,OnButton1) 
    改成这个
    ON_COMMAND_RANGE(IDC_BUTTON1,IDC_BUTTON6,OnButton1)因为BN_CLICKED是WM_COMMAND的消息,不是WM_NOTIFY的消息。所以得用ON_COMMAND_RANGE宏来映射。