HeaderPane
Main
Hide

SftButton/DLL 3.0 - Button Control

Share Link
Print

Using C

This section describes how to use SftButton/DLL in an application written using the C programming language.

Adding SftButton/DLL to an Application

Please see "Building Applications" to prepare a project for development with SftButton/DLL.

A)Every source program making use of a SftButton/DLL control must include the required header file SftButton.h by using the #include directive.
#include "SftButton.h" /* SftButton/DLL required header file */

This include statement should appear after the #include <windows.h> statement. The file is located in the directory \Program Files (x86)\Softelvdm\SftButton DLL 3.0\Include (unless changed during the installation). The project settings may need to be updated so the #include file can be located (see "Building Applications" for more information).

B)In order to use SftButton/DLL controls, an application must call the SftButton_RegisterApp function. The call to this function is required so that SftButton/DLL window classes can be registered. This call has to be made before any SftButton/DLL controls are created. Add the following statement to your source code, where your application registers its window classes (normally during application initialization):
SftButton_RegisterApp(hInstance); /* Use SftButton/DLL with this application */
C)Once SftButton/DLL controls are no longer needed, an application must call the SftButton_UnregisterApp function. The call to this function is required so that SftButton/DLL window classes can be unregistered and cleanup processing can take place. This call has to be made after all SftButton/DLL controls have been destroyed (normally during application termination).
SftButton_UnregisterApp(hInstance); /* No longer use SftButton/DLL */
D)The application's executable (Exe or Dll) must be linked with the correct Lib file, depending on the target environment. Please see "Building Applications" for more information.

Adding a Button Control

There are two methods to add a button control to an application:

  • using dialog resources
  • using CreateWindow(Ex)

Adding a button control using dialog resources is accomplished by using a resource editor to design a dialog. Once a button control is created, its window handle can be obtained by using the Windows GetDlgItem function. For more information, see Creating a Dialog Resource.

Another method to create a button control is by using the CreateWindow(Ex) Windows call:

hwndButton = CreateWindow(TEXT(SFTBUTTON_CLASS), NULL,
    WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0, 0, 120, 32, hwndMain,
    (HMENU) IDC_BUTTON, hInstance, NULL);

For more information on the various parameters used, see the Windows API documentation.

Configuring the Button

A newly created button control is configured using SftButton_SetControlInfo. Populate a SFTBUTTON_CONTROL structure with the desired images, text, colors, border style, theme and behavior flags, then pass it to SftButton_SetControlInfo.

SFTBUTTON_CONTROL Ctl;
ZeroMemory(&Ctl, sizeof(Ctl));
Ctl.cbSize = sizeof(Ctl);
Ctl.nBorderStyle = SFTBUTTON_BORDER_STANDARD;
Ctl.nUseThemes = SFTBUTTON_THEME_YES;
Ctl.nDarkMode = SFTBUTTON_DARKMODE_AUTO;
Ctl.nHighContrastMode = SFTBUTTON_HIGHCONTRAST_AUTO;
/* populate Text, Picture1, colors, etc. */
SftButton_SetControlInfo(hwndButton, &Ctl);

Handling Notifications

As with standard Windows controls, applications must respond to events and messages to cause controls to respond to user requests. For additional information, see Notifications.

Responding to Clicks

Respond to the WM_COMMAND / BN_CLICKED notification just as you would for a standard Windows push button:

case WM_COMMAND: {
    int id = LOWORD(wParam);
    int code = HIWORD(wParam);
    switch (id) {
    case IDC_BUTTON:
        if (code == BN_CLICKED)
            DoButtonAction();
        break;
    }
    break;
}

If the button has an attached dropdown arrow (fShowDropDown is TRUE), clicks on the arrow are delivered as SFTBUTTONN_DROPDOWNCLICK instead of BN_CLICKED. Handle them through the same WM_COMMAND switch.


Last Updated 04/25/2026 - (email)
© 2026 Softel vdm, Inc.