我在CMainFrame中
ON_COMMAND_RANGE(0,0xFFFF, OnCommandRange)捕获所有的WM_COMMAND消息,
结果诸如ID_APP_ABOUT,ID_FILE_NEW等命令消息都被捕捉了,主线程CWinApp没有处理。
我在自己的OnCommandRange()函数最后加入
const MSG *pMsg=GetCurrentMessage();
afxGetApp()->PostThreadMessage(pMsg->message,pMsg->wParam,pMsg->lParam);
将帮助消息传给主线程,但依然没有效果。为何啊?

解决方案 »

  1.   

    呵呵,是有点怪,帮不上了,只好帮你up,gz一下了
      

  2.   

    主线程应该用ON_THREAD_MESSAGE声明把
      

  3.   

    主线程是这样的:
    BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
    //{{AFX_MSG_MAP(CMainFrame)
    ON_WM_CREATE()
    ON_MESSAGE(WM_OUTBAR_NOTIFY,OnListGroupNotify)
    //}}AFX_MSG_MAP
    ON_UPDATE_COMMAND_UI_RANGE(0,0xFFFF,OnUpdateCommandUIRange)
    ON_COMMAND_RANGE(0,0xFFFF, OnCommandRange)
    END_MESSAGE_MAP()
      

  4.   

    sorry 发错了:是这样的才对:
    BEGIN_MESSAGE_MAP(CBiomApp, CWinApp)
    //{{AFX_MSG_MAP(CBiomApp)
    ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
    // NOTE - the ClassWizard will add and remove mapping macros here.
    //    DO NOT EDIT what you see in these blocks of generated code!
    //}}AFX_MSG_MAP
    // Standard file based document commands
    ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
    ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
    // Standard print setup command
    ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
    END_MESSAGE_MAP()
      

  5.   

    我在自己的OnCommandRange()函数最后加入
    const MSG *pMsg=GetCurrentMessage();
    afxGetApp()->PostThreadMessage(pMsg->message,pMsg->wParam,pMsg->lParam);
    ////////////////////////////////////
    贴完整一点
    你上面说的东西再哪里?
      

  6.   

    // 处理菜单命令
    void CMainFrame::OnCommandRange(UINT nId)
    {
    switch(nId)
    {
    case ID_VIEW_STOCK: //进货报表
    case ID_VIEW_STORE: //库存报表
    case ID_VIEW_OUTLIB: //出库报表
    case ID_VIEW_GOODSRACK: //货架报表
    case ID_VIEW_SELL: //销售报表
    {
    int nReport=0;
    if(nId==ID_VIEW_STOCK)
    nReport=STOCK_REPORT;
    else if(nId==ID_VIEW_STORE)
    nReport=STORE_REPORT;
    else if(nId==ID_VIEW_OUTLIB)
    nReport=OUTLIB_REPORT;
    else if(nId==ID_VIEW_GOODSRACK)
    nReport=GOODSRACK_REPORT;
    else
    nReport=SELL_REPORT; CBiomView* pView = GetRightPane();
    if(pView)
    pView->ReportActive(nReport);
    }
    break;
    case ID_MANAGER_STOCK: //进货管理
    {
    CManagerStockDlg dlgManagerStock(&theDatabase);
    if(dlgManagerStock.DoModal()==IDOK)
    {
    int iPages=dlgManagerStock.m_StockInfos.GetSize();
    int iPage=0;
    CString strSQL;
    for(iPage=0;iPage<iPages;iPage++)
    {
    STOCKINFO &StockInfo=dlgManagerStock.m_StockInfos[iPage];
    TRY
    {
    strSQL.Format(_T("INSERT INTO 进货 (商品代号,进货日期,进货批次,进货数量,进货价格,进货员,入库员,货源单位)"
    "VALUES ('%s',#%s#,%d,%f,%f,'%s','%s','%s');"),
    StockInfo.szGoodsID,
    StockInfo.tmStock.Format(_T("%Y-%m-%d")),
    StockInfo.iGroup,
    StockInfo.dAmount,
    StockInfo.dPrice,
    StockInfo.szStocker,
    StockInfo.szStorer,
    StockInfo.szStockFrom);
    theDatabase.Execute(strSQL,dbDenyWrite|dbConsistent);
    strSQL.Format(_T("INSERT INTO 库存 (商品代号,进货日期,进货批次,库存商品数量)"
    "VALUES ('%s',#%s#,%d,%f);"),
    StockInfo.szGoodsID,
    StockInfo.tmStock.Format(_T("%Y-%m-%d")),
    StockInfo.iGroup,
    StockInfo.dAmount);
    theDatabase.Execute(strSQL,dbDenyWrite|dbConsistent);
    }
    CATCH(CDaoException,e)
    {
    #ifdef _DEBUG
    e->ReportError();
    #endif
    }
    END_CATCH
    }
    if(iPages&&MessageBox(_T("进货和库存记录已经更新,要重新创建进货和库存报表吗?"),NULL,MB_YESNO|MB_ICONQUESTION)==IDYES)
    {
    CBiomView* pView = GetRightPane();
    if(pView)
    {
    pView->DoReport(STOCK_REPORT,&theDatabase,m_dlgReportStock.m_strSQL);
    pView->DoReport(STORE_REPORT,&theDatabase,m_dlgReportStore.m_strSQL);
    }
    }
    }
    }
    break;
    case ID_MANAGER_OUTLIB: //出库管理
    {
    CManagerOutlibDlg dlgManagerOutlib(&theDatabase);
    if(dlgManagerOutlib.DoModal()==IDOK)
    {
    TRY
    {
    CString strSQL;
    strSQL.Format(_T("UPDATE 库存 SET 库存商品数量=库存商品数量-%f WHERE (((库存.商品代号)='%s') AND ((库存.进货日期)=#%s#) AND ((库存.进货批次)=%d));"),
    dlgManagerOutlib.m_dAmount,
    dlgManagerOutlib.m_strGoodsID,
    dlgManagerOutlib.m_tmStock.Format(_T("%Y-%m-%d")),
    dlgManagerOutlib.m_nGroup);
    theDatabase.Execute(strSQL,dbDenyWrite|dbConsistent);
    strSQL.Format(_T("INSERT INTO 出库 (商品代号,进货日期,进货批次,出库数量,出库员,货架号)"
    "VALUES ('%s',#%s#,%d,%f,'%s','%s');"),
    dlgManagerOutlib.m_strGoodsID,
    dlgManagerOutlib.m_tmStock.Format(_T("%Y-%m-%d")),
    dlgManagerOutlib.m_nGroup,
    dlgManagerOutlib.m_dAmount,
    dlgManagerOutlib.m_strOutLiber,
    dlgManagerOutlib.m_strRackId);
    theDatabase.Execute(strSQL,dbDenyWrite|dbConsistent); strSQL.Format(_T("SELECT 货架.货架商品数量 FROM 货架 WHERE (((货架.商品代号)='%s') AND ((货架.进货日期)=#%s#) AND ((货架.进货批次)=%d));"),
    dlgManagerOutlib.m_strGoodsID,
    dlgManagerOutlib.m_tmStock.Format(_T("%Y-%m-%d")),
    dlgManagerOutlib.m_nGroup);
    CDaoRecordset Recordset(&theDatabase);
    Recordset.Open(dbOpenDynaset,strSQL,dbDenyRead);
    if(Recordset.IsEOF())
    {
    strSQL.Format(_T("INSERT INTO 货架(商品代号,进货日期,进货批次,货架商品数量) VALUES ('%s',#%s#,%d,%f);"),
    dlgManagerOutlib.m_strGoodsID,
    dlgManagerOutlib.m_tmStock.Format(_T("%Y-%m-%d")),
    dlgManagerOutlib.m_nGroup,
    dlgManagerOutlib.m_dAmount);
    }
    else
    {
    strSQL.Format(_T("UPDATE 货架 SET 货架商品数量=%f+货架商品数量 WHERE (((货架.商品代号)='%s') AND ((货架.进货日期)=#%s#) AND ((货架.进货批次)=%d));"),
    dlgManagerOutlib.m_dAmount,
    dlgManagerOutlib.m_strGoodsID,
    dlgManagerOutlib.m_tmStock.Format(_T("%Y-%m-%d")),
    dlgManagerOutlib.m_nGroup);
    }
    Recordset.Close();
    theDatabase.Execute(strSQL,dbDenyWrite|dbConsistent);
    }
    if(MessageBox(_T("库存、货架和出库记录已经更新,要重新创建库存、货架和出库报表吗?"),NULL,MB_YESNO|MB_ICONQUESTION)==IDYES)
    {
    CBiomView* pView = GetRightPane();
    if(pView)
    {
    pView->DoReport(STORE_REPORT,&theDatabase,m_dlgReportStore.m_strSQL);
    pView->DoReport(GOODSRACK_REPORT,&theDatabase,m_dlgReportGoodsRack.m_strSQL);
    pView->DoReport(OUTLIB_REPORT,&theDatabase,m_dlgReportOutLib.m_strSQL);
    }
    }
    CATCH(CDaoException,e)
    {
    #ifdef _DEBUG
    e->ReportError();
    #endif
    }
    END_CATCH
    }
    }
    break;
    case ID_MANAGER_SELL: //销售管理
    {
    CManagerSellDlg dlgManagerSell(&theDatabase);
    if(dlgManagerSell.DoModal()==IDOK)
    {
    TRY
    {
    CString strSQL;
    strSQL.Format(_T("UPDATE 货架 SET 货架商品数量=货架商品数量-%f WHERE (((货架.商品代号)='%s') AND ((货架.进货日期)=#%s#) AND ((货架.进货批次)=%d));"),
    dlgManagerSell.m_dAmount,
    dlgManagerSell.m_strGoodsID,
    dlgManagerSell.m_tmStockTime.Format(_T("%Y-%m-%d")),
    dlgManagerSell.m_nGroup);
    theDatabase.Execute(strSQL,dbDenyWrite|dbConsistent);
    strSQL.Format(_T("INSERT INTO 销售 (商品代号,进货日期,进货批次,售货时间,售货员,单价,数量,折扣)"
    "VALUES ('%s',#%s#,%d,#%s#,'%s',%f,%f,%f);"),
    dlgManagerSell.m_strGoodsID,
    dlgManagerSell.m_tmStockTime.Format(_T("%Y-%m-%d")),
    dlgManagerSell.m_nGroup,
    dlgManagerSell.m_tmSellTime.Format(_T("%Y-%m-%d")),
    dlgManagerSell.m_strSeller,
    dlgManagerSell.m_dSellPrice,
    dlgManagerSell.m_dAmount,
    dlgManagerSell.m_dAgio);
    theDatabase.Execute(strSQL,dbDenyWrite|dbConsistent);
    }
    if(MessageBox(_T("货架和销售记录已经更新,要重新创建货架和销售报表吗?"),NULL,MB_YESNO|MB_ICONQUESTION)==IDYES)
    {
    CBiomView* pView = GetRightPane();
    if(pView)
    {
    pView->DoReport(GOODSRACK_REPORT,&theDatabase,m_dlgReportGoodsRack.m_strSQL);
    pView->DoReport(SELL_REPORT,&theDatabase,m_dlgReportSell.m_strSQL);
    }
    }
    CATCH(CDaoException,e)
    {
    #ifdef _DEBUG
    e->ReportError();
    #endif
    }
    END_CATCH
    }
    }
    break;
    case ID_STATISTIC_STOCK: //进货统计
    if(m_dlgReportStock.DoModal()==IDOK)
    {
    CBiomView* pView = GetRightPane();
    if(pView)
    {
    pView->DoReport(STOCK_REPORT,&theDatabase,m_dlgReportStock.m_strSQL);
    pView->ReportActive(STOCK_REPORT);
    }
    }
    break;
    case ID_STATISTIC_STORE: //库存统计
    if(m_dlgReportStore.DoModal()==IDOK)
    {
    CBiomView* pView = GetRightPane();
    if(pView)
    {
    pView->DoReport(STORE_REPORT,&theDatabase,m_dlgReportStore.m_strSQL);
    pView->ReportActive(STORE_REPORT);
    }
    }
    break;
    case ID_STATISTIC_OUTLIB: //出库统计
    if(m_dlgReportOutLib.DoModal()==IDOK)
    {
    CBiomView* pView = GetRightPane();
    if(pView)
    {
    pView->DoReport(OUTLIB_REPORT,&theDatabase,m_dlgReportOutLib.m_strSQL);
    pView->ReportActive(OUTLIB_REPORT);
    }
    }
    break;
    case ID_STATISTIC_GOODSRACK: //货架统计
    if(m_dlgReportGoodsRack.DoModal()==IDOK)
    {
    CBiomView* pView = GetRightPane();
    if(pView)
    {
    pView->DoReport(GOODSRACK_REPORT,&theDatabase,m_dlgReportGoodsRack.m_strSQL);
    pView->ReportActive(GOODSRACK_REPORT);
    }
    }
    break;
    case ID_STATISTIC_SELL: //销售统计
    if(m_dlgReportSell.DoModal()==IDOK)
    {
    CBiomView* pView = GetRightPane();
    if(pView)
    {
    pView->D
      

  7.   

    你在app中用ON_THREAD_MESSAGE宏试试。
      

  8.   

    老兄,你是向主线程PostThreadMessage
    主线程应该用ON_THREAD_MESSAGE声明这个消息才行啊
      

  9.   

    奇怪,不应该这样。
    既然是截获所有Command消息,直接重载CMainFrame::OnCommand()吧:
    WORD wNotifyCode = HIWORD(wParam); // notification code 
    WORD wID = LOWORD(wParam);         // item, control, or accelerator identifier 
    HWND hwndCtl = (HWND) lParam;      // handle of control 
    注意把不处理的Command消息留给基类处理。
      

  10.   

    在MDI中不行在SDI和Dialog中是可以的!
      

  11.   

    你再试试app类的PreTranslateMessage,看能不能收到你发出的消息。
      

  12.   

    try this:
    _AFX_THREAD_STATE* pThreadState=AfxGetThreadState();
    MSG& msg = pThreadState->m_lastSentMsg;
    PostThreadMessage(msg, msg.wParam, msg.lParam);