CPoint pt;
  GetCursorPos(&pt);
  CMy750_clientApp* app = (CMy750_clientApp*)AfxGetApp();
  HMENU hmenu = LoadMenu(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDR_MENU1));
  HMENU hpopup = GetSubMenu(hmenu, 0);
  switch(TrackPopupMenu(hpopup,TPM_RETURNCMD|TPM_RIGHTBUTTON,   
            pt.x,pt.y,0,m_hWnd,NULL))             
  {
case ID_Config1:  //配置中队
        
       m.Format(TEXT("%d"),(inifile.GetNumKeys()+1));
   ttt=m;
           //截取x=ip;y=netmask;z=gateway
   //   ".... .... ...."
   
   x = m_tree.GetItemText(m_tree.GetNextItem(TVI_ROOT,TVGN_CARET));
   temp=x.Mid(x.Find(" ")+1,x.GetLength());   
   z=temp.Mid(temp.Find(" ")+1,temp.GetLength());  
   x=x.Left(x.Find(" "));
   y=temp.Left(temp.Find(" "));
           
           //
           inifile.SetPath("test.ini");
           inifile.ReadFile();
   //根据中队名Name查找IP地址
           for(h=1;h<=(inifile.GetNumKeys());h++)
   {
             s.Format(TEXT("%d"),h); 
             if((inifile.GetValue(s,"Name"))==m_tree.GetItemText(m_tree.GetNextItem(TVI_ROOT,TVGN_CARET)))
 {
   x=inifile.GetValue(s,"Ip");
   y=inifile.GetValue(s,"NetMask");
   z=inifile.GetValue(s,"GateWay");
   ttt = s;
 }
   }
   ICspAdmin::CAMCFG *pCam = (ICspAdmin::CAMCFG *)m_tree.GetItemData(m_tree.GetNextItem(TVI_ROOT,TVGN_CARET));
   zzz dlg(pCam,ttt,m_tree.GetItemText(m_tree.GetNextItem(TVI_ROOT,TVGN_CARET)),x,y,z);
   dlg.DoModal(); 
   
   
   break;
case ID_Config3:
CSname dlg(NULL);
dlg.DoModal();
break;
这是我做的右健弹出式菜单的选择的语句,不过总报错,帮我看看,不胜感谢
C:\Downloads\750_client\750_clientDlg.cpp(439) : error C2360: initialization of 'dlg' is skipped by 'case' label
        C:\Downloads\750_client\750_clientDlg.cpp(434) : see declaration of 'dlg'
C:\Downloads\750_client\750_clientDlg.cpp(439) : error C2360: initialization of 'pCam' is skipped by 'case' label
        C:\Downloads\750_client\750_clientDlg.cpp(433) : see declaration of 'pCam'
C:\Downloads\750_client\750_clientDlg.cpp(440) : error C2371: 'dlg' : redefinition; different basic types
        C:\Downloads\750_client\750_clientDlg.cpp(434) : see declaration of 'dlg'

解决方案 »

  1.   

    要在case里面定义变量,需要用{}
    比如
    switch(a)
    {
    case 1:
       {
           int b=0;
       }
       break;
    ...
      

  2.   

    你的dlg不能在CASE里为变量,应放在SWITCH之前,这样就不会错了
      

  3.   

    case ID_Config3:
    CSname dlg(NULL);
    dlg.DoModal();
    break;改为
    case ID_Config3:
    {
    CSname dlg(NULL);
    dlg.DoModal();
    }
    break;
      

  4.   

    给case里面加上
    {
    }
      

  5.   

    dlg放在switch前那还怎么选择呢,我就是要用switch选者打开哪个对话框
    请详细说一下好吗
      

  6.   

    pt.x,pt.y,0,m_hWnd,NULL))             
      {
    case ID_Config1:  //配置中队
    {        
           m.Format(TEXT("%d"),(inifile.GetNumKeys()+1));
       ttt=m;
               //截取x=ip;y=netmask;z=gateway
       //   ".... .... ...."
       
       x = m_tree.GetItemText(m_tree.GetNextItem(TVI_ROOT,TVGN_CARET));
       temp=x.Mid(x.Find(" ")+1,x.GetLength());   
       z=temp.Mid(temp.Find(" ")+1,temp.GetLength());  
       x=x.Left(x.Find(" "));
       y=temp.Left(temp.Find(" "));
               
               //
               inifile.SetPath("test.ini");
               inifile.ReadFile();
       //根据中队名Name查找IP地址
               for(h=1;h<=(inifile.GetNumKeys());h++)
       {
                 s.Format(TEXT("%d"),h); 
                 if((inifile.GetValue(s,"Name"))==m_tree.GetItemText(m_tree.GetNextItem(TVI_ROOT,TVGN_CARET)))
     {
       x=inifile.GetValue(s,"Ip");
       y=inifile.GetValue(s,"NetMask");
       z=inifile.GetValue(s,"GateWay");
       ttt = s;
     }
       }
       ICspAdmin::CAMCFG *pCam = (ICspAdmin::CAMCFG *)m_tree.GetItemData(m_tree.GetNextItem(TVI_ROOT,TVGN_CARET));
       zzz dlg(pCam,ttt,m_tree.GetItemText(m_tree.GetNextItem(TVI_ROOT,TVGN_CARET)),x,y,z);
       dlg.DoModal(); 
       
       
       break;
              }
    case ID_Config3:
             {
    CSname dlg(NULL);
    dlg.DoModal();
    break;
              }
      

  7.   

    请参见MSDN的错误说明C2360,给出的例子和你的错误一样.
      

  8.   

    switch(TrackPopupMenu(hpopup,TPM_RETURNCMD|TPM_RIGHTBUTTON,   
                pt.x,pt.y,0,m_hWnd,NULL))             没有结束语句.
      

  9.   

    case ....
    {        CSname dlg(NULL);
            dlg.DoModal();
            break;
    }