#include <WINDOWS.H>
void GetInfo (int *, int *) ;
LRESULT CALLBACK WndProc(HWND , UINT, WPARAM, LPARAM) ;
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
static TCHAR Name[] = TEXT("What Color") ;
HWND hWnd ;
int cxClient, cyClient ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hbrBackground = (HBRUSH)(GetStockObject(WHITE_BRUSH) ) ;
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW) ;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION) ;
wndclass.hInstance = hInstance ;
wndclass.lpfnWndProc = WndProc ;
wndclass.lpszClassName = Name ;
wndclass.lpszMenuName =NULL ;
wndclass.style = CS_VREDRAW || CS_HREDRAW ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("ERROE"),
Name, MB_ICONERROR) ;
return 0 ;
}
GetInfo(&cxClient, &cyClient) ;
hWnd = CreateWindow(Name, TEXT("Color"), WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_BORDER,
CW_USEDEFAULT, CW_USEDEFAULT,
cxClient, cyClient, NULL, NULL,
hInstance, NULL) ;
ShowWindow(hWnd, nShowCmd) ;
UpdateWindow(hWnd) ;
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg) ;
DispatchMessage(&msg) ;
}
return msg.wParam ;
}
void GetInfo(int * pcxClient, int * pcyClient)
{
HDC hdc ;
TEXTMETRIC tm ;
hdc = CreateIC (TEXT ("DISPLAY"), NULL, NULL, NULL) ;
GetTextMetrics (hdc, &tm) ;
DeleteDC (hdc) ;
// 建立对话框宽度,高度
*pcxClient = GetSystemMetrics(SM_CXBORDER) +
12 * tm.tmAveCharWidth ;
*pcyClient = GetSystemMetrics(SM_CYBORDER) +
2 * tm.tmHeight + GetSystemMetrics(SM_CYCAPTION) ;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wparam, LPARAM lparam)
{
static COLORREF cr , cr2 ;
static HDC hdc ;
HDC hdc1 ;
RECT re ;
POINT pt ;
static PAINTSTRUCT ps ;
TCHAR szBuffer[16] ;
switch(message)
{
case WM_CREATE :
hdc = CreateDC (TEXT ("DISPLAY"), NULL, NULL, NULL) ;
SetTimer (hWnd, 1, 100, NULL) ;
return 0 ;
case WM_TIMER :
GetCursorPos(&pt) ;
cr = GetPixel(hdc, pt.x, pt.y) ;
//获取的颜色改变则重画窗口
if(cr != cr2)
{
cr2 = cr ;
InvalidateRect(hWnd, NULL, FALSE) ;
}
return 0 ;
case WM_PAINT :
hdc1 = BeginPaint (hWnd, &ps) ;
GetClientRect(hWnd, &re) ;
wsprintf(szBuffer, TEXT(" %02X %02X %02X "), GetRValue(cr), GetGValue(cr), GetBValue(cr) ) ;
DrawText(hdc1, szBuffer, -1, &re,
DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
EndPaint(hWnd, &ps) ;
return 0 ;
case WM_DISPLAYCHANGE:
DeleteDC (hdc) ;
hdc = CreateDC (TEXT ("DISPLAY"), NULL, NULL, NULL) ;
return 0 ;
case WM_DESTROY :
DeleteDC (hdc) ;
KillTimer (hWnd, 1) ;
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc(hWnd, message, wparam, lparam) ;
}
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)