# SftButton/DLL 3.0 — Sample Source Code > Full source code for the SftButton/DLL 3.0 samples, referenced from https://softelvdm.com/Vault/Softelvdm.com/llms/SftButton-DLL-3.0.txt ## Simple Sample (C) *Source: https://softelvdm.com/Documentation/SftButton%20DLL%203%200/Topic/sample_c_simple* ```c /****************************************************************************/ /* SftButton/DLL 3.0 - Button Control for C/C++ */ /* Copyright (C) 2026 Softel vdm, Inc. All Rights Reserved. */ /****************************************************************************/ /* SftButton/DLL 3.0 sample. Guide: https://softelvdm.com/Vault/Softelvdm.com/llms/SftButton-DLL-3.0.txt, API reference: https://softelvdm.com/Vault/Softelvdm.com/llms/SftButton-DLL-3.0-reference.txt - see AGENTS.md. */ #include #include #include "SftButton.h" // SftButton/DLL Header File #define SFTDARKMODE_IMPLEMENTATION #include "SftDarkMode.h" // Dark mode support #include "resource.h" // application resources /**********************************************************************/ /* Globals */ /**********************************************************************/ HINSTANCE g_hInst; // App Instance Handle static LPVOID g_pImg1 = NULL; // GDI+ image for Button2 Picture1 static LPVOID g_pImg2 = NULL; // GDI+ image for Button2 Picture2 /**********************************************************************/ /* Main Dialog Proc */ /**********************************************************************/ INT_PTR CALLBACK Main_DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { INT_PTR dmResult; switch (msg) { case WM_INITDIALOG: { HWND hwndButton1 = GetDlgItem(hwndDlg, IDC_SFTBUTTON1); HWND hwndButton2 = GetDlgItem(hwndDlg, IDC_SFTBUTTON2); HWND hwndButton3 = GetDlgItem(hwndDlg, IDC_SFTBUTTON3); // Set dialog icon SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ICON1))); SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ICON1))); // Apply dark mode to dialog SftDarkMode_ApplyToDialog(hwndDlg); // Configure SftButton control 1 { SFTBUTTON_CONTROL Ctl; Ctl.cbSize = sizeof(SFTBUTTON_CONTROL); SftButton_GetControlInfo(hwndButton1, &Ctl); Ctl.nDarkMode = SFTBUTTON_DARKMODE_AUTO;/* automatic dark mode support */ SftButton_SetControlInfo(hwndButton1, &Ctl); } // Configure SftButton control 2 { SFTBUTTON_CONTROL Ctl; Ctl.cbSize = sizeof(SFTBUTTON_CONTROL); SftButton_GetControlInfo(hwndButton2, &Ctl); Ctl.nDarkMode = SFTBUTTON_DARKMODE_AUTO;/* automatic dark mode support */ Ctl.Text.align = SFT_PICALIGN_LEFT;/* text horizontal alignment */ g_pImg1 = SftButton_LoadGDIPlusImageFromFile(TEXT("Res\\pic_world_48.png")); if (g_pImg1) Sft_SetPictureGDIPlusImage(&Ctl.Picture1, g_pImg1); Ctl.Picture1.align = SFT_PICALIGN_CENTER; Ctl.Picture1.valign = SFT_PICALIGN_VCENTER; g_pImg2 = SftButton_LoadGDIPlusImageFromFile(TEXT("Res\\pic_go_32.png")); if (g_pImg2) Sft_SetPictureGDIPlusImage(&Ctl.Picture2, g_pImg2); Ctl.Picture2.align = SFT_PICALIGN_LEFT; Ctl.Picture2.valign = SFT_PICALIGN_VCENTER; SftButton_SetControlInfo(hwndButton2, &Ctl); } // Configure SftButton control 3 { SFTBUTTON_CONTROL Ctl; Ctl.cbSize = sizeof(SFTBUTTON_CONTROL); SftButton_GetControlInfo(hwndButton3, &Ctl); Ctl.fShowDropDown = TRUE;/* show drop-down arrow */ Ctl.nDarkMode = SFTBUTTON_DARKMODE_AUTO;/* automatic dark mode support */ SftButton_SetControlInfo(hwndButton3, &Ctl); } CheckDlgButton(hwndDlg, IDC_USE_THEMES, BST_CHECKED); CheckDlgButton(hwndDlg, IDC_DARK_MODE, SftDarkMode_IsActive() ? BST_CHECKED : BST_UNCHECKED); return TRUE; } case WM_COMMAND: switch (LOWORD(wParam)) { case IDCANCEL: EndDialog(hwndDlg, 0); return TRUE; case IDC_SFTBUTTON1: if (HIWORD(wParam) == BN_CLICKED) MessageBox(hwndDlg, TEXT("Button 1 clicked!"), TEXT("SftButton/DLL"), MB_OK); return TRUE; case IDC_SFTBUTTON2: if (HIWORD(wParam) == BN_CLICKED) MessageBox(hwndDlg, TEXT("Button 2 clicked!"), TEXT("SftButton/DLL"), MB_OK); return TRUE; case IDC_SFTBUTTON3: if (HIWORD(wParam) == BN_CLICKED) MessageBox(hwndDlg, TEXT("Button 3 clicked!"), TEXT("SftButton/DLL"), MB_OK); else if (HIWORD(wParam) == SFTBUTTONN_DROPDOWNCLICK) MessageBox(hwndDlg, TEXT("Button 3 drop-down clicked!"), TEXT("SftButton/DLL"), MB_OK); return TRUE; case IDC_USE_THEMES: if (HIWORD(wParam) == BN_CLICKED) { int useThemes = IsDlgButtonChecked(hwndDlg, IDC_USE_THEMES) == BST_CHECKED ? SFTBUTTON_THEME_YES : SFTBUTTON_THEME_NO; int ids[] = { IDC_SFTBUTTON1, IDC_SFTBUTTON2, IDC_SFTBUTTON3 }; for (int i = 0; i < (int)(sizeof(ids) / sizeof(ids[0])); ++i) { HWND hwndBtn = GetDlgItem(hwndDlg, ids[i]); SFTBUTTON_CONTROL Ctl; Ctl.cbSize = sizeof(SFTBUTTON_CONTROL); SftButton_GetControlInfo(hwndBtn, &Ctl); Ctl.nUseThemes = useThemes; SftButton_SetControlInfo(hwndBtn, &Ctl); } } return TRUE; case IDC_DARK_MODE: if (HIWORD(wParam) == BN_CLICKED) { BOOL fDark = IsDlgButtonChecked(hwndDlg, IDC_DARK_MODE) == BST_CHECKED; int btnMode = fDark ? SFTBUTTON_DARKMODE_ON : SFTBUTTON_DARKMODE_OFF; int ids[] = { IDC_SFTBUTTON1, IDC_SFTBUTTON2, IDC_SFTBUTTON3 }; for (int i = 0; i < (int)(sizeof(ids) / sizeof(ids[0])); ++i) SftButton_SetDarkMode(GetDlgItem(hwndDlg, ids[i]), btnMode); SftDarkMode_SetActive(fDark); SftDarkMode_ApplyToDialog(hwndDlg); InvalidateRect(hwndDlg, NULL, TRUE); } return TRUE; } break; case WM_DESTROY: // Free GDI+ images now that the control no longer references them. if (g_pImg1) { SftButton_FreeGDIPlusImageLoadedFromFile(g_pImg1); g_pImg1 = NULL; } if (g_pImg2) { SftButton_FreeGDIPlusImageLoadedFromFile(g_pImg2); g_pImg2 = NULL; } break; case WM_SETTINGCHANGE: // dark mode handling if (lParam && (lstrcmpW((LPCWSTR)lParam, L"ImmersiveColorSet") == 0 || lstrcmpA((LPCSTR)lParam, "ImmersiveColorSet") == 0)) { SftDarkMode_Init(); SftDarkMode_ApplyToDialog(hwndDlg); // Forward to the SftButton controls so they can update (AUTO mode) SendMessage(GetDlgItem(hwndDlg, IDC_SFTBUTTON1), WM_SETTINGCHANGE, wParam, lParam); SendMessage(GetDlgItem(hwndDlg, IDC_SFTBUTTON2), WM_SETTINGCHANGE, wParam, lParam); SendMessage(GetDlgItem(hwndDlg, IDC_SFTBUTTON3), WM_SETTINGCHANGE, wParam, lParam); InvalidateRect(hwndDlg, NULL, TRUE); } return TRUE; } if (SftDarkMode_HandleDialogMessage(hwndDlg, msg, wParam, lParam, &dmResult)) return dmResult; return FALSE; } /**********************************************************************/ /* WinMain */ /**********************************************************************/ int PASCAL WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR lpszCmdLine, int cmdShow) { INITCOMMONCONTROLSEX icc; g_hInst = hinst; icc.dwSize = sizeof(icc); icc.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&icc); // Register with SftButton/DLL SftButton_RegisterApp(hinst); // Initialize dark mode support SftDarkMode_Init(); DialogBox(hinst, MAKEINTRESOURCE(IDD_MAIN), NULL, Main_DialogProc); // Unregister from SftButton/DLL SftButton_UnregisterApp(hinst); return 0; } ``` ## Simple Sample (C++/MFC) — Simple.cpp - CWinApp initialization *Source: https://softelvdm.com/Documentation/SftButton%20DLL%203%200/Topic/sample_mfc_simple* ```cpp /****************************************************************************/ /* SftButton/DLL 3.0 - Button Control for C/C++ */ /* Copyright (C) 2026 Softel vdm, Inc. All Rights Reserved. */ /****************************************************************************/ /* SftButton/DLL 3.0 sample. Guide: https://softelvdm.com/Vault/Softelvdm.com/llms/SftButton-DLL-3.0.txt, API reference: https://softelvdm.com/Vault/Softelvdm.com/llms/SftButton-DLL-3.0-reference.txt - see AGENTS.md. */ #include "stdafx.h" #include "Simple.h" #include "Maindlg.h" #ifdef _DEBUG #undef THIS_FILE static char BASED_CODE THIS_FILE[] = __FILE__; #endif BEGIN_MESSAGE_MAP(CSimpleApp, CWinApp) END_MESSAGE_MAP() CSimpleApp::CSimpleApp() { } CSimpleApp NEAR theApp; BOOL CSimpleApp::InitInstance() { SftDarkMode_Init(); // Dark mode support CSftButton::RegisterApp(); // Register with SftButton/DLL CMainDlg dlg; m_pMainWnd = &dlg; dlg.DoModal(); return FALSE; } int CSimpleApp::ExitInstance() { CSftButton::UnregisterApp(); // Unregister from SftButton/DLL return CWinApp::ExitInstance(); } ``` ## Simple Sample (C++/MFC) — Maindlg.h - dialog class *Source: https://softelvdm.com/Documentation/SftButton%20DLL%203%200/Topic/sample_mfc_simple* ```cpp /****************************************************************************/ /* SftButton/DLL 3.0 - Button Control for C/C++ */ /* Copyright (C) 2026 Softel vdm, Inc. All Rights Reserved. */ /****************************************************************************/ class CMainDlg : public CDialog { public: CMainDlg(CWnd* pParent = NULL); enum { IDD = IDD_MAIN }; CSftButton m_Button1; CSftButton m_Button2; CSftButton m_Button3; LPVOID m_pImg1; // GDI+ image for Button2 Picture1 LPVOID m_pImg2; // GDI+ image for Button2 Picture2 protected: virtual void DoDataExchange(CDataExchange* pDX); virtual BOOL OnInitDialog(); virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); afx_msg void OnButton1(); afx_msg void OnButton2(); afx_msg void OnButton3(); afx_msg void OnButton3DropDown(); afx_msg void OnUseThemes(); afx_msg void OnDarkMode(); afx_msg void OnDestroy(); afx_msg void OnSettingChange(UINT uFlags, LPCTSTR lpszSection); DECLARE_MESSAGE_MAP() }; ``` ## Simple Sample (C++/MFC) — Maindlg.cpp - dialog implementation *Source: https://softelvdm.com/Documentation/SftButton%20DLL%203%200/Topic/sample_mfc_simple* ```cpp /****************************************************************************/ /* SftButton/DLL 3.0 - Button Control for C/C++ */ /* Copyright (C) 2026 Softel vdm, Inc. All Rights Reserved. */ /****************************************************************************/ #include "stdafx.h" #include "Simple.h" #include "Maindlg.h" #ifdef _DEBUG #undef THIS_FILE static char BASED_CODE THIS_FILE[] = __FILE__; #endif CMainDlg::CMainDlg(CWnd* pParent /*=NULL*/) : CDialog(CMainDlg::IDD, pParent) , m_pImg1(NULL) , m_pImg2(NULL) { } void CMainDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_SFTBUTTON1, m_Button1); DDX_Control(pDX, IDC_SFTBUTTON2, m_Button2); DDX_Control(pDX, IDC_SFTBUTTON3, m_Button3); } BEGIN_MESSAGE_MAP(CMainDlg, CDialog) ON_BN_CLICKED(IDC_SFTBUTTON1, OnButton1) ON_BN_CLICKED(IDC_SFTBUTTON2, OnButton2) ON_BN_CLICKED(IDC_SFTBUTTON3, OnButton3) ON_CONTROL(SFTBUTTONN_DROPDOWNCLICK, IDC_SFTBUTTON3, OnButton3DropDown) ON_BN_CLICKED(IDC_USE_THEMES, OnUseThemes) ON_BN_CLICKED(IDC_DARK_MODE, OnDarkMode) ON_WM_DESTROY() ON_WM_SETTINGCHANGE() END_MESSAGE_MAP() BOOL CMainDlg::OnInitDialog() { CDialog::OnInitDialog(); // Set dialog icon HICON hIcon = AfxGetApp()->LoadIcon(IDI_ICON1); SetIcon(hIcon, TRUE); SetIcon(hIcon, FALSE); // Apply dark mode to dialog SftDarkMode_ApplyToDialog(m_hWnd); // Configure SftButton control 1 { SFTBUTTON_CONTROL Ctl; Ctl.cbSize = sizeof(SFTBUTTON_CONTROL); m_Button1.GetControlInfo(&Ctl); Ctl.nDarkMode = SFTBUTTON_DARKMODE_AUTO;/* automatic dark mode support */ m_Button1.SetControlInfo(&Ctl); } // Configure SftButton control 2 { SFTBUTTON_CONTROL Ctl; Ctl.cbSize = sizeof(SFTBUTTON_CONTROL); m_Button2.GetControlInfo(&Ctl); Ctl.nDarkMode = SFTBUTTON_DARKMODE_AUTO;/* automatic dark mode support */ Ctl.Text.align = SFT_PICALIGN_LEFT;/* text horizontal alignment */ m_pImg1 = SftButton_LoadGDIPlusImageFromFile(_T("Res\\pic_world_48.png")); if (m_pImg1) Sft_SetPictureGDIPlusImage(&Ctl.Picture1, m_pImg1); Ctl.Picture1.align = SFT_PICALIGN_CENTER; Ctl.Picture1.valign = SFT_PICALIGN_VCENTER; m_pImg2 = SftButton_LoadGDIPlusImageFromFile(_T("Res\\pic_go_32.png")); if (m_pImg2) Sft_SetPictureGDIPlusImage(&Ctl.Picture2, m_pImg2); Ctl.Picture2.align = SFT_PICALIGN_LEFT; Ctl.Picture2.valign = SFT_PICALIGN_VCENTER; m_Button2.SetControlInfo(&Ctl); } // Configure SftButton control 3 { SFTBUTTON_CONTROL Ctl; Ctl.cbSize = sizeof(SFTBUTTON_CONTROL); m_Button3.GetControlInfo(&Ctl); Ctl.fShowDropDown = TRUE;/* show drop-down arrow */ Ctl.nDarkMode = SFTBUTTON_DARKMODE_AUTO;/* automatic dark mode support */ m_Button3.SetControlInfo(&Ctl); } CheckDlgButton(IDC_USE_THEMES, BST_CHECKED); CheckDlgButton(IDC_DARK_MODE, SftDarkMode_IsActive() ? BST_CHECKED : BST_UNCHECKED); return TRUE; } void CMainDlg::OnButton1() { AfxMessageBox(_T("Button 1 clicked!")); } void CMainDlg::OnButton2() { AfxMessageBox(_T("Button 2 clicked!")); } void CMainDlg::OnButton3() { AfxMessageBox(_T("Button 3 clicked!")); } void CMainDlg::OnButton3DropDown() { AfxMessageBox(_T("Button 3 drop-down clicked!")); } void CMainDlg::OnUseThemes() { int useThemes = (IsDlgButtonChecked(IDC_USE_THEMES) == BST_CHECKED) ? SFTBUTTON_THEME_YES : SFTBUTTON_THEME_NO; CSftButton* btns[] = { &m_Button1, &m_Button2, &m_Button3 }; for (int i = 0; i < (int)(sizeof(btns) / sizeof(btns[0])); ++i) { SFTBUTTON_CONTROL Ctl; Ctl.cbSize = sizeof(SFTBUTTON_CONTROL); btns[i]->GetControlInfo(&Ctl); Ctl.nUseThemes = useThemes; btns[i]->SetControlInfo(&Ctl); } } void CMainDlg::OnDarkMode() { BOOL fDark = (IsDlgButtonChecked(IDC_DARK_MODE) == BST_CHECKED); int btnMode = fDark ? SFTBUTTON_DARKMODE_ON : SFTBUTTON_DARKMODE_OFF; m_Button1.SetDarkMode(btnMode); m_Button2.SetDarkMode(btnMode); m_Button3.SetDarkMode(btnMode); SftDarkMode_SetActive(fDark); SftDarkMode_ApplyToDialog(m_hWnd); InvalidateRect(NULL, TRUE); } void CMainDlg::OnDestroy() { // Free GDI+ images now that the controls no longer reference them. if (m_pImg1) { SftButton_FreeGDIPlusImageLoadedFromFile(m_pImg1); m_pImg1 = NULL; } if (m_pImg2) { SftButton_FreeGDIPlusImageLoadedFromFile(m_pImg2); m_pImg2 = NULL; } CDialog::OnDestroy(); } LRESULT CMainDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { // Route through SftDarkMode first so it can handle WM_CTLCOLOR*, WM_ERASEBKGND, etc. INT_PTR dmResult; if (SftDarkMode_HandleDialogMessage(m_hWnd, message, wParam, lParam, &dmResult)) return dmResult; return CDialog::WindowProc(message, wParam, lParam); } void CMainDlg::OnSettingChange(UINT uFlags, LPCTSTR lpszSection) { CDialog::OnSettingChange(uFlags, lpszSection); // Forward to the SftButton controls so they can update (AUTO mode) if (lpszSection && lstrcmpW((LPCWSTR)lpszSection, L"ImmersiveColorSet") == 0) { SftDarkMode_Init(); SftDarkMode_ApplyToDialog(m_hWnd); m_Button1.SendMessage(WM_SETTINGCHANGE, uFlags, (LPARAM)lpszSection); m_Button2.SendMessage(WM_SETTINGCHANGE, uFlags, (LPARAM)lpszSection); m_Button3.SendMessage(WM_SETTINGCHANGE, uFlags, (LPARAM)lpszSection); InvalidateRect(NULL, TRUE); } } ```