HWND myWnd=NULL;
#define CLASS_SIZE 1024
//查找子窗体控件
BOOL CALLBACK ChildWndProc(HWND hwnd, LPARAM lParam)
{
        HGLOBAL hglb=NULL;
        char className[CLASS_SIZE];
        if (GetClassName(hwnd,className,CLASS_SIZE)==0)
                return TRUE;
        CString str(className);
        if(str==_T("ListBox"))
        {
                HWND parentHwnd = ::GetParent(hwnd);
                myWnd = hwnd;
        }
        return TRUE;
}
void OnButton1()
{
        CWnd *pWnd;
        pWnd = CWnd::FindWindow (NULL,"makeini");//应用程序的窗体标题
        if (pWnd != NULL)
        {
                HWND hwnd3=pWnd->m_hWnd ;
                EnumChildWindows(hwnd3,ChildWndProc,0);//获得ListBox控件hWnd -> myWnd
                char className[CLASS_SIZE];
                if (GetClassName(myWnd,className,CLASS_SIZE)==0)
                        return;// TRUE;
                CString str(className);
                if(str==_T("ListBox"))
                {
                        int sendId2 = ::GetDlgCtrlID (myWnd);
                        for(int j=0;j<2;j++)
                        {
                                CWnd *pWnd2 = pWnd->GetDlgItem(sendId2);
                                if (pWnd2 != NULL)//有时第一次返回空
                                {
                                        CString str2;
                                        CListBox *m_listParam=(CListBox*)pWnd2;
                                        int i=m_listParam->GetCurSel();//获得被选择的区域索引号
                                        if(i>=0)
                                        {
                                                str2.Format("列表项索引为[%d]",i);
                                                MessageBox(str2);
                                                CRect reWindow;
                                                pWnd->GetWindowRect(reWindow);//makeini的窗体坐标
                                                str2.Format("窗体坐标[%d][%d][%d][%d]",reWindow.TopLeft(),reWindow.BottomRight(),reWindow.Width(),reWindow.Height());
                                                MessageBox(str2);
                                                m_listParam->GetWindowRect(reWindow);//ListBox控件的坐标
                                                str2.Format("控件坐标[%d][%d][%d][%d]",reWindow.TopLeft(),reWindow.BottomRight(),reWindow.Width(),reWindow.Height());
                                                MessageBox(str2);
                                                m_listParam->GetItemRect(i,reWindow);//中的某一项的坐标
                                                str2.Format("列表项坐标[%d][%d][%d][%d]",reWindow.TopLeft(),reWindow.BottomRight(),reWindow.Width(),reWindow.Height());
                                                MessageBox(str2);
                                                int mHeight=m_listParam->GetItemHeight(i);//
                                                str2.Format("高度为[%d]",mHeight);
                                                MessageBox(str2);
                                        }
                                        else
                                        {
                                                MessageBox("没有选择列表项!");
                                        }                                        i=m_listParam->GetCount()-1;
                                        CString strLine;
                                        str2="所有内容:\r\n";
                                        for(i=0;i<m_listParam->GetCount();i++)
                                        {
                                                m_listParam->GetText(i,strLine);
                                                str2+=strLine;
                                        }
                                        MessageBox(str2);
                                        MessageBox("下一步,删除所有内容!");
                                        while(m_listParam->GetCount()>0)
                                                m_listParam->DeleteString(0);
                                        break;
                                }
                        }
                }
        }
        return;
}
我用以上办法可以取得ListBox上的任意思东西,但是MSFlexGrid和MSHFlexGrid这两个控件我也用类似的办法做,却连ID都取不出来,请问这是为什么?有什么办法解决吗?我急需答案,在线等,QQ:28290994!谢谢了!http://www.xiaohui.com/forum/viewthread.php?tid=4872&pid=102029&page=2&sid=t52tvstn#pid102029

解决方案 »

  1.   

    CMSHFlexGrid    m_Grid;
    1)取(i,j)格数据
      CString strText = m_Grid.GetTextMatrix( i, j );
    2)设置(i,j)格数据
      CString strText("Data");
      m_Grid.GetTextMatrix( i, j ,strText);
      

  2.   

    还有,设置和获得当前行列的方式
    m_Grid.SetRow(int);
    m_Grid.SetCol(int);
    m_Grid.GetRow(int);
    m_Grid.GetCol(int);
      

  3.   

    对了,还有个前提,那就是CMSHFlexGrid控件不是本程序上的控件,我是想通过自己的程序控制其它程序上的CMSHFlexGrid控件
      

  4.   

    我上面代码中的makeini就是一个应用程序的窗体标题,不是本程序的
      

  5.   

    strValue = m_grid.get_TextMatrix(oldRow,1);//读取数据 m_grid.put_Row(i+1);//往flexgrid里添加 i+1行
    m_grid.put_Col(0);//i+1行,0列
    str.Format(_T("%d"),i+1);
    m_grid.put_Text(str);
    m_grid.put_Col(1);//i+1行,1列
    strValue = _T(" ") + strValue;
    m_grid.put_Text(strValue);
    m_grid.put_Col(2); //i+1行,2列
    strContent = _T(" ") + strContent;
    m_grid.put_Text(strContent);
    m_grid.put_Col(3);
    strDate = _T(" ") + strDate;
    m_grid.put_Text(strDate);
      

  6.   

    一再强调的条件怎么就没人看呢,要获得其它应用程序上的MSFGrid控件的内容。
      

  7.   

    你用SPY++看一看要取的那个窗口里的的确是MSFGrid控件吗?