Hide

SftTabs/DLL 6.5 - Tab Control

Display
Print

Images Sample (C)

This sample illustrates a simple tabbed Images with nested tabs, some graphics, transition effects.

The source code is located at C:\Program Files (x86)\Softelvdm\SftTabs DLL 6.5\Samples\C\Images\Images.c or C:\Program Files\Softelvdm\SftTabs DLL 6.5\Samples\C\Images\Images.c (on 32-bit Windows versions).

/****************************************************************************/
/* SftTabs/DLL 6.5 - Tab Control for C/C++                                  */
/* Copyright (C) 1994, 2017  Softel vdm, Inc. All Rights Reserved.          */
/****************************************************************************/

#include <windows.h>

#include "sfttb.h"                       /* SftTabs/DLL Header File */

#include "resource.h"                   // application resources

/**********************************************************************/
/*                              Globals                               */
/**********************************************************************/

HINSTANCE g_hInst;                      // App Instance Handle

HWND m_hwndMainTab = NULL;              // tab control in main dialog

HBITMAP m_hSampleBitmap;                /* A sample bitmap */
HIMAGELIST m_hImgList;                  /* Imagelist control */
HICON m_hSampleIcon;                    /* A sample icon */

LPVOID m_lpGDIPlusImage;                /* Sample GDI+ images */
LPVOID m_lpGDIPlusImageHot;
LPVOID m_lpGDIPlusImageDisabled;
LPVOID m_lpGDIPlusUp;
LPVOID m_lpGDIPlusDown;
LPVOID m_lpGDIPlusLeft;
LPVOID m_lpGDIPlusRight;

/**********************************************************************/
/*                        Page 1 Dialog Proc                          */
/**********************************************************************/

void EnableThisTab(BOOL fEnable)
{
    SFTTABS_TAB Tab;
    SftTabs_GetTabInfo(m_hwndMainTab, 0, &Tab); // we're updating the first tab
    Tab.fEnabled = fEnable;
    SftTabs_SetTabInfo(m_hwndMainTab, 0, &Tab);
}

BOOL CALLBACK Page1_DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
    LRESULT lResult;

    switch (msg) {
    case WM_INITDIALOG:
        // initialize page
        SftTabs_SetPageActive(hwndDlg, (HWND) lParam, NULL);
        return !SftTabs_IsRegisteredDialog(GetParent(hwndDlg));

    case WM_COMMAND: {
        int code = (int)HIWORD(wParam);
        int ID = (int)LOWORD(wParam);
        HWND hwndCtl = (HWND)lParam;

        if (ID == IDC_GDI_LOAD || ID == IDC_GDI_LOAD_HOT || ID == IDC_GDI_LOAD_DISABLED) {
            if (code == BN_CLICKED) {
                OPENFILENAME ofn;
                TCHAR szFile[_MAX_PATH] = TEXT("");
                memset(&ofn, 0, sizeof(OPENFILENAME));
                ofn.lStructSize = sizeof(OPENFILENAME);
                ofn.hwndOwner = hwndDlg;
                ofn.lpstrFile = szFile;
                ofn.nMaxFile = sizeof(szFile)*sizeof(TCHAR);
                ofn.lpstrFilter = TEXT("All\0*.*\0");
                ofn.nFilterIndex = 0;
                ofn.lpstrFileTitle = NULL;
                ofn.nMaxFileTitle = 0;
                ofn.lpstrInitialDir = NULL;
                ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
                if (GetOpenFileName(&ofn)) {
                    LPVOID lpImage = SftTabs_LoadGDIPlusImageFromFile(ofn.lpstrFile);
                    if (lpImage) {
                        SFTTABS_TAB Tab;
                        SftTabs_GetTabInfo(m_hwndMainTab, 0, &Tab); // we're updating the first tab
                        if (ID == IDC_GDI_LOAD)
                            Sft_SetPictureGDIPlusImage(&Tab.TabPicture, lpImage);
                        else if (ID == IDC_GDI_LOAD_HOT)
                            Sft_SetPictureGDIPlusImage(&Tab.TabPictureHot, lpImage);
                        else if (ID == IDC_GDI_LOAD_DISABLED)
                            Sft_SetPictureGDIPlusImage(&Tab.TabPictureDisabled, lpImage);
                        SftTabs_SetTabInfo(m_hwndMainTab, 0, &Tab);

                        if (ID == IDC_GDI_LOAD) {
                            SftTabs_FreeGDIPlusImageLoadedFromResource(m_lpGDIPlusImage); // delete the current image
                            m_lpGDIPlusImage = lpImage;
                        } else if (ID == IDC_GDI_LOAD_HOT) {
                            SftTabs_FreeGDIPlusImageLoadedFromResource(m_lpGDIPlusImageHot);
                            m_lpGDIPlusImageHot = lpImage;
                        } else if (ID == IDC_GDI_LOAD_DISABLED) {
                            SftTabs_FreeGDIPlusImageLoadedFromResource(m_lpGDIPlusImageDisabled);
                            m_lpGDIPlusImageDisabled = lpImage;
                        }
                    }
                }
            }
        } else if (ID == IDC_TAB1_DISABLED) {
            if (code == BN_CLICKED) {
                if (SendMessage(hwndCtl, BM_GETCHECK, 0, 0) == BST_CHECKED)
                    EnableThisTab(FALSE);
                else
                    EnableThisTab(TRUE);
            }
        }
        break;
     }
    }

    if (SftTabs_HandleDialogMessage(hwndDlg, msg, wParam, lParam))
        return TRUE;
    if (SftTabs_TransparentControls(hwndDlg, NULL, &msg, &wParam, &lParam, &lResult, 0, 0))
        return (BOOL) lResult;

    return FALSE;
}

