Skip to content

Instantly share code, notes, and snippets.

@PBfordev
Last active December 11, 2020 09:48
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 PBfordev/e3fb68ec7576cb2a6534ea230b300508 to your computer and use it in GitHub Desktop.
Save PBfordev/e3fb68ec7576cb2a6534ea230b300508 to your computer and use it in GitHub Desktop.
Shows enabled and disabled Win32 push buttons
#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#include <windows.h>
#include <windowsx.h>
#include <tchar.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if ( message == WM_DESTROY )
{
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
const int ID_TOGGLEBTN_1 = 1001;
const int ID_TOGGLEBTN_2 = 1002;
const int ID_TOGGLEBTN_3 = 1003;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow)
{
// Create frame
WNDCLASS wc = { };
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.lpszClassName = _T("SampleFrame");
RegisterClass(&wc);
HWND hFrame = CreateWindow(wc.lpszClassName, _T("Toggle Button Test"),
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 400, 400,
nullptr, nullptr, hInstance, nullptr);
// Create buttons
HWND hButton = nullptr;
// Enabled push button
hButton = CreateWindowEx(0, _T("BUTTON"), _T("Enabled"), WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX | BS_PUSHLIKE,
20, 20, 150, 60, hFrame, (HMENU)(ID_TOGGLEBTN_1), hInstance, nullptr);
// Disabled push button, pushed
hButton = CreateWindowEx(0, _T("BUTTON"), _T("Disabled ON"), WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX | BS_PUSHLIKE,
20, 150, 150, 60, hFrame, (HMENU)(ID_TOGGLEBTN_2), hInstance, nullptr);
Button_SetCheck(hButton, BST_CHECKED);
EnableWindow(hButton, FALSE);
// Disabled push button, unpushed
hButton = CreateWindowEx(0, _T("BUTTON"), _T("Disabled OFF"), WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX | BS_PUSHLIKE,
20, 270, 150, 60, hFrame, (HMENU)(ID_TOGGLEBTN_3), hInstance, nullptr);
Button_SetCheck(hButton, BST_UNCHECKED);
EnableWindow(hButton, FALSE);
ShowWindow(hFrame, nCmdShow);
//UpdateWindow(hFrame);
// Handle messages
MSG msg;
while ( GetMessage(&msg, NULL, 0, 0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment