AUI Framework  master
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
Win32Util.h
    1/*
    2 * AUI Framework - Declarative UI toolkit for modern C++20
    3 * Copyright (C) 2020-2025 Alex2772 and Contributors
    4 *
    5 * SPDX-License-Identifier: MPL-2.0
    6 *
    7 * This Source Code Form is subject to the terms of the Mozilla Public
    8 * License, v. 2.0. If a copy of the MPL was not distributed with this
    9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
   10 */
   11
   12#pragma once
   13
   14#include "AUI/Image/AImage.h"
   15#include <Windows.h>
   16
   17namespace aui::win32 {
   24    API_AUI_VIEWS AImage iconToImage(HICON hIcon);
   25
   31    API_AUI_VIEWS AImage bitmapToImage(HBITMAP hbitmap);
   32
   33
   34    enum class BitmapMode {
   35        RGB,
   36        A
   37    };
   38
   39    namespace detail {
   40
   41        template<typename T>
   42        struct Win32Object: aui::noncopyable {
   43        public:
   44
   45            Win32Object(T value) : value(value) {}
   46            Win32Object(Win32Object&& rhs) noexcept : value(rhs.value) {
   47                rhs.value = nullptr;
   48            }
   49
   50            operator T() const noexcept {
   51                return value;
   52            }
   53
   54            ~Win32Object() {}
   55
   56        protected:
   57            T value = nullptr;
   58        };
   59    }
   60
   61    struct Bitmap: detail::Win32Object<HBITMAP> {
   62    public:
   63        using detail::Win32Object<HBITMAP>::Win32Object;
   64
   65        ~Bitmap() {
   66            if (value) {
   67                DeleteObject(value);
   68            }
   69        }
   70    };
   71
   72    struct DeviceContext: detail::Win32Object<HDC> {
   73    public:
   74        using detail::Win32Object<HDC>::Win32Object;
   75
   76        ~DeviceContext() {
   77            if (value) {
   78                ReleaseDC(NULL, value);
   79            }
   80        }
   81    };
   82
   83    API_AUI_VIEWS Bitmap imageRgbToBitmap(const AImage& image, BitmapMode mode = BitmapMode::RGB);
   84}
   85
   86
Owning image representation.
Definition AImage.h:25
API_AUI_VIEWS AImage bitmapToImage(HBITMAP hbitmap)
HBITMAP to AImage.
API_AUI_VIEWS AImage iconToImage(HICON hIcon)
HICON to AImage.
Forbids copy of your class.
Definition values.h:45
Definition Win32Util.h:61
Definition Win32Util.h:72