Skip to content

Commit

Permalink
Code Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ryandw11 committed Dec 14, 2021
1 parent f1c731c commit 16fad5c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 20 deletions.
47 changes: 28 additions & 19 deletions AutoClickerDL/AutoClickerDL.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,25 @@ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#define WIDTH 400
#define HEIGHT 500

// The handle to the main window.
HWND mainWindowHandle;

// The different tabs.
HWND tabControl, generalDisplayArea, settingsDisplayArea, rememberClickDisplayArea;

// The hotkey control for the start/stop of the Auto Clicker.
HWND startStopHotKey;
// The spinner for clicks per second.
HWND spinnerHWD;

// The timer used by the clicker. Not null when enabled, NULL when not enabled.
UINT_PTR autoClickerTimer = NULL;

// Process callbacks.
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK SettingsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

// Main method.
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) {
// Class name of the window.
const wchar_t CLASS_NAME[] = L"AutoClickerDL Window Class";
Expand Down Expand Up @@ -105,14 +113,19 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
*/
HWND hotKeyLabel = CreateWindow(WC_STATIC, L"Start/Stop Auto Clicker:", WS_VISIBLE | WS_CHILD,
10, 23, 150, 20, settingsDisplayArea, NULL, hInstance, NULL);
startStopHotKey = CreateWindow(HOTKEY_CLASS, L"Start/Stop Auto Clicker", WS_VISIBLE | WS_CHILD,
startStopHotKey = CreateWindow(HOTKEY_CLASS, L"Start/StopHotKey", WS_VISIBLE | WS_CHILD,
10, 43, 150, 20, settingsDisplayArea, NULL, hInstance, NULL);
SendMessage(startStopHotKey, HKM_SETHOTKEY, MAKEWORD(VK_F1, 0), 0);
RegisterHotKey(windowHandle, 0, MOD_NOREPEAT, VK_F1);


/*
===============
Window Messages
===============
*/
ShowWindow(windowHandle, nCmdShow);

// Message Loop
MSG msg = { 0 };
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
Expand All @@ -122,14 +135,20 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
return 0;
}

/*
This is the callback for the messages of the settings display background.
*/
LRESULT CALLBACK SettingsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
case WM_COMMAND:
{
int cmd = HIWORD(wParam);
// Triggered by the hotkey change.
if (cmd == EN_CHANGE) {
// Identification of the hotkey control.
int loword = LOWORD(wParam);
if (loword == 0) {
// Unregister and re-register global hot key with the change.
UnregisterHotKey(mainWindowHandle, 0);
int result = SendMessage(startStopHotKey, HKM_GETHOTKEY, NULL, NULL);
RegisterHotKey(mainWindowHandle, 0, HIBYTE(result), LOBYTE(result));
Expand All @@ -143,6 +162,9 @@ LRESULT CALLBACK SettingsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

/*
Callback for the main window message process.
*/
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
case WM_DESTROY:
Expand Down Expand Up @@ -183,39 +205,26 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
}
}
break;
case WM_COMMAND:
{
int cmd = HIWORD(wParam);
if (cmd == EN_CHANGE) {
int loword = LOWORD(wParam);
if (loword == 0) {
UnregisterHotKey(hwnd, 0);
int result = SendMessage(startStopHotKey, HKM_GETHOTKEY, NULL, NULL);
RegisterHotKey(hwnd, 0, HIBYTE(result), LOBYTE(result));
}
}
}
break;
// When a global hotkey for the program is triggered.
case WM_HOTKEY:
{
// If the timmer is not running, trigger it.
if (autoClickerTimer == NULL) {
int pos = SendMessage(spinnerHWD, UDM_GETPOS32, NULL, NULL);
autoClickerTimer = SetTimer(hwnd, 1001, (1000 / pos), (TIMERPROC)NULL);
}
// Else, kill it.
else {
KillTimer(hwnd, autoClickerTimer);
autoClickerTimer = NULL;
}


}
break;
case WM_KEYDOWN:
{
}
break;
case WM_TIMER:
{
// When the timmer is triggered, send a click event.
INPUT inputs[2] = { 0 };

inputs[0].type = INPUT_MOUSE;
Expand Down
26 changes: 25 additions & 1 deletion AutoClickerDL/General.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,43 @@

#include "General.h"

/*
Create a display area for the tab. (This create a seperate window class for each tab display area.)
@param parent The parent window for the display area.
@param hInstance The hInstance for the program.
@param className The class name to use for the created Window Class.
@param x The x coordinate of the display area.
@param y The y coordinate of the display area.
@param width The width of the dispaly area.
@param height The height of the display area.
@param procCallback The callback function to use for the process callback.
@returns The handle for the created display area.
*/
HWND CreateTabDisplayArea(HWND parent, HINSTANCE hInstance, LPCWSTR className, int x, int y, int width, int height, WNDPROC procCallback) {
WNDCLASS wc = { 0 };
wc.lpfnWndProc = procCallback;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.lpszClassName = className;
wc.hbrBackground = CreateSolidBrush(RGB(240, 240, 240));

RegisterClass(&wc);

HWND displayArea = CreateWindowEx(NULL, className, className, WS_CHILD, x, y, width, height, parent, NULL, hInstance, NULL);
HWND displayArea = CreateWindowEx(NULL, className, className, WS_CHILD | WS_BORDER, x, y, width, height, parent, NULL, hInstance, NULL);
return displayArea;
}

/*
Create a spinner control.
@param parent The parent window of the spinner.
@param hInstance The hInstance of the program.
@param spinner The struct that details the creation of the spinner.
@returns The handle to the UPDOWN control.
*/
HWND CreateSpinner(HWND parent, HINSTANCE hInstance, Spinner spinner) {
HWND cpsLabel = CreateWindow(WC_STATIC, spinner.labelPtr, WS_VISIBLE | WS_CHILD | SS_LEFT, spinner.x + 64, spinner.y, 40, 20, parent, NULL, hInstance, NULL);
HWND spinnerUpDown = CreateWindow(UPDOWN_CLASS, L"F", WS_VISIBLE | WS_CHILD | UDS_ARROWKEYS | UDS_SETBUDDYINT | UDS_ALIGNRIGHT,
Expand Down

0 comments on commit 16fad5c

Please sign in to comment.