mirror of
https://github.com/DosX-dev/obfus.h
synced 2026-06-06 15:34:32 +00:00
Update hello_win.c
- Improved comment clarity and formatting - Consistent indentation and spacing - Combined duplicate or similar cases in the message switch - Used modern variable initialization where possible - Clarified variable names and groupings
This commit is contained in:
+37
-68
@@ -5,30 +5,21 @@
|
||||
//+---------------------------------------------------------------------------
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include "../include/obfus.h"
|
||||
|
||||
#define APPNAME "Turn around"
|
||||
|
||||
char szAppName[] = APPNAME; // The name of this application
|
||||
char szTitle[] = APPNAME; // The title bar text
|
||||
const char *pWindowText;
|
||||
char szAppName[] = APPNAME; // Application name
|
||||
char szTitle[] = APPNAME; // Title bar text
|
||||
const char *pWindowText; // Text to display in window
|
||||
|
||||
void CenterWindow(HWND hWnd);
|
||||
|
||||
//+---------------------------------------------------------------------------
|
||||
//
|
||||
// Function: WndProc
|
||||
//
|
||||
// Synopsis: very unusual type of function - gets called by system to
|
||||
// process windows messages.
|
||||
//
|
||||
// Arguments: same as always.
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
// WndProc - Handles window messages
|
||||
//+---------------------------------------------------------------------------
|
||||
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
|
||||
switch (message) {
|
||||
// ----------------------- first and last
|
||||
case WM_CREATE:
|
||||
CenterWindow(hwnd);
|
||||
break;
|
||||
@@ -37,33 +28,25 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
|
||||
// ----------------------- get out of it...
|
||||
case WM_RBUTTONUP:
|
||||
case WM_RBUTTONUP: // Right mouse button releases
|
||||
case WM_KEYDOWN:
|
||||
if (message == WM_KEYDOWN && wParam != VK_ESCAPE)
|
||||
break;
|
||||
DestroyWindow(hwnd);
|
||||
break;
|
||||
|
||||
case WM_KEYDOWN:
|
||||
if (VK_ESCAPE == wParam)
|
||||
DestroyWindow(hwnd);
|
||||
break;
|
||||
|
||||
// ----------------------- display our minimal info
|
||||
case WM_PAINT: {
|
||||
PAINTSTRUCT ps;
|
||||
HDC hdc;
|
||||
HDC hdc = BeginPaint(hwnd, &ps);
|
||||
RECT rc;
|
||||
hdc = BeginPaint(hwnd, &ps);
|
||||
|
||||
GetClientRect(hwnd, &rc);
|
||||
SetTextColor(hdc, RGB(240, 240, 96));
|
||||
SetBkMode(hdc, TRANSPARENT);
|
||||
DrawText(hdc, pWindowText, -1, &rc, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
|
||||
|
||||
EndPaint(hwnd, &ps);
|
||||
break;
|
||||
}
|
||||
|
||||
// ----------------------- let windows do all other stuff
|
||||
default:
|
||||
return DefWindowProc(hwnd, message, wParam, lParam);
|
||||
}
|
||||
@@ -71,88 +54,74 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
}
|
||||
|
||||
//+---------------------------------------------------------------------------
|
||||
//
|
||||
// Function: WinMain
|
||||
//
|
||||
// Synopsis: standard entrypoint for GUI Win32 apps
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
// WinMain - Program Entry Point
|
||||
//+---------------------------------------------------------------------------
|
||||
int APIENTRY WinMain(
|
||||
HINSTANCE hInstance,
|
||||
HINSTANCE hPrevInstance,
|
||||
LPSTR lpCmdLine,
|
||||
int nCmdShow) {
|
||||
int nCmdShow
|
||||
) {
|
||||
MSG msg;
|
||||
WNDCLASS wc;
|
||||
WNDCLASS wc = { 0 };
|
||||
HWND hwnd;
|
||||
|
||||
// Use command line as window text, or default
|
||||
pWindowText = lpCmdLine[0] ? lpCmdLine : "DosX behind you!";
|
||||
|
||||
// Fill in window class structure with parameters that describe
|
||||
// the main window.
|
||||
|
||||
ZeroMemory(&wc, sizeof wc);
|
||||
// Set up window class
|
||||
wc.hInstance = hInstance;
|
||||
wc.lpszClassName = szAppName;
|
||||
wc.lpfnWndProc = (WNDPROC)WndProc;
|
||||
wc.lpfnWndProc = WndProc;
|
||||
wc.style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW;
|
||||
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
|
||||
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
|
||||
if (FALSE == RegisterClass(&wc))
|
||||
if (!RegisterClass(&wc))
|
||||
return 0;
|
||||
|
||||
// create the browser
|
||||
// Create main window
|
||||
hwnd = CreateWindow(
|
||||
szAppName,
|
||||
szTitle,
|
||||
szAppName, szTitle,
|
||||
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
360, // CW_USEDEFAULT,
|
||||
240, // CW_USEDEFAULT,
|
||||
0,
|
||||
0,
|
||||
hInstance,
|
||||
0);
|
||||
CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
360, 240, // Size: width, height
|
||||
NULL, NULL,
|
||||
hInstance, NULL
|
||||
);
|
||||
|
||||
if (NULL == hwnd)
|
||||
if (!hwnd)
|
||||
return 0;
|
||||
|
||||
// Main message loop:
|
||||
// Message loop
|
||||
while (GetMessage(&msg, NULL, 0, 0) > 0) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
|
||||
return msg.wParam;
|
||||
return (int)msg.wParam;
|
||||
}
|
||||
|
||||
//+---------------------------------------------------------------------------
|
||||
|
||||
// CenterWindow - Centers window on its parent or desktop
|
||||
//+---------------------------------------------------------------------------
|
||||
|
||||
void CenterWindow(HWND hwnd_self) {
|
||||
HWND hwnd_parent;
|
||||
RECT rw_self, rc_parent, rw_parent;
|
||||
int xpos, ypos;
|
||||
|
||||
hwnd_parent = GetParent(hwnd_self);
|
||||
if (NULL == hwnd_parent)
|
||||
HWND hwnd_parent = GetParent(hwnd_self);
|
||||
if (!hwnd_parent)
|
||||
hwnd_parent = GetDesktopWindow();
|
||||
|
||||
RECT rw_self, rc_parent, rw_parent;
|
||||
GetWindowRect(hwnd_parent, &rw_parent);
|
||||
GetClientRect(hwnd_parent, &rc_parent);
|
||||
GetWindowRect(hwnd_self, &rw_self);
|
||||
|
||||
xpos = rw_parent.left + (rc_parent.right + rw_self.left - rw_self.right) / 2;
|
||||
ypos = rw_parent.top + (rc_parent.bottom + rw_self.top - rw_self.bottom) / 2;
|
||||
int xpos = rw_parent.left + (rc_parent.right + rw_self.left - rw_self.right) / 2;
|
||||
int ypos = rw_parent.top + (rc_parent.bottom + rw_self.top - rw_self.bottom) / 2;
|
||||
|
||||
SetWindowPos(
|
||||
hwnd_self, NULL,
|
||||
xpos, ypos, 0, 0,
|
||||
SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
|
||||
SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE
|
||||
);
|
||||
}
|
||||
|
||||
//+---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user