HWND CALLBACK Page1_Callback(BOOL fCreate, HWND hwndOwner, HWND hwndPage, HWND hwndTab)
{
    if (fCreate) {                      // creating a new page
        if (hwndPage) {
            // already created, we could do some initialization here.
            // this will be called every time the page becomes active.
            // The WM_SHOWWINDOW message is also sent to the page and could
            // be used to determine activation/deactivation of the page.

            // optional, set the main window's title to the window title defined for this page
            //SftTabs_CopyWindowTitle(hwndPage, hwndOwner);
            return NULL;                // return NULL, ignored
        } else {
            // Create the page.
            // You can create and initialize any type of window here, not just dialogs.
            // Use CreateWindow to create other windows. Don't specify WS_VISIBLE, but
            // make sure you use WS_TABSTOP.
            // When creating a non-dialog window, make sure to call SftTabs_SetPageActive
            // after the page has been created.
            HWND hwnd = CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_PAGE1), hwndOwner, (DLGPROC)Page1_DialogProc,
                    (LPARAM)hwndTab);// pass tab control as data
            // optional, set the main window's title to the window title defined for this page
            //SftTabs_CopyWindowTitle(hwnd, hwndOwner);
            return hwnd;
        }
    } else {                            // destroying page
        SendMessage(GetDlgItem(hwndPage, IDC_TAB1_DISABLED), BM_SETCHECK, BST_UNCHECKED, 0); // make sure we enable this tab so we can return here
        EnableThisTab(TRUE);
        if (hwndOwner)                  // - because we're switching away
            return hwndPage;            //   keep the window handle, don't destroy it
        else {                          // - because we're closing the main dialog
            DestroyWindow(hwndPage);
            return NULL;
        }
    }
}

/**********************************************************************/
/*                        Page 2 Dialog Proc                          */
/**********************************************************************/

