11 hours ago
(This post was last modified: 8 hours ago by Stanley Durham.)
Cold blooded!
I had to give it a shot. x86_6 GCC version
Command line:
gcc EnableVisualStyles.c -o EnableVisualStyles.exe -mwindows -lcomctl32 -lgdi32 -luser32
DeepSeek conversion of code; I wouldn’t have a clue how to do it.
---
Added Note: Maybe I shouldn’t have put this here. Fill free to delete.
I had to give it a shot. x86_6 GCC version
Command line:
gcc EnableVisualStyles.c -o EnableVisualStyles.exe -mwindows -lcomctl32 -lgdi32 -luser32
DeepSeek conversion of code; I wouldn’t have a clue how to do it.
---
Added Note: Maybe I shouldn’t have put this here. Fill free to delete.
Code:
// gcc EnableVisualStyles.c -o EnableVisualStyles.exe -mwindows -lcomctl32 -lgdi32 -luser32
// targets x86_6
#ifndef UNICODE
#define UNICODE
#endif
#ifndef _UNICODE
#define _UNICODE
#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <commctrl.h>
#define IDC_TEXTBOX1 531
static HFONT g_hFont;
typedef struct
{
HANDLE hActCtx;
ULONG_PTR cookie;
HMODULE hShell32;
} VISUAL_STYLES;
static VISUAL_STYLES EnableVisualStyles(void)
{
WCHAR szSys[MAX_PATH];
ACTCTXW aCtx;
VISUAL_STYLES vs;
vs.hActCtx = INVALID_HANDLE_VALUE;
vs.cookie = 0;
vs.hShell32 = NULL;
if (!GetSystemDirectoryW(szSys, MAX_PATH))
return vs;
ZeroMemory(&aCtx, sizeof(aCtx));
aCtx.cbSize = sizeof(aCtx);
aCtx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID
| ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID
| ACTCTX_FLAG_HMODULE_VALID;
aCtx.hModule = LoadLibraryW(L"shell32.dll");
aCtx.lpResourceName = MAKEINTRESOURCEW(124);
aCtx.lpAssemblyDirectory = szSys;
if (!aCtx.hModule)
return vs;
vs.hShell32 = aCtx.hModule;
vs.hActCtx = CreateActCtxW(&aCtx);
if (vs.hActCtx != INVALID_HANDLE_VALUE)
ActivateActCtx(vs.hActCtx, &vs.cookie);
return vs;
}
static void DisableVisualStyles(VISUAL_STYLES *vs)
{
if (vs->cookie)
DeactivateActCtx(0, vs->cookie);
if (vs->hActCtx != INVALID_HANDLE_VALUE)
ReleaseActCtx(vs->hActCtx);
if (vs->hShell32)
FreeLibrary(vs->hShell32);
vs->cookie = 0;
vs->hActCtx = INVALID_HANDLE_VALUE;
vs->hShell32 = NULL;
}
static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CREATE:
{
HINSTANCE hInst = (HINSTANCE)GetWindowLongPtrW(hwnd, GWLP_HINSTANCE);
HWND hEdit, hOk;
hEdit = CreateWindowExW(WS_EX_CLIENTEDGE, L"EDIT", L"TextBox1",
WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL |
ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL,
10, 10, 150, 55, hwnd, (HMENU)(INT_PTR)IDC_TEXTBOX1, hInst, NULL);
hOk = CreateWindowExW(0, L"BUTTON", L"&Ok",
WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_DEFPUSHBUTTON,
172, 54, 88, 26, hwnd, (HMENU)IDCANCEL, hInst, NULL);
SendMessageW(hEdit, WM_SETFONT, (WPARAM)g_hFont, TRUE);
SendMessageW(hOk, WM_SETFONT, (WPARAM)g_hFont, TRUE);
SetFocus(hEdit);
}
return 0;
case WM_COMMAND:
if (LOWORD(wParam) == IDCANCEL)
SendMessageW(hwnd, WM_CLOSE, 0, 0);
return 0;
case WM_CLOSE:
DestroyWindow(hwnd);
return 0;
case WM_DESTROY:
if (g_hFont)
{
DeleteObject(g_hFont);
g_hFont = NULL;
}
PostQuitMessage(0);
return 0;
}
return DefWindowProcW(hwnd, msg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR pCmdLine, int nCmdShow)
{
VISUAL_STYLES vs;
WNDCLASSEXW wc;
INITCOMMONCONTROLSEX icc;
NONCLIENTMETRICSW ncm;
HWND hwnd;
MSG msg;
RECT rc;
DWORD style = WS_OVERLAPPEDWINDOW & ~(WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX);
(void)hPrevInstance;
(void)pCmdLine;
vs = EnableVisualStyles();
if (vs.cookie)
{
icc.dwSize = sizeof(icc);
icc.dwICC = ICC_STANDARD_CLASSES;
InitCommonControlsEx(&icc);
}
ncm.cbSize = sizeof(ncm);
if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0))
g_hFont = CreateFontIndirectW(&ncm.lfMessageFont);
if (!g_hFont)
g_hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
ZeroMemory(&wc, sizeof(wc));
wc.cbSize = sizeof(wc);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hIcon = LoadIconW(NULL, IDI_APPLICATION);
wc.hIconSm = wc.hIcon;
wc.hCursor = LoadCursorW(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
wc.lpszClassName = L"EnableVisualStylesDemo";
if (!RegisterClassExW(&wc))
{
DisableVisualStyles(&vs);
return 1;
}
rc.left = 0; rc.top = 0; rc.right = 270; rc.bottom = 90;
AdjustWindowRectEx(&rc, style, FALSE, WS_EX_CONTROLPARENT);
hwnd = CreateWindowExW(WS_EX_CONTROLPARENT, wc.lpszClassName,
L"EnableVisualStyles", style, CW_USEDEFAULT, CW_USEDEFAULT,
rc.right - rc.left, rc.bottom - rc.top,
NULL, NULL, hInstance, NULL);
if (!hwnd)
{
DisableVisualStyles(&vs);
return 1;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while (GetMessageW(&msg, NULL, 0, 0) > 0)
{
if (!IsDialogMessageW(hwnd, &msg))
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
}
DisableVisualStyles(&vs);
return (int)msg.wParam;
}