RT,注意该窗口可能不是前台窗口,也就是说改窗口对于用户来说不可见,求高手解答

解决方案 »

  1.   

    HWND -> DC -> GetPixel
      

  2.   

    这个不能用,好像该窗口不支持GetPixel函数
      

  3.   

    这个函数支持DC,是不支持HWND,但是DC是可以DC GetDC(HWND hWnd);的。这样不就从HWND到像素了?
    COLORREF GetPixel(HDC hdc, int nXPos, int nYPos)
      

  4.   

    Res
    The pixel must be within the boundaries of the current clipping region. Not all devices support GetPixel. An application should call GetDeviceCaps to determine whether a specified device supports this function没有clipping region呢,或者下面那个GetDevicecaps怎么来判断是否支持
      

  5.   

    窗口不支持??暂时我还没有遇到过,可以使用GetDCEx获取是内绘还是外绘。
    坐等高人
      

  6.   

    用日志钩子:#define WM_XXXXX WM_USER+1         //给我的程序发送的消息
    HWND hwndDlg = NULL;              //全局变量,我的窗口的hwnd
    HHOOK global_hhookJournalRecord = NULL; //全局变量,钩子句柄
    LRESULT CALLBACK JournalRecordProc(
       int code,       // hook code
       WPARAM wParam,  // not used
       LPARAM lParam   // messag
       )
    {
    if (code == HC_ACTION)
    {
    if (hwndDlg)
    SendMessage(hwndDlg,WM_XXXXX,wParam,lParam);//发给自己的程序
    }
    else if (code == HC_SYSMODALOFF)
    {
    ;
    }
    else if (code == HC_SYSMODALON)
    {
    ;
    }
    if (code <0)
    {
    CallNextHookEx(global_hhookJournalRecord,code,wParam,lParam);
    } return 0;}
    由于钩子函数需要知道把消息发给哪个窗口,我在OnInitDialog给他赋值
    hwndDlg = m_hWnd;挂钩:
    void CTstDisableDlg::OnBTHook() 
    {
    // TODO: Add your control notification handler code here
    global_hhookJournalRecord =  SetWindowsHookEx(WH_JOURNALRECORD,JournalRecordProc,(HINSTANCE  )AfxGetApp()->m_hInstance,0);
    }
    释放钩子:
    void CTstDisableDlg::OnBTUnHook() 
    {
    // TODO: Add your control notification handler code here
    if (global_hhookJournalRecord)
    {UnhookWindowsHookEx(global_hhookJournalRecord);
    }

    }
    在程序退出时,释放一下钩子:
    void CTstDisableDlg::PostNcDestroy() 
    {
    // TODO: Add your specialized code here and/or call the base class
    OnBTUnHook();
    CDialog::PostNcDestroy();
    }程序接收来自钩子的消息:
    定义:void OnJournalMsg( WPARAM wParam,LPARAM lParam );
    加入消息:ON_MESSAGE(WM_XXXXX,OnJournalMsg)
    函数实现:
    void CTstDisableDlg::OnJournalMsg(WPARAM wParam, LPARAM lParam)
    {
    PEVENTMSG pEventMsg;
    pEventMsg =PEVENTMSG(lParam);
    CString strTmp;
    /* strTmp.Format("%04X,%d,%d",pEventMsg->message,pEventMsg->paramH,pEventMsg->paramL);*/
    if (pEventMsg->message = WM_MOUSEMOVE)
    {
    HDC dc = ::GetDC(NULL);
    COLORREF coPixel =::GetPixel(dc,pEventMsg->paramL,pEventMsg->paramH);
    strTmp.Format("R=%03d,G=%03d,B=%03d",GetRValue(coPixel),GetGValue(coPixel),GetBValue(coPixel));
    }

    m__cEditHookDisp = strTmp;//我这里把它写到了一个编辑框里,你可以任意处理
    UpdateData(FALSE);
    }
      

  7.   

    这些代码都是我测试之后贴过来的,可以实现你所说的功能,当然,还有很多细节没有处理,比如,钩子函数中
    HC_SYSMODALOFF时需要处理,钩子被系统关闭后,再自动重新挂钩
    另外,我忘记了ReleaseDC