BOOL CALLBACK Page2_DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
    LRESULT lResult;

    switch (msg) {
        case WM_INITDIALOG:
            SftTabs_SetPageActive(hwndDlg, (HWND) lParam, NULL);
            return !SftTabs_IsRegisteredDialog(GetParent(hwndDlg));

        case WM_COMMAND: {
            int code = (int)HIWORD(wParam);
            int ID = (int)LOWORD(wParam);
            HWND hwndCtl = (HWND)lParam;

            switch (ID) {
                case IDC_IMG_CHECKBOX: {
                    SFTTABS_TAB Tab;
                    SftTabs_GetTabInfo(m_hwndMainTab, 1, &Tab); // we're updating the second tab
                    Tab.graph.location = SFTTABS_GRAPH_LEFT;
                    Sft_SetPictureCheckBox(&Tab.TabPicture, 1, 16, 16, TRUE);
                    SftTabs_SetTabInfo(m_hwndMainTab, 1, &Tab);
                    break;
                 }
                case IDC_IMG_COLORSAMPLE: {
                    SFTTABS_TAB Tab;
                    SftTabs_GetTabInfo(m_hwndMainTab, 1, &Tab); // we're updating the second tab
                    Tab.graph.location = SFTTABS_GRAPH_BOTTOM;
                    Sft_SetPictureColorSample(&Tab.TabPicture, 32, 16, RGB(0,255,0), RGB(128,128,128));
                    SftTabs_SetTabInfo(m_hwndMainTab, 1, &Tab);
                    break;
                 }
                case IDC_IMG_IMAGELIST: {
                    SFTTABS_TAB Tab;
                    SftTabs_GetTabInfo(m_hwndMainTab, 1, &Tab); // we're updating the second tab
                    Tab.graph.location = SFTTABS_GRAPH_RIGHT;
                    Sft_SetPictureImageList(&Tab.TabPicture, m_hImgList, 4, 1);
                    SftTabs_SetTabInfo(m_hwndMainTab, 1, &Tab);
                    break;
                 }
                case IDC_IMG_ICON: {
                    SFTTABS_TAB Tab;
                    SftTabs_GetTabInfo(m_hwndMainTab, 1, &Tab); // we're updating the second tab
                    Tab.graph.location = SFTTABS_GRAPH_LEFT;
                    Sft_SetPictureIcon(&Tab.TabPicture, m_hSampleIcon);
                    SftTabs_SetTabInfo(m_hwndMainTab, 1, &Tab);
                    break;
                 }
                case IDC_IMG_BITMAP: {
                    SFTTABS_TAB Tab;
                    SftTabs_GetTabInfo(m_hwndMainTab, 1, &Tab); // we're updating the second tab
                    Tab.graph.location = SFTTABS_GRAPH_LEFT;
                    Sft_SetPictureBitmap(&Tab.TabPicture, m_hSampleBitmap);
                    SftTabs_SetTabInfo(m_hwndMainTab, 1, &Tab);
                    break;
                 }
                case IDC_IMG_CLEAR: {
                    SFTTABS_TAB Tab;
                    SftTabs_GetTabInfo(m_hwndMainTab, 1, &Tab); // we're updating the second tab
                    Tab.graph.location = SFTTABS_GRAPH_NONE;
                    Sft_ClearPicture(&Tab.TabPicture);
                    Sft_ClearPicture(&Tab.TabPictureHot);
                    Sft_ClearPicture(&Tab.TabPictureDisabled);
                    SftTabs_SetTabInfo(m_hwndMainTab, 1, &Tab);
                    break;
                 }

            }
            break;
         }
        case WM_DESTROY:
            break;
    }

    if (SftTabs_HandleDialogMessage(hwndDlg, msg, wParam, lParam))
        return TRUE;
    if (SftTabs_TransparentControls(hwndDlg, NULL, &msg, &wParam, &lParam, &lResult, SFTTABS_DRAWBG_OVERRIDETHEME, 0))
        return (BOOL) lResult;

    return FALSE;
}

HWND CALLBACK Page2_Callback(BOOL fCreate, HWND hwndOwner, HWND hwndPage, HWND hwndTab)
{
    if (fCreate) {                      // creating a new page
        if (hwndPage) {
            // already created, we could do some initialization here.
            // this will be called every time the page becomes active.
            // The WM_SHOWWINDOW message is also sent to the page and could
            // be used to determine activation/deactivation of the page.

            // optional, set the main window's title to the window title defined for this page
            //SftTabs_CopyWindowTitle(hwndPage, hwndOwner);
            return NULL;                // return NULL, ignored
        } else {
            // Create the page.
            // You can create and initialize any type of window here, not just dialogs.
            // Use CreateWindow to create other windows. Don't specify WS_VISIBLE, but
            // make sure you use WS_TABSTOP.
            // When creating a non-dialog window, make sure to call SftTabs_SetPageActive
            // after the page has been created.
            HWND hwnd = CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_PAGE2), hwndOwner, (DLGPROC)Page2_DialogProc,
                    (LPARAM)hwndTab);// pass tab control as data
            // optional, set the main window's title to the window title defined for this page
            //SftTabs_CopyWindowTitle(hwnd, hwndOwner);
            return hwnd;
        }
    } else {                            // destroying page
        if (hwndOwner)                  // - because we're switching away
            return hwndPage;            //   keep the window handle, don't destroy it
        else {                          // - because we're closing the main dialog
            DestroyWindow(hwndPage);
            return NULL;
        }
    }
}

