1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
#include <windows.h>
#include <tchar.h>
// Global variables
/*int keyone = 1;*/
/*int keytwo = 2;*/
// The main window class name.
static TCHAR g_szWindowClass[] = _T("win32Spinapp");
// Foward declaration of the 'Spin' function
void Spin (int x, int y );
// Foward declaration of the Windows Procedure
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
/*double sWidth = ::GetSystemMetrics( SM_CXSCREEN )-1;*/
//Gets the screen width
/*double sHeight = ::GetSystemMetrics( SM_CYSCREEN )-1;*/
//Gets the screen height
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
//Optional Pre-Step: Hotkeys To Call Your App Functions
RegisterHotKey(
NULL,
1,
NULL,
0x53); //0x53 is 's'
//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szWindowClass;
wc.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Failed To Register Window!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
// Step 2: Creating the Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szWindowClass,
"Serpentine's Spin Bot V 1.1",
WS_POPUPWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 300, 120,
NULL, NULL, hInstance, NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "Failed To Create Window!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
/*::MoveWindow(hwnd, sWidth/2, sHeight/2, 300, 120, TRUE);*/
//Moves window
/*ShowWindow(hwnd, nCmdShow);*/
//Shows window, in this case
//it's hidden since commented
/*UpdateWindow(hwnd);*/
//Updates the window for the
//above to take affect
//==============================================================//
// Step 3: The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
// Optional Step: Your Functions Four Your App, Have Fun!
void Spin (int x, int y )
{
double fScreenWidth = ::GetSystemMetrics( SM_CXSCREEN )-1;
double fScreenHeight = ::GetSystemMetrics( SM_CYSCREEN )-1;
double fx = x*(65535.0f/fScreenWidth);
double fy = y*(65535.0f/fScreenHeight);
INPUT Input={0};
Input.type = INPUT_MOUSE;
Input.mi.dwFlags = MOUSEEVENTF_MOVE|MOUSEEVENTF_ABSOLUTE;
Input.mi.dx = fx;
Input.mi.dy = fy;
::SendInput(1,&Input,sizeof(INPUT));
}
// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_HOTKEY:
Spin(1820, 800);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
break;
}
return 0;
}
|