我用EnumChildWindows遍历一个窗口的句柄,并用用它最后一个参数LParam返回我想要的句柄.
我在EnumChildProc中,当取得我想要的窗口时,我将句柄赋值给它的Lparam参数,并且返回,中止遍历.代码在Win7下运行正常,EnumChildWindows的Lparam返回了我想要的句柄,完全正常.但是我切换到XP下测试,发现EnumChildWindows最后一个参数返回的总是0.
而我在EnumChildProc中输出了句柄,是正确的,但就是无法在EnumChildWindows中返回,很奇怪啊.
能帮忙解释一下是怎么回事么?

解决方案 »

  1.   

    你这个用法有问题
    LPARAM是让你用来传入的参数,是[in]
    而你把他当成了传出的参数,成了[out]
      

  2.   

    可是我在win7下运行正常呢
    我猜想是user32.dll版本的问题,所以把win7的user32.dll复制到我程序目录下,但仍然没有效果.
      

  3.   

    Lparam是回调函数EnumChildProc的入参,MSDN写的很清楚了。楼主用法不正确ParametershWndParent
    [in] 
    Handle to the parent window whose child windows are to be enumerated. If this parameter is NULL, this function is equivalent to EnumWindows.Windows 95/98/Me: hWndParent cannot be NULL.lpEnumFunc
    [in] Pointer to an application-defined callback function. For more information, see EnumChildProc. 
    lParam
    [in] Specifies an application-defined value to be passed to the callback function. 
    Return Value
      

  4.   

    我在WIN7下运行正常...只是XP不正常哎.
      

  5.   

    给 lParam 传入一个 HWND 的指针吧
      

  6.   

    BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam)
    {
      if (取得你想要的窗口)
      {
      *(HWND *)lParam = hwnd;
      return FALSE;
      }
      return TRUE;
    }
    HWND hWnd;
    EnumChildWindows(hWndParent, EnumChildProc, (LPARAM)&hWnd);
    //此时hWnd就是你想要的窗口的句柄
      

  7.   


    兄弟,你在XP下运行能得到正确的结果吗?我在WIN7下这代码确实行,但到XP就不行了..
      

  8.   

    提供一个昨天用的例子:
     ::EnumWindows(&EnumWindowsProc, processInfo.dwThreadId);int CALLBACK EnumWindowsProc(HWND hwnd, LPARAM param)
        {
            DWORD pID;
            DWORD TpID = GetWindowThreadProcessId(hwnd, &pID);
                if (TpID == (DWORD)param)
                    {
                    apphwnd=hwnd;
                    return false;
                    }
            return true;
        }http://www.codeproject.com/Articles/18724/Hosting-exe-applications-into-a-dialog
      

  9.   

    你用个全局的变量保存该HWND窗口句柄不行吗?