/**********************************************************************/
/*                        Page 3 Dialog Proc                          */
/**********************************************************************/

BOOL CALLBACK Page3_DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
    LRESULT lResult;

    switch (msg) {
        case WM_INITDIALOG:
            SftTabs_SetPageActive(hwndDlg, (HWND) lParam, NULL);
            return !SftTabs_IsRegisteredDialog(GetParent(hwndDlg));

        case WM_COMMAND: {
            int code = (int)HIWORD(wParam);
            int ID = (int)LOWORD(wParam);
            HWND hwndCtl = (HWND)lParam;

            if (ID == IDC_SWITCHTAB) {
                if (code == BN_CLICKED) {
                    // change the tab control style
                    SFTTABS_CONTROL Ctl;
                    SftTabs_GetControlInfo(m_hwndMainTab, &Ctl);
                    if (Ctl.style == SFTTABSSTYLE_MODERN_I)
                        Ctl.style = SFTTABSSTYLE_BUTTONS;
                    else
                        Ctl.style = SFTTABSSTYLE_MODERN_I;
                    SftTabs_SetControlInfo(m_hwndMainTab, &Ctl);
                }
            }
            break;
        }
    }

    if (SftTabs_HandleDialogMessage(hwndDlg, msg, wParam, lParam))
        return TRUE;
    if (SftTabs_TransparentControls(hwndDlg, NULL, &msg, &wParam, &lParam, &lResult, 0, 0))
        return (BOOL) lResult;

    return FALSE;
}

HWND CALLBACK Page3_Callback(BOOL fCreate, HWND hwndOwner, HWND hwndPage, HWND hwndTab)
{
    if (fCreate) {                      // creating a new page
        if (hwndPage) {
            // already created, we could do some initialization here.
            // this will be called every time the page becomes active
            // The WM_CREATE/WM_INITDIALOG/WM_DESTROY messages are also sent to
            // the page and could be used to determine activation/deactivation.
            // of the page.

            // optional, set the main window's title to the window title defined for this page
            //SftTabs_CopyWindowTitle(hwndPage, hwndOwner);
            return NULL;
        } else {
            // Create the page.
            // You can create and initialize any type of window here, not just dialogs.
            // Use CreateWindow to create other windows. Don't specify WS_VISIBLE, but
            // make sure you use WS_TABSTOP.
            // When creating a non-dialog window, make sure to call SftTabs_SetPageActive
            // after the page has been created.
            HWND hwnd = CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_PAGE3), hwndOwner, (DLGPROC)Page3_DialogProc,
                    (LPARAM)hwndTab);// pass tab control as data
            // optional, set the main window's title to the window title defined for this page
            //SftTabs_CopyWindowTitle(hwnd, hwndOwner);
            return hwnd;
        }
    } else {                            // destroying page
        // We'll always destroy this page (to save resources)
        DestroyWindow(hwndPage);
        return NULL;
    }
}

/****************************************************************************/
/*                       Center the main dialog                             */
/****************************************************************************/

static void CenterWindow(HWND hwnd)
{
    RECT rc;
    RECT rcOwner;
    int x, y;

    GetWindowRect(hwnd, &rc);
    GetWindowRect(GetDesktopWindow(), &rcOwner);

    // Calculate the starting x,y for the new window so that it would be centered.
    x = rcOwner.left + (((rcOwner.right - rcOwner.left) - (rc.right - rc.left)) / 2);
    y = rcOwner.top + (((rcOwner.bottom - rcOwner.top) - (rc.bottom - rc.top)) / 2);

    SetWindowPos(hwnd, NULL, x, y, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER);
}

/**********************************************************************/
/*                          Frame Dialog Proc                         */
/**********************************************************************/

/*- Tab Control Initialization Data --------------------------------------------*/

