Giter Club home page Giter Club logo

borderlesswindow's Introduction

BorderlessWindow

This sample application demonstrates the necessary WinAPI calls and window messages to handle to produce a resizable, borderless window (similar to Steam, GitHub for Windows).

sample

The borderless window can be resized, moved, and also supports all the Aero features a regular window has:

  • snapping to desktop halves/quadrants
  • shake to minimize all other windows
  • animations when minimizing, maximizing, restoring, snapping
  • native soft shadow around the window

The sample should work on Windows 7, 8/8.1 and 10.

What this example does not do:

  • Draw anything to the client area. You will need to fill the entire window with an opaque color, or the window frame may be visible inside your client area in borderless mode. In my use case I simply fill the D3D backbuffer covering the window's client area.
  • Calculate proper client/window size in windowed mode. You will need to use AdjustWindowRect and friends to calculate the correct window size for a desired client area size.

Keybinds:

  • F8 enables/disables dragging in the borderless window to move it
  • F9 enables/disables resizing the borderless window
  • F10 toggles between borderless and windowed mode
  • F11 toggles the aero shadow when in borderless mode

borderlesswindow's People

Contributors

melak47 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

borderlesswindow's Issues

How to install it?

I was wondering if it is possible to directly obtain the .exe file compiled for both 64-bit and 32-bit.
if not, then how can i create the .exe file so as to install it?

borderless with opengl issues

Not sure if this is the right place for my question, but I'll try anyway.

I'm using your method to create a borderless window with an opengl context. It's working but looks different from your example.The shadow seems to expand less from the edge and is almost nonexistent at corners. I'm wondering if this has to do with the calculate proper client size thing you pointed out in the readme. I've experimented but nothing seems to affect the shadow. Since I'm using the entire window for opengl shouldn't it be enough to just pass my desired window dimensions?

here is a comparison screenshot, the bottom one is my window.

I have almost no experience with win32 programming so forgive me if I'm doing stupid and the solution is obvious.

Blocked taskbar behavior after maximizing

After setting the taskbar to automatically hide, maximize the window, and then move the mouse to the bottom of the screen, the taskbar does not pop up.

If other applications are maximized, the taskbar will pop up.

License file is missing

This repo is very useful, code is much simpler and better than some other repos which abstract away window creation. The issue is it's missing a license, and so we cannot assume the code can be used.

Win10: Resize outside of window frame

I was wondering if there was any way to recreate the windows 10 behaviour that allows resizing on a transparent border around the (now frameless) window.
Visual Studio 2015 seems to be the only other application that seems to have recreated a similar behaviour, even if slightly differently (It allows resizing above the caption aswell, which is not possible for default windows).

I imagine one way to do it would be enabling WS_CAPTION | WS_POPUP | WS_THICKFRAME, removing the WS_CAPTION size from the top of the window in WM_NCCALCSIZE (without returning 0) and then drawing a transparent color in WM_NCPAINT, even though I'm not convinced it would work, and wonder if there may be an easier way to achieve the same effect.

See comment: https://github.com/melak47/BorderlessWindow/blob/master/BorderlessWindow/src/Window.cpp#L103#L105

Calling toggle_borderless() in constructor introduces resize artifacts when borderless.

I discovered something really weird with the borderless window code. As part of a attempt to create the window as borderless, but keep the boarder toggle option, I used to call toggle_borderless at the very end on the constructor. When resizing was introduced though, I discovered a strange bug. If toggle_borderless was called in the constructor, when resizing the window on the left, a weird stuttering appeared on the right. This persists even when the boarder is toggled to areo and back to borderless. This does not occur if toggle_boarderless is not called in the constructor. Any clue as what the problem is? Is this due to the fact that we redraw the window before it is fully drawn? Thanks!

Shadow does not show (Running on Win 8)

I have looked at the Github Application which I believe uses MahMetro and it seems to have a shadow when focused. Your BorderlessWindow does become border-less however does not have the shadows around it. Just for more information, I did run it with the Default Windows 8 Theme on VS2013RC.

On a side note:
To create this same effect, what are your thoughts on making a transparent border-less frame behind (z-index wise) another border-less frame (however, this one will be your application). The top frame will be slightly smaller than the frame below such that when you place the top frame in the middle of the frame below you will have a 10 - 20px padding between them.

The padding in the frame below will provide you enough canvas space where you will be where you can manually create the shadow from scratch or just use stretched images.

Drag when in the top area in borderless mode

When the window is borderless, the window can be dragged by cursor from anywhere in the client RECT area.
Is there any method in which we can only enable dragging when its within some area from the top?

The reason being, I want to create my own custom title bar (what should be considered as the HTCAPTION area) for windows.

example
Something like this, I am aiming for.

Noob question: can't think of a good title

The window will be borderless only if userdata is passed to CreateWindowExW which if I understand correctly is a void pointer to the BorderlessWindow object.

1280, 720, nullptr, nullptr, nullptr, userdata

my noob question is why is that necessary ?

if I used the following code in a plain wWinMain, the window won't be borderless.

CreateWindowExW( 
             0, window_class(wndproc), L"Borderless Window", 
             WS_POPUP | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, 
             1280, 720, nullptr, nullptr, nullptr, nullptr
         );

Why is main() used instead of winmain()?

I was wondering why main() is used instead of winmain(). I can't see any advantages to using main over winmain, other than the fact the main is more common outside of the windows api. The advatange to using winmain is that is what vc++ looks for while linking.

I would advocate for using winmain unless theatre is definite reason for using main because it requires less configuration and is more standard as a example project to be replicated by others.

Is there any way to remove the 1px border?

My recent project requires a semi-transparent borderless window. I'm using your method and direct2d for rendering on window 10:
image
(set alpha = 0.5F)
image

(set alpha = 0.0F)

As you can see there is still a 1px border. Is there any way to remove it?

Border color and maximize problems in Windows 8.1

Very nice sample. I ran it under win 8.1 and encountered some issues that I don't know how to fix:

  • border color remains white in win 8.1 when I change window background to any non-white color (for a window with shadow)
  • maximized window (the one with shadow) can be moved unlike regular maximized windows

For maximized window I think it's a matter of playing with styles to convince OS to leave maximized window alone and not move it, but for border color I don't know how DWM decides what value to use.

Here's example window with enlarged borders (rather than 1,1,1,1 used originally) to illustrate the color problem:
shadow

Interior is gray, as intended, but borders remain white. Any ideas how to overcome this limitation would be great. Especially not involving WM_NCPAINT.

The titlebar will appear again sometimes.

When I click/focus other window such as Chrome Brower, and then
MouseDown on the BorderlessWindow, and don't release, [This must be at the dragging state]
Then we will see the titlebar again.
Along with the border, and the maximize,minimize icons doesn't appear. This is at the Aero state,
At the win7 basic theme, when I maximize/restore the window by double clicking the window
The titlebar will appear in the procedure of maximize/restore.

adjust_maximized_client_rect fails when restore maximized window from taskbar

adjust_maximized_client_rect for me works fine when i minimize/maximize and restore window within my window, but problem appears when i hide (minimize) window using taskbar, and then again restore it with taskbar, size of the window still not fits correctly (it not fills hole monitor but a make size of my window a little larger ,and shift window down).

  1. Not maximized window (normal)
    image

  2. Maximized window (by double clicking on nc area or my maximize button).
    image

  3. But when window maximized and minimized by taskbar and restore it fails.
    image

And that happens on all sides of the window (i.e it little bigger that usual).

But when i resize taskbar, window again fits currently.
image

I try everything, send message WM_NCCALCSIZE, when message WM_SHOWWINDOW process, or manually move and change size of the window, but result still the same.

NOTE: In my window i use the same example as BordelessWindow only i change a little the HitTest, but that not causing this problem i've checked.

LRESULT HitTest(POINT p, HWND hwnd, bool handleResize) {
		// identify borders and corners to allow resizing the window.
		// Note: On Windows 10, windows behave differently and
		// allow resizing outside the visible window frame.
		// This implementation does not replicate that behavior.
		const POINT border{
			::GetSystemMetrics(SM_CXFRAME) + ::GetSystemMetrics(SM_CXPADDEDBORDER),
			::GetSystemMetrics(SM_CYFRAME) + ::GetSystemMetrics(SM_CXPADDEDBORDER)
		};
		RECT window;
		if (!::GetWindowRect(hwnd, &window)) {
			return HTNOWHERE;
		}

		bool handleDragForClient = FE_FALSE;
		bool handleDrag = FE_TRUE;

		const auto drag = handleDrag ? HTCAPTION : HTCLIENT;
		const auto dragClient = handleDragForClient ? HTCAPTION : HTCLIENT;

		enum region_mask {
			client = 0b0000,
			left = 0b0001,
			right = 0b0010,
			top = 0b0100,
			bottom = 0b1000,
		};

		const auto result = left * (p.x < (window.left + border.x)) |
			right * (p.x >= (window.right - border.x)) |
			top * (p.y < (window.top + border.y)) |
			bottom * (p.y >= (window.bottom - border.y));

		switch (result) {
		case left:           return handleResize ? HTLEFT : drag;
		case right:          return handleResize ? HTRIGHT : drag;
		case top:            return handleResize ? HTTOP : drag;
		case bottom:         return handleResize ? HTBOTTOM : drag;
		case top | left:  return handleResize ? HTTOPLEFT : drag;
		case top | right: return handleResize ? HTTOPRIGHT : drag;
		case bottom | left:  return handleResize ? HTBOTTOMLEFT : drag;
		case bottom | right: return handleResize ? HTBOTTOMRIGHT : drag;
		case client: {
			// Define the No Client Area Where we can drag. In this case is:
			// 0 -- window.right - 117 
			// |                     |
			// |                     |
			// window.top + 40 -------
			// 
			// NOTE: Client Area implement here using in Force Editor as PanelNonClientArea.
			if (
				// First rect.
				p.x >= 0 && p.x <= window.right - 117 &&
				p.y >= 0 && p.y <= window.top + 32 ||

				// Second rect.
				p.x >= (window.right / 2) + 100 && p.x <= window.right &&
				p.y >= window.top + 32 && p.y <= window.top + 64
				)
				return HTCAPTION;

			return dragClient;
		}
		default:             return HTNOWHERE;
		}
	}

Edit 1: I look up to the #14 issue, it shoud fix my problem, but it didn't.

How to remove the round corners

I am trying to render an ImGui dockspace, and using certain parts of your code in combination with glfw.

However, the resulting window has round corners, and hence, it might be introducing certain padding/space.
Screenshot_1

How do I remove the round corners? I need to test whether this is causing that gap.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.