Skip to content

Commit

Permalink
Redraw on MOVE, SIZEMOVE, and SIZING
Browse files Browse the repository at this point in the history
  • Loading branch information
Stehfyn committed Jul 29, 2023
1 parent b605615 commit 3135ffb
Show file tree
Hide file tree
Showing 3 changed files with 211 additions and 150 deletions.
60 changes: 55 additions & 5 deletions imgui-borderless-win32/BorderlessWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
#include <windowsx.h>
#include <dwmapi.h>
#include <iostream>
#include <unordered_map>


namespace
{
static UINT timer_id = 0;
static std::unordered_map<HWND, BorderlessWindow*> s_BorderlessInstanceMap;

enum class Style : DWORD
{
windowed = WS_OVERLAPPEDWINDOW | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
Expand Down Expand Up @@ -99,13 +104,15 @@ namespace

if (!handle) throw last_error("failed to create window");


return unique_handle{ handle };
}
}

BorderlessWindow::BorderlessWindow()
: m_hHWND{ create_window(&BorderlessWindow::WndProc, this) }
: m_hHWND{ create_window(&this->BorderlessWindow::WndProc, this) }
{
s_BorderlessInstanceMap.insert({ m_hHWND.get(), this });
GetClassNameW(m_hHWND.get(), m_wstrWC, 256);
set_composition(true);
set_borderless(true);
Expand Down Expand Up @@ -230,6 +237,7 @@ LRESULT BorderlessWindow::WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpa
GET_X_LPARAM(lparam),
GET_Y_LPARAM(lparam)
};

//::ScreenToClient(hwnd, &cursor);
if (window.m_bBorderless) {
return window.hit_test(cursor);
Expand Down Expand Up @@ -261,19 +269,61 @@ LRESULT BorderlessWindow::WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpa
break;

case WM_SIZE:
{
if (wparam != SIZE_MINIMIZED)
{
window.m_uWidth = LOWORD(lparam);
window.m_uHeight = HIWORD(lparam);
}

return 0;
}
case WM_SIZING:
{
if (wparam != SIZE_MINIMIZED)
{
window.m_uWidth = LOWORD(lparam);
window.m_uHeight = HIWORD(lparam);
}

auto it = s_BorderlessInstanceMap.find(hwnd);
if (it != s_BorderlessInstanceMap.end() && it->second) {
it->second->render_callback();
}
}
case WM_MOVE:
{
if (wparam != SIZE_MINIMIZED)
{
window.m_uWidth = LOWORD(lparam);
window.m_uHeight = HIWORD(lparam);
}

auto it = s_BorderlessInstanceMap.find(hwnd);
if (it != s_BorderlessInstanceMap.end() && it->second) {
it->second->render_callback();
}
}
case WM_ENTERSIZEMOVE: {
SetTimer(hwnd, (UINT_PTR)&timer_id, USER_TIMER_MINIMUM, NULL);
return 0;
}
case WM_EXITSIZEMOVE: {
KillTimer(hwnd, (UINT_PTR)&timer_id);
break;
}
case WM_TIMER: {
auto it = s_BorderlessInstanceMap.find(hwnd);
if (it != s_BorderlessInstanceMap.end() && it->second) {
it->second->render_callback();
}
break;
}

case WM_SYSCOMMAND:
if ((wparam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu
return 0;
#ifdef BORDERLESS_DEBUG
if ((wparam & 0xF012))
std::cout << "DRAG MOVE\n";
#endif

break;

case WM_DESTROY:
Expand Down
3 changes: 2 additions & 1 deletion imgui-borderless-win32/BorderlessWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <Windows.h>
#include "imgui.h"

#define BORDERLESS_DEBUG // Alloc a console to our Windows subsytem process
#define BORDERLESS_USE_IMGUI // Tell BorderlessWindow to call ImGui_ImplWin32_WndProcHandler in WndProc

struct hwnd_deleter {
Expand All @@ -27,6 +26,8 @@ class BorderlessWindow
BorderlessWindow();
BorderlessWindow(std::function<void()> render);

VOID render_callback() { if (m_fRender) m_fRender(); };
VOID set_render_callback(std::function<void()> render) { m_fRender = render; };
VOID set_composition(BOOL enabled);
VOID set_borderless(BOOL enabled);
VOID set_borderless_shadow(BOOL enabled);
Expand Down
Loading

0 comments on commit 3135ffb

Please sign in to comment.