static const SFTTABS_CONTROL CtlInit = {
    SFTTABSSTYLE_MODERN_I,               /* tab style */
    1,                                   /* number of rows */
    0,                                   /* number of tabs per row (if fFixed) */
    0,                                   /* width of left margin */
    0,                                   /* width of right margin */
    FALSE,                               /* same width for all tabs */
    TRUE,                                /* Client area wanted */
    FALSE,                               /* allow multiline label text */
    TRUE,                                /* use with dialog */
    FALSE,                               /* use specified background color only for text */
    FALSE,                               /* scrollable tabs */
    FALSE,                               /* hide scroll buttons */
    TRUE,                                /* bold font for active tab wanted */
    FALSE,                               /* fill rows completely */
    NULL,                                /* scroll button bitmap */
    NULL,                                /* Dialog data associated with active tab */
    NULL,                                /* Dialog window handle associated with active tab */
    NULL,                                /* Frame, used as client area */
    TRUE,                                /* Tooltips wanted */
    FALSE,                               /* drop text if it doesn't fit */
    FALSE,                               /* conditional scroll buttons */
    BMBUTTONSTYLE_THEME_SCROLL2,         /* scroll button style */
    TRUE,                                /* display ... if truncated */
    TRUE,                                /* Flyby highlighting */
    TRUE,                                /* use client area colors in partially obscured frames */
    FALSE,                               /* scroll buttons on left side */
    -1,                                  /* row indentation */
    FALSE,                               /* don't show truncated pattern for clipped tab */
    FALSE,                               /* full size scroll buttons */
    TRUE,                                /* use themes on Windows XP */
    FALSE,                               /* use exact window region */
    FALSE,                               /* always show prefix _ */
    0,0,0,0,                             /* animation values */
    NULL,                                /* disabled button bitmap */
    TRUE,                                /* focus rectangle if the control has i/p focus */
    FALSE,                               /* TRUE if Close button wanted */
    FALSE,                               /* TRUE if Close button disabled */
    TRUE,                                /* TRUE if WM_CLOSE message wanted */
    FALSE,                               /* TRUE if Minimize, Restore, Close buttons are full size */
    SFTTABS_BUTTON_NEAR,                 /* scroll button alignment */
    SFTTABS_BUTTON_NEAR,                 /* Minimize, Restore, Close button alignment */
    FALSE,                               /* TRUE if Minimize button wanted */
    FALSE,                               /* TRUE if Minimize button disabled */
    FALSE,                               /* TRUE if Restore button wanted */
    FALSE,                               /* TRUE if Restore button disabled */
    NULL,                                /* Close, Minimize, Restore button bitmap */
    NULL,                                /* Close, Minimize, Restore disabled button bitmap */
    TEXT("Scroll Left/Up"),              /* scroll left button tooltip */
    TEXT("Scroll Right/Down"),           /* scroll button tooltip */
    TEXT("Close"),                       /* Close button tooltip */
    TEXT("Minimize"),                    /* Minimize button tooltip */
    TEXT("Restore"),                     /* Restore button tooltip */
    0,                                   /* custom modifications */
    0,                                   /* forced height/width depending on tab style - 0 to ignore */
    FALSE,                               /* switch tabs on button release (or down if FALSE) */
    FALSE,                               /* Rendering compatible with pre-6.0 */
    FALSE,                               /* don't display clientarea border - select styles only */
    SFTTABS_TABS_LEFT,                   /* alignment of tabs on all rows */
    SFTTABS_LAYOUT_DISTRIBUTE,           /* distribution of tabs on rows */
    0, 0,                                /* minimum and maximum number of rows for autoflow layout (none specified) */
    FALSE,                               /* reorderable tabs */
    FALSE,                               /* drag & drop */
};

