- 1 year ago
Button without style windows
If you want to create a button without any visual style (no borders, background, etc.) on Windows, you can create a standard Windows button and set its style to remove all visual elements. Here's an example in C++ using the Windows API:
cpp#include <windows.h>
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CREATE:
{
// Create the button
HWND hButton = CreateWindow(L"BUTTON", L"", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
50, 50, 100, 30, hwnd, NULL, NULL, NULL);
// Remove all visual styles from the button
SetWindowLongPtr(hButton, GWL_STYLE, 0);
break;
}
case WM_COMMAND:
{
// Handle button click event
if (LOWORD(wParam) == BN_CLICKED)
{
MessageBox(hwnd, L"Button clicked!", L"Message", MB_OK);
}
break;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// Register the window class
WNDCLASS wc = {0};
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);
wc.lpszClassName = L"ButtonApp";
if (!RegisterClass(&wc))
return -1;
// Create the main window
HWND hwnd = CreateWindowEx(0, L"ButtonApp", L"No Style Button Example",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
400, 200, NULL, NULL, hInstance, NULL);
if (!hwnd)
return -1;
// Show the window
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
// Enter the message loop
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
In this example, we create a standard Windows button using the BUTTON
window class. We then remove all the button's visual styles by setting its style to 0 using SetWindowLongPtr
. This results in a button with no visible appearance.
The button will still be functional and can receive click events. When clicked, a message box will pop up showing a message indicating that the button was clicked.
Keep in mind that removing all visual styles from a button might make it hard for users to recognize it as a button. So, use this approach sparingly and make sure it fits your application's design and user experience.