// autoclick.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include <stdlib.h>
#define settext(h,s) SendMessage(h,WM_SETTEXT,NULL,s)
#define gettext(h,maxc,s) SendMessage(h,WM_GETTEXT,maxc,s)
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
HINSTANCE hInst; // current instance
HFONT hFont;
HWND hWnd; // Main Window Handle
HWND txtTimes, cmdStart, Label1;
bool start = false;
int n;
int num;
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC) WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(wcex.hInstance, NULL);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = CreateSolidBrush (14933984);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "AppClass";
wcex.hIconSm = LoadIcon(wcex.hInstance, NULL);
if (!RegisterClassEx(&wcex)) {return 0;};
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindowEx (WS_EX_WINDOWEDGE, "AppClass", "Auto click",
WS_VISIBLE | WS_OVERLAPPED | WS_CLIPSIBLINGS | WS_CLIPCHILDREN
| WS_CAPTION | WS_SYSMENU,
451, 72 , 174, 110, NULL, NULL, hInstance, NULL);
if (!hWnd) {return 0;};
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
};
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
/**********************START CREATING CONTROLS*********************/
hFont = CreateFont (-MulDiv(10, GetDeviceCaps(GetDC (0), LOGPIXELSY), 72), 0, 0, 0, 400, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, DEFAULT_PITCH, "MS Sans Serif");
SendMessage (hWnd, WM_SETFONT, (WPARAM) hFont, MAKELPARAM (TRUE, 0));
txtTimes = CreateWindowEx (WS_EX_CLIENTEDGE, "Edit", "", WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP | ES_NUMBER, 8, 8, 73, 24, hWnd, NULL, hInst, NULL);
if (!txtTimes) {return FALSE;};
SendMessage (txtTimes, WM_SETFONT, (WPARAM) hFont, MAKELPARAM (TRUE, 0));
cmdStart = CreateWindowEx (NULL, "Button", "Bat dau`", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_TEXT | WS_TABSTOP, 48, 40, 97, 25, hWnd, NULL, hInst, NULL);
if (!cmdStart) {return FALSE;};
SendMessage (cmdStart, WM_SETFONT, (WPARAM) hFont, MAKELPARAM (TRUE, 0));
Label1 = CreateWindowEx (WS_EX_TRANSPARENT, "Static", "La^n`/s", WS_VISIBLE | WS_CHILD | SS_SIMPLE, 88, 8, 57, 17, hWnd, NULL, hInst, NULL);
if (!Label1) {return FALSE;};
SendMessage (Label1, WM_SETFONT, (WPARAM) hFont, MAKELPARAM (TRUE, 0));
/**********************END CREATING CONTROLS*********************/
break;
case WM_COMMAND:
if ((HWND) lParam == cmdStart)
if (!start)
{
char ts[9];
gettext (txtTimes, 10, (LPARAM) &ts[0]);
n = atoi (ts);
SetTimer (hWnd, 0, 1000/n, NULL);
settext (cmdStart, (LPARAM) "Dung`");
start = true;
}
else
{
KillTimer (hWnd, 0);
settext (cmdStart, (LPARAM) "Bat' dau`");
start = false;
};
break;
case WM_TIMER:
POINT p;
GetCursorPos (&p);
mouse_event (MOUSEEVENTF_LEFTDOWN, p.x, p.y, 0, 0);
mouse_event (MOUSEEVENTF_LEFTUP, p.x, p.y, 0, 0);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}