我打开了windows自己带的计算器,然后用spy++取得类名和窗口名hwnd=::FindWindow("SciCalc","计算器");为什么得不到正确的句柄?我是在2003下运行的

解决方案 »

  1.   

    在调试窗口显示
    hwnd  0xccccccc
    unused cxx0030:error:expression cannot be evaluated
      

  2.   

    SyntaxHWND FindWindow(          LPCTSTR lpClassName,
        LPCTSTR lpWindowName
    );
    ParameterslpClassName
    [in] Pointer to a null-terminated string that specifies the class name or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low-order word of lpClassName; the high-order word must be zero. 
    If lpClassName points to a string, it specifies the window class name. The class name can be any name registered with RegisterClass or RegisterClassEx, or any of the predefined control-class names. If lpClassName is NULL, it finds any window whose title matches the lpWindowName parameter. lpWindowName
    [in] Pointer to a null-terminated string that specifies the window name (the window's title). If this parameter is NULL, all window names match. // /////////////////////////
    你可以直接这样:
    hwnd=::FindWindow(NULL, "计算器");
    if(hwnd == NULL)
    {
       TRACE("Error: %d\n", GetLastError());
    }
      

  3.   

    你只用类名试试,将窗口名设为NULL
      

  4.   

    试过了无论是只有类名,还是只有窗口名,还是两个都有返回值都是0xcccccccc
      

  5.   

    hwnd=::FindWindow("SciCalc","计算器");类名不用加引号吧
    SciCalc
      

  6.   

    CWnd *pWnd;pWnd=FindWindow(_T("SciCalc"),_T("计算器"));呵呵,好像要引号.
      

  7.   

    在调试窗口显示
    hwnd  0xccccccc
    unused cxx0030:error:expression cannot be evaluated
    这个问题不大的。建议你使用spy++ 先看看计算器的句柄是多少。看看是否是你真的没有找对。
      

  8.   

    等运行了这个语句hwnd=::FindWindow("SciCalc","计算器");后
    你在看看hwnd的值是否有。
    这个语句运行前如果你没有对hwnd赋初值智能感知就会显示hwnd  0xccccccc
      

  9.   

    直接
    FindWindow(NULL,"计算器");