π Virtual ATM Machine using C++ | Secure Login, Deposit & Withdraw Demo | FuzzuTech
Demo :
Click Video πππ
➤ Features :
-
Secure PIN-based login
-
Deposit & Withdraw Buttons
-
Balance Display
-
Logout and session reset
-
Built in pure C++ with Windows API
Code :
#define _WIN32_WINNT 0x0601
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <string>
#include <sstream>
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "gdi32.lib")
// Global variables
HWND hBalanceStatic;
HWND hDepositBtn, hWithdrawBtn, hCheckBtn, hLogoutBtn;
HWND hPinStatic, hPinEdit, hLoginBtn;
int balance = 1000; // initial balance
const std::string correctPIN = "1234";
bool loggedIn = false;
// Forward declarations
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void UpdateBalanceText(HWND hwnd);
void ShowMessage(LPCSTR msg, LPCSTR title);
std::string GetTextFromEdit(HWND hwnd);
void ClearPinInput();
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow) {
// Register Window Class
WNDCLASSEX wc{ sizeof(WNDCLASSEX) };
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.lpszClassName = "VirtualATMClass";
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
RegisterClassEx(&wc);
// Create Window
HWND hWnd = CreateWindowEx(
0, "VirtualATMClass", "Virtual ATM Machine - Fuzzu Developer",
WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX,
CW_USEDEFAULT, CW_USEDEFAULT, 400, 320,
NULL, NULL, hInstance, NULL);
if (!hWnd) return 0;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
// Message Loop
MSG msg{};
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
// Helper: Show MessageBox
void ShowMessage(LPCSTR msg, LPCSTR title) {
MessageBoxA(NULL, msg, title, MB_OK | MB_ICONINFORMATION);
}
// Helper: Update balance label text
void UpdateBalanceText(HWND hwnd) {
std::stringstream ss;
ss << "Balance: $" << balance;
SetWindowTextA(hwnd, ss.str().c_str());
}
// Helper: Get text from an edit control as std::string
std::string GetTextFromEdit(HWND hwnd) {
int length = GetWindowTextLengthA(hwnd);
if (length == 0) return "";
char* buffer = new char[length + 1];
GetWindowTextA(hwnd, buffer, length + 1);
std::string text(buffer);
delete[] buffer;
return text;
}
// Helper: Clear PIN input
void ClearPinInput() {
SetWindowTextA(hPinEdit, "");
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_CREATE:
{
// Create PIN input controls
hPinStatic = CreateWindowA("STATIC", "Enter PIN:", WS_VISIBLE | WS_CHILD, 30, 30, 80, 20, hwnd, NULL, NULL, NULL);
hPinEdit = CreateWindowA("EDIT", "", WS_VISIBLE | WS_CHILD | WS_BORDER | ES_PASSWORD, 120, 25, 150, 25, hwnd, NULL, NULL, NULL);
hLoginBtn = CreateWindowA("BUTTON", "Login", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 280, 25, 80, 25, hwnd, (HMENU)100, NULL, NULL);
// Balance display (hidden initially)
hBalanceStatic = CreateWindowA("STATIC", "Balance: $0", WS_CHILD | WS_VISIBLE, 30, 70, 300, 30, hwnd, NULL, NULL, NULL);
// Buttons (hidden initially)
hDepositBtn = CreateWindowA("BUTTON", "Deposit $100", WS_CHILD | WS_VISIBLE, 30, 120, 150, 40, hwnd, (HMENU)101, NULL, NULL);
hWithdrawBtn = CreateWindowA("BUTTON", "Withdraw $100", WS_CHILD | WS_VISIBLE, 200, 120, 150, 40, hwnd, (HMENU)102, NULL, NULL);
hCheckBtn = CreateWindowA("BUTTON", "Check Balance", WS_CHILD | WS_VISIBLE, 30, 180, 150, 40, hwnd, (HMENU)103, NULL, NULL);
hLogoutBtn = CreateWindowA("BUTTON", "Logout", WS_CHILD | WS_VISIBLE, 200, 180, 150, 40, hwnd, (HMENU)104, NULL, NULL);
// Initially disable buttons except login-related controls
ShowWindow(hBalanceStatic, SW_HIDE);
ShowWindow(hDepositBtn, SW_HIDE);
ShowWindow(hWithdrawBtn, SW_HIDE);
ShowWindow(hCheckBtn, SW_HIDE);
ShowWindow(hLogoutBtn, SW_HIDE);
break;
}
case WM_COMMAND:
switch (LOWORD(wParam)) {
case 100: // Login button
{
std::string pin = GetTextFromEdit(hPinEdit);
if (pin == correctPIN) {
loggedIn = true;
ShowMessage("Login Successful!", "Welcome");
// Hide login controls
ShowWindow(hPinStatic, SW_HIDE);
ShowWindow(hPinEdit, SW_HIDE);
ShowWindow(hLoginBtn, SW_HIDE);
// Show ATM controls
UpdateBalanceText(hBalanceStatic);
ShowWindow(hBalanceStatic, SW_SHOW);
ShowWindow(hDepositBtn, SW_SHOW);
ShowWindow(hWithdrawBtn, SW_SHOW);
ShowWindow(hCheckBtn, SW_SHOW);
ShowWindow(hLogoutBtn, SW_SHOW);
}
else {
ShowMessage("Incorrect PIN. Try again.", "Error");
ClearPinInput();
}
break;
}
case 101: // Deposit $100
{
if (loggedIn) {
balance += 100;
UpdateBalanceText(hBalanceStatic);
ShowMessage("Deposited $100 successfully.", "Deposit");
}
break;
}
case 102: // Withdraw $100
{
if (loggedIn) {
if (balance >= 100) {
balance -= 100;
UpdateBalanceText(hBalanceStatic);
ShowMessage("Withdrawn $100 successfully.", "Withdraw");
}
else {
ShowMessage("Insufficient balance!", "Withdraw Error");
}
}
break;
}
case 103: // Check Balance
{
if (loggedIn) {
std::stringstream ss;
ss << "Your current balance is $" << balance;
ShowMessage(ss.str().c_str(), "Balance");
}
break;
}
case 104: // Logout
{
loggedIn = false;
// Hide ATM controls
ShowWindow(hBalanceStatic, SW_HIDE);
ShowWindow(hDepositBtn, SW_HIDE);
ShowWindow(hWithdrawBtn, SW_HIDE);
ShowWindow(hCheckBtn, SW_HIDE);
ShowWindow(hLogoutBtn, SW_HIDE);
// Show login controls
ShowWindow(hPinStatic, SW_SHOW);
ShowWindow(hPinEdit, SW_SHOW);
ShowWindow(hLoginBtn, SW_SHOW);
ClearPinInput();
ShowMessage("Logged out successfully.", "Logout");
break;
}
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
Comments
Post a Comment