Skip to content

Timboy67678/WindowsPlusPlus

Repository files navigation

WindowsPlusPlus

WindowsPlusPlus is a C++ library providing object-oriented wrappers and abstractions for Windows dialogs, windows, and controls. It enables rapid development of rich, interactive GUIs using modern C++ techniques.

Features

  • Object-oriented dialog and window classes
  • Automatic mapping of Win32 messages to C++ callbacks
  • Easy creation and management of common controls (buttons, checkboxes, tabs, list views, etc.)
  • Designed for modularity and extensibility
  • Easily manage multiple windows with the message_loop implementation
  • XAML-Style window layout panels (Grid, Stack and Dock panels included)

Quick Start

Requirements

  • Windows (Win32 API)
  • C++17 or later
  • Visual Studio or compatible toolchain

Example: Creating a Window

#include "window.hpp"
#include "layout.hpp"
#include "controls.hpp"

using namespace wpp;

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow) {
    // Create a window
    auto window = std::make_shared<window_base>();

    // Create a grid panel as root layout
    auto layout = std::make_shared<layout::grid_panel>(window->get_handle());

    // Add controls to grid positions
    auto btn1 = std::make_shared<button>("OK");
    auto btn2 = std::make_shared<button>("Cancel");

    layout->add(btn1, /*row=*/0, /*column=*/0);
    layout->add(btn2, /*row=*/0, /*column=*/1);

    return window->run_window(layout);
}

This example uses the grid_panel layout. You can also use stack_panel or dock_panel for other layout scenarios. Panels allow flexible nesting and layout of controls/windows.


Example: Creating a Dialog

#include "stdafx.h"
#include "dialog.hpp"

using namespace wpp;

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow) {
    // IDD_MYDIALOG is a dialog resource defined in your .rc file
    dialog dlg(hInstance, IDD_MYDIALOG);

    // Optionally, connect handlers, e.g.
    // dlg.on_init_dialog = [](HWND hWnd, WPARAM, LPARAM) -> INT_PTR {
    //     // Initialization code here
    //     return TRUE;
    // };

    return dlg.run_dlg();
}

Example: Example Messaqge Loop implementation

#include "stdafx.h"
#include "resource.h"
#include "MainDialog.hpp"
#include "MainWindow.hpp"

INT APIENTRY _tWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, _In_ INT nCmdShow) {
    InitCommonControls();
    if (::GetModuleHandle(TEXT("Riched20.dll")) == NULL)
        ::LoadLibrary(TEXT("Riched20.dll"));

    auto mainwindow = std::make_unique<MainWindow>(TEXT("Test Window"), 0, 0, hInstance);
    auto dialog = std::make_unique<MainDialog>(hInstance);
    mainwindow->create_window();
    dialog->create_modeless();

    message_loop loop;
    loop.register_window(*mainwindow);
    loop.register_window(*dialog);
    loop.run();

    return 0;
}

How It Works

  • Use window and dialog base classes to create custom windows/dialogs.
  • Register controls with IDs and bind event handlers using lambdas or member functions.
  • Use the provided message_loop class to run your GUI event loop.

Credits

  • DarthTon's Xenos Injector for message mapping ideas and bound member thunking
  • WTL for dialog abstraction patterns

License

MIT (see LICENSE)


Copilot Usage

This project benefits from frequent use of GitHub Copilot, including the Visual Studio extension. Copilot helps speed up development by providing code suggestions, auto-completion, and assistance with complex patterns and boilerplate. While not all code is generated by Copilot, it contributes extensively to coding productivity and workflow.


For more code and usage, visit the TestProj directory and view individual classes for implementation details.


About

Library for object oriented dialogs

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published