static const SFTTABS_TAB Tab0 = {   /*&{linksame "GDI+" g_gdiplus} Images */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color (when selected) */
    { SFTTABS_GRAPH_LEFT, 0 },           /* location */
    TRUE,                                /* enabled/disabled */
    0,                                   /* userdata */
    (SFTTABS_DWORD_PTR) Page1_Callback,  /* user supplied tab callback */
    NULL,                                /* reserved */
    SFTTABS_NOCOLOR,                     /* Flyby foreground color */
    SFTTABS_NOCOLOR,                     /* Client area background color */
    0,0,0,0,                             /* animation values */
    NULL,                                /* tab-specific ImageList handle*/
    FALSE,                               /* hidden tab */
    SFTTABS_NOCOLOR,                     /* gradient fill background color */
    SFTTABS_NOCOLOR,
    SFTTABS_NOCOLOR,                     /* gradient fill background color, active tab */
    SFTTABS_NOCOLOR,
    SFTTABS_NOCOLOR,                     /* gradient fill client area color */
    SFTTABS_NOCOLOR,
    0,0,0,                         /* TabPicture, TabPictureDisabled and TabPictureHot */
    FALSE,                               /* has tab close button */
    0,0,0,0,0,                   /* gap2, TabPicture2, TabPicture2Active, TabPicture2Disabled, TabPicture2Hot */
};
static const SFTTABS_TAB Tab1 = {   /*Other &Images */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color (when selected) */
    { SFTTABS_GRAPH_NONE, 0 },           /* location */
    TRUE,                                /* enabled/disabled */
    0,                                   /* userdata */
    (SFTTABS_DWORD_PTR) Page2_Callback,  /* user supplied tab callback */
    NULL,                                /* reserved */
    SFTTABS_NOCOLOR,                     /* Flyby foreground color */
    SFTTABS_NOCOLOR,                     /* Client area background color */
    0,0,0,0,                             /* animation values */
    NULL,                                /* tab-specific ImageList handle*/
    FALSE,                               /* hidden tab */
    SFTTABS_NOCOLOR,                     /* gradient fill background color */
    SFTTABS_NOCOLOR,
    SFTTABS_NOCOLOR,                     /* gradient fill background color, active tab */
    SFTTABS_NOCOLOR,
    SFTTABS_NOCOLOR,                     /* gradient fill client area color */
    SFTTABS_NOCOLOR,
    0,0,0,                         /* TabPicture, TabPictureDisabled and TabPictureHot */
    FALSE,                               /* has tab close button */
    0,0,0,0,0,                   /* gap2, TabPicture2, TabPicture2Active, TabPicture2Disabled, TabPicture2Hot */
};
static const SFTTABS_TAB Tab2 = {   /*Other Tab &Styles */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color (when selected) */
    { SFTTABS_GRAPH_NONE, 0 },           /* location */
    TRUE,                                /* enabled/disabled */
    0,                                   /* userdata */
    (SFTTABS_DWORD_PTR) Page3_Callback,  /* user supplied tab callback */
    NULL,                                /* reserved */
    SFTTABS_NOCOLOR,                     /* Flyby foreground color */
    SFTTABS_NOCOLOR,                     /* Client area background color */
    0,0,0,0,                             /* animation values */
    NULL,                                /* tab-specific ImageList handle*/
    FALSE,                               /* hidden tab */
    SFTTABS_NOCOLOR,                     /* gradient fill background color */
    SFTTABS_NOCOLOR,
    SFTTABS_NOCOLOR,                     /* gradient fill background color, active tab */
    SFTTABS_NOCOLOR,
    SFTTABS_NOCOLOR,                     /* gradient fill client area color */
    SFTTABS_NOCOLOR,
    0,0,0,                         /* TabPicture, TabPictureDisabled and TabPictureHot */
    FALSE,                               /* has tab close button */
    0,0,0,0,0,                   /* gap2, TabPicture2, TabPicture2Active, TabPicture2Disabled, TabPicture2Hot */
};

BOOL CALLBACK MainDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg) {

    case WM_INITDIALOG: {
        int index;
        HWND hwndTab;
        SFTTABS_TAB Tab;

        // Center this dialog
        CenterWindow(hwndDlg);

        m_hwndMainTab = hwndTab = GetDlgItem(hwndDlg, IDC_TAB); /* get the window handle */

        /* Initialization is faster if we set redraw off */
        SendMessage(hwndTab, WM_SETREDRAW, (WPARAM)FALSE, 0);

        /* We are using new features */
        SftTabs_SetVersion(hwndTab, SFTTABS_6_5);

        index = SftTabs_AddTab(hwndTab, TEXT("&GDI+ Images"));
        Tab = Tab0;
        Sft_SetPictureGDIPlusImage(&Tab.TabPicture, m_lpGDIPlusImage);
        Sft_SetPictureGDIPlusImage(&Tab.TabPictureHot, m_lpGDIPlusImageHot);
        Sft_SetPictureGDIPlusImage(&Tab.TabPictureDisabled, m_lpGDIPlusImageDisabled);
        SftTabs_SetTabInfo(hwndTab, index, &Tab);

        index = SftTabs_AddTab(hwndTab, TEXT("More &Images"));
        SftTabs_SetTabInfo(hwndTab, index, &Tab1);

        index = SftTabs_AddTab(hwndTab, TEXT("Other Tab &Styles"));
        SftTabs_SetTabInfo(hwndTab, index, &Tab2);

        SftTabs_SetControlInfo(hwndTab, &CtlInit);

        SftTabs_SetCurrentTab(hwndTab, 0);

        // Make sure to turn redraw back on
        SendMessage(hwndTab, WM_SETREDRAW, (WPARAM)TRUE, 0);
        InvalidateRect(hwndTab, NULL, TRUE);

        // Activate current page
        SftTabs_ActivatePage(hwndDlg, hwndTab, NULL, TRUE);

        // Mark the window as a main, tabbed dialog (so accel. keys work) by registering it.
        // Register the dialog AFTER activating the current page
        SftTabs_RegisterDialog(hwndDlg);

        return FALSE;                        // WM_INITDIALOG, input focus already set
     }

    case WM_DESTROY:
        // Unregister, or the window properties used won't be removed
        SftTabs_UnregisterDialog(hwndDlg);

        // destroy all pages
        SftTabs_Destroy(hwndDlg, GetDlgItem(hwndDlg, IDC_TAB));
        break;

    case WM_COMMAND: {
        // Parameter packing differs between 16-bit and 32-bit Windows
        HWND hwndCtl = (HWND) lParam;
        int id = LOWORD(wParam);
        int code = HIWORD(wParam);
        if (hwndCtl) {

            switch (id) {
            case IDC_TAB:
                switch (code) {
                case SFTTABSN_SWITCHING:// we're about to switch away from
                    // the current page.  If you need to know what the new
                    // page will be, use SftTabs_GetNextTab(hwndCtl).
                    if (!SftTabs_DeactivatePage(hwndDlg, hwndCtl))
                        // couldn't deactivate current page, so don't switch
                        SendMessage(hwndCtl, WM_CANCELMODE, 0, 0);
                    break;
                case SFTTABSN_SWITCHED: { // we switched to a new page
                    int currTab;
                    BOOL fNext = TRUE, fBack = TRUE;
                    SftTabs_ActivatePage(hwndDlg, hwndCtl, NULL, FALSE);

                    currTab = SftTabs_GetCurrentTab(m_hwndMainTab);

                    if (currTab == 0)
                        fBack = FALSE;
                    else if (currTab >= SftTabs_GetCount(m_hwndMainTab)-1)
                        fNext = FALSE;
                    EnableWindow(GetDlgItem(hwndDlg, IDC_BACK), fBack);
                    EnableWindow(GetDlgItem(hwndDlg, IDC_NEXT), fNext);
                    break;
                 }
                case SFTTABSN_LBUTTONDBLCLK_IMAGE: // left button click on tab picture
                case SFTTABSN_LBUTTONDOWN_IMAGE: {
                    int iTab = SftTabs_GetNextTab(m_hwndMainTab);
                    SFTTABS_TAB Tab;
                    SftTabs_GetTabInfo(m_hwndMainTab, iTab, &Tab); // retrieve tab information
                    if (Sft_IsPictureCheckBox(&Tab.TabPicture)) {
                        BOOL fChecked;
                        // it's a checkbox, so make sure to cancel this event so we don't switch tabs.
                        SendMessage(m_hwndMainTab, WM_CANCELMODE, 0, 0);
                        // change the checkbox state
                        fChecked = Tab.TabPicture.Picture.CheckBox.state;
                        fChecked = !fChecked;
                        Sft_SetPictureCheckBox(&Tab.TabPicture, fChecked, 16, 16, TRUE);
                        SftTabs_SetTabInfo(m_hwndMainTab, iTab, &Tab); // save the new tab settings
                    }
                 }
                }
                break;

            case IDC_NEXT:
                SftTabs_SwitchTab(m_hwndMainTab, TRUE);
                break;
            case IDC_BACK:
                SftTabs_SwitchTab(m_hwndMainTab, FALSE);
                break;
            case IDOK:
            case IDCANCEL:
                if (code == BN_CLICKED)
                    SendMessage(hwndDlg, WM_COMMAND, id, 0);
                break;
            }

        } else {
            switch (id) {
            case IDOK:
                // The currently active page will be called with a
                // WM_QUERYENDSESSION/SftTabs_GetEndPageMessage message
                // to determine whether it can be closed
                if (SftTabs_ClosePossible(hwndDlg, GetDlgItem(hwndDlg, IDC_TAB)))
                    EndDialog(hwndDlg, TRUE);
                break;
            case IDCANCEL:
                EndDialog(hwndDlg, FALSE);
                break;
            }
            // The above assumes that this is a modal dialog. If it is a modeless
            // don't use EndDialog, use DestroyWindow instead.
        }
        break;

     }

    }

    if (SftTabs_HandleDialogMessage(hwndDlg, msg, wParam, lParam))
        return TRUE;

    return FALSE;
}

/**********************************************************************/
/*                              WinMain                               */
/**********************************************************************/

int PASCAL WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR lpszCmdLine, int cmdShow)
{
    // Initialize
    g_hInst = hinst;

    SftTabs_RegisterApp(hinst);         /* Register with SftTabs/DLL */

    /* load the bitmaps/icons */
    m_hImgList = ImageList_LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_TOOLBAR), 16, 0, RGB(255,0,0));
    m_hSampleBitmap = LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_SMILE));
    m_hSampleIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ICON));
    m_lpGDIPlusImage = SftTabs_LoadGDIPlusImageFromResource(g_hInst, TEXT("PNG"), MAKEINTRESOURCE(IDR_IMAGE));
    m_lpGDIPlusImageHot = SftTabs_LoadGDIPlusImageFromResource(g_hInst, TEXT("PNG"), MAKEINTRESOURCE(IDR_IMAGE_HOT));
    m_lpGDIPlusImageDisabled = SftTabs_LoadGDIPlusImageFromResource(g_hInst, TEXT("PNG"), MAKEINTRESOURCE(IDR_IMAGE_DISABLED));
    m_lpGDIPlusUp = SftTabs_LoadGDIPlusImageFromResource(g_hInst, TEXT("PNG"), MAKEINTRESOURCE(IDR_UP));
    m_lpGDIPlusDown = SftTabs_LoadGDIPlusImageFromResource(g_hInst, TEXT("PNG"), MAKEINTRESOURCE(IDR_DOWN));
    m_lpGDIPlusLeft = SftTabs_LoadGDIPlusImageFromResource(g_hInst, TEXT("PNG"), MAKEINTRESOURCE(IDR_LEFT));
    m_lpGDIPlusRight = SftTabs_LoadGDIPlusImageFromResource(g_hInst, TEXT("PNG"), MAKEINTRESOURCE(IDR_RIGHT));

    // Initialize, run, and terminate the application
    DialogBox(g_hInst, MAKEINTRESOURCE(IDD_DIALOG1), NULL, (DLGPROC)MainDialogProc);

    /* delete the bitmaps/icons */
    DeleteObject(m_hSampleBitmap);
    SftTabs_FreeGDIPlusImageLoadedFromResource(m_lpGDIPlusImage);
    SftTabs_FreeGDIPlusImageLoadedFromResource(m_lpGDIPlusImageHot);
    SftTabs_FreeGDIPlusImageLoadedFromResource(m_lpGDIPlusImageDisabled);
    SftTabs_FreeGDIPlusImageLoadedFromResource(m_lpGDIPlusUp);
    SftTabs_FreeGDIPlusImageLoadedFromResource(m_lpGDIPlusDown);
    SftTabs_FreeGDIPlusImageLoadedFromResource(m_lpGDIPlusLeft);
    SftTabs_FreeGDIPlusImageLoadedFromResource(m_lpGDIPlusRight);
    ImageList_Destroy(m_hImgList);

    SftTabs_UnregisterApp(hinst);       /* Unregister from SftTabs/DLL */

    return 0;
}

Last Updated 08/13/2020 - (email)
© 2024 Softel vdm, Inc.