65,187
社区成员




HDC hDC = CreateDC(TEXT("DISPLAY"),NULL,NULL,NULL);
COLORREF clr = ::GetPixel(hDC, x, y);
#pragma data_seg("my_data")
HHOOK hHook = NULL;
HWND hMainWnd = NULL;
HDC hDC = CreateDC(TEXT("DISPLAY"),NULL,NULL,NULL);
CPoint pt;
COLORREF clr;
#pragma data_seg()
#pragma comment(linker, "/SECTION:my_data,RWS")
LRESULT CALLBACK MouseProc(int nCode,WPARAM wParam,LPARAM lParam)
{
hMainWnd = FindWindow(NULL, "拾色器");
if(hMainWnd==NULL)
::MessageBox(NULL, "NULL", 0, 0);
MOUSEHOOKSTRUCT *mht = (MOUSEHOOKSTRUCT*)lParam;
clr = ::GetPixel(hDC, mht->pt.x, mht->pt.y);
int nRed = GetRValue(clr);
int nGreen = GetGValue(clr);
int nBlue = GetBValue(clr);
// char ch[20];
// sprintf(ch, "r=%d, g=%d, b=%d",nRed,nGreen,nBlue);
// TRACE0(ch);
// ::MessageBox(NULL, ch, 0, 0);
SetDlgItemInt(hMainWnd, IDC_RED, nRed, FALSE);
SetDlgItemInt(hMainWnd, IDC_GREEN, nGreen, FALSE);
SetDlgItemInt(hMainWnd, IDC_BLUE, nBlue, FALSE);
return CallNextHookEx(hHook,nCode,wParam,lParam);
}
HHOOK InstallMyHook()
{
hHook = SetWindowsHookEx(WH_MOUSE, MouseProc, GetModuleHandle(NULL), NULL);
return hHook;
}
void UninstallMyHook()
{
::ReleaseDC(NULL, hDC);
::UnhookWindowsHookEx(hHook);
}
#include <iostream.h>
#include <windows.h>
int main()
{
POINT p;
while(true)
{
if(GetCursorPos(&p))
{
cout<<p.x<<","<<p.y<<endl;
Sleep(500);
system("cls");
}
}
}