//Name : FindHandle
//By : Softwaring
//总共三个文件
//FindHandle.c
#include
#include "resource.h"
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("FindHandle") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
HACCEL hAccel;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (hInstance, szAppName) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = CreateSolidBrush (RGB (240, 240, 240)); ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, // window class name
TEXT ("Find Handle"), // window caption
WS_CAPTION | WS_SYSMENU |
WS_MINIMIZEBOX, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
450, // initial x size
300, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
hAccel = LoadAccelerators (hInstance, TEXT ("EXIT"));
while (GetMessage (&msg, NULL, 0, 0))
{
if (!TranslateAccelerator (hwnd, hAccel, &msg))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
}
DeleteObject (CreateSolidBrush (RGB (240, 240, 240)));
return msg.wParam ;
}
void InitFont (LOGFONT *lf)
{
lf->lfHeight = 16;
lf->lfWidth = 0 ;
lf->lfEscapement = 0 ;
lf->lfOrientation = 0 ;
lf->lfWeight = 400 ;
lf->lfItalic = 0 ;
lf->lfUnderline = 0 ;
lf->lfStrikeOut = 0 ;
lf->lfCharSet = DEFAULT_CHARSET ;
lf->lfOutPrecision = 0 ;
lf->lfClipPrecision = 0 ;
lf->lfQuality = 0 ;
lf->lfPitchAndFamily = 0 ;
lstrcpy (lf->lfFaceName, TEXT ("MS Sns Serif"));
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
LOGFONT lf;
HWND TempHandle;
POINT TempPoint;
int i;
static HFONT hFont;
static HINSTANCE hInstance;
static HWND Handle;
static POINT point;
static TCHAR szHandle[MAX], szText[MAX], szClass[MAX], szPoint[MAX];
static BOOL Flag = TRUE;
static int cxChar, cyChar;
static HDC hdcEdit;
switch (message)
{
case WM_CREATE :
cxChar = LOWORD(GetDialogBaseUnits());
cyChar = HIWORD(GetDialogBaseUnits());
InitFont (&lf);
hFont = CreateFontIndirect (&lf);
for (i = 0; i < 4; ++i)
Handle = CreateWindow (TEXT ("Edit"), NULL,
WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL,
450 - 40 * cxChar, 10 + i * 40, 35 * cxChar, cyChar,
hwnd, (HMENU) (IDE_HWND + i), hInstance, 0);
CreateWindow (TEXT ("Button"), TEXT ("Get Again"),
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
150, 160, 15 * cxChar , 7 * cyChar / 4,
hwnd, (HMENU) IDB_GET, hInstance, 0);
SetTimer (hwnd, IDT_TIME, 10, NULL);
EnableWindow (GetDlgItem (hwnd, IDB_GET), FALSE);
RegisterHotKey (hwnd, GetCurrentTime (), (UINT) NULL, VK_F1);
return 0;
case WM_TIMER :
GetCursorPos (&TempPoint);
if (point.x != TempPoint.x || point.y != TempPoint.y)
{
point = TempPoint;
wsprintf (szPoint, TEXT ("X : %d, Y : %d"), point.x, point.y);
SetWindowText (GetDlgItem (hwnd, IDE_POINT), szPoint);
}
TempHandle = WindowFromPoint (point);
if (TempHandle != Handle && Flag)
{
Handle = TempHandle;
wsprintf (szHandle, TEXT ("%d"), Handle);
SetWindowText (GetDlgItem (hwnd, IDE_HWND), szHandle);
GetWindowText (Handle, szText, MAX);
SetWindowText (GetDlgItem (hwnd, IDE_TEXT), szText);
GetClassName (Handle, szClass, MAX);
SetWindowText (GetDlgItem (hwnd, IDE_CLASS), szClass);
}
return 0;
case WM_HOTKEY :
Flag = FALSE;
EnableWindow (GetDlgItem (hwnd, IDB_GET), TRUE);
return 0;
case WM_CTLCOLOREDIT :
hdcEdit = (HDC) wParam;
//SetTextColor (hdcEdit, RGB (255, 255, 0));
//SetBkColor (hdcEdit, RGB (255, 0, 0));
SelectObject (hdcEdit, hFont);
return 0;
case WM_COMMAND :
switch (LOWORD (wParam))
{
case IDB_GET :
Flag = TRUE;
EnableWindow (GetDlgItem (hwnd, IDB_GET), FALSE);
return 0;
case IDB_EXIT :
SendMessage (hwnd, WM_CLOSE, 0, 0);
return 0;
}
break;
case WM_PAINT :
hdc = BeginPaint (hwnd, &ps);
SetBkMode (hdc, TRANSPARENT);
SelectObject (hdc, hFont);
TextOut (hdc, 10, 10, TEXT ("Handle :"), lstrlen (TEXT ("Handle :")));
TextOut (hdc, 10, 50, TEXT ("WindowText :"), lstrlen (TEXT ("WindowText :")));
TextOut (hdc, 10, 90, TEXT ("ClassName :"), lstrlen (TEXT ("ClassName :")));
TextOut (hdc, 10,130, TEXT ("Point :"), lstrlen (TEXT ("Point :")));
TextOut (hdc, 10, 200, TEXT ("F1 to Locking Edit."), lstrlen ("F1 to Locking Edit."));
TextOut (hdc, 10, 220, TEXT ("Esc
to Exit."), lstrlen (TEXT ("Esc to Exit.")));
TextOut (hdc, 300, 240, TEXT ("By : Softwaring"), lstrlen (TEXT ("By : Softwaring")));
EndPaint (hwnd, &ps);
return 0;
case WM_DESTROY :
DeleteObject (hFont);
KillTimer (hwnd, IDT_TIME);
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam);
}
//FindHandle.rc 文件
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE 4, 2
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
//ACCEL
EXIT ACCELERATORS
BEGIN
VK_ESCAPE, IDB_EXIT, VIRTKEY, NOINVERT
END
FINDHANDLE ICON "FindHandle.ico"
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
//resource.h 文件
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by FindHandle.rc
#define IDT_TIME 1
#define IDE_HWND 2
#define IDE_TEXT 3
#define IDE_CLASS 4
#define IDE_POINT 5
#define IDB_GET 6
#define IDB_EXIT 7
#define MAX 128
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif