Jump to content

[C++] Borderless Window Movable


tierrilopes
 Share

Recommended Posts

Example:

Go to file EterLib/MSWindow.cpp

Look for:

LRESULT CMSWindow::WindowProcedure(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uiMsg)
	{
	case WM_SIZE:
		OnSize(wParam, lParam);
		break;

	case WM_ACTIVATEAPP:
		m_isActive = (wParam == WA_ACTIVE) || (wParam == WA_CLICKACTIVE);
		break;
	}

	return DefWindowProc(hWnd, uiMsg, wParam, lParam);
}

Replace all with:

LRESULT CMSWindow::WindowProcedure (HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
	//make borderless window
	static int xClick;
	static int yClick;
	switch (uiMsg) {
		case WM_SIZE:
			OnSize (wParam, lParam);
			break;
		case WM_ACTIVATEAPP:
			m_isActive = (wParam == WA_ACTIVE) || (wParam == WA_CLICKACTIVE);
			break;
		case WM_LBUTTONDOWN:
			//Tierri todo: Prevent the first click if CTRL is holded.  Code at PyAppPro and PyAppEve
			if (GetKeyState (VK_CONTROL) & 0x8000) {
				//Tierri: Restrict mouse input to current window
				SetCapture (hWnd);
				POINT mousei;
				GetMousePosition (&mousei);
				//Tierri: Get the click position
				xClick = mousei.x;
				yClick = mousei.y;
			}
			break;
		case WM_LBUTTONUP:
			//Rui: Window no longer requires all mouse input
			ReleaseCapture();
			break;
		case WM_MOUSEMOVE: {
			if (GetCapture() == hWnd && (GetKeyState (VK_CONTROL) & 0x8000)) { //Rui: Check if this window has mouse input
				//Rui: Get the window's screen coordinates
				RECT rc;
				POINT mouse;
				GetClientRect (&rc);
				GetMousePosition (&mouse);
				int windowWidth = (rc.right - rc.left);
				int windowHeight = (rc.bottom - rc.top);
				//Rui: Get the current mouse coordinates
				int xMouse = LOWORD (lParam);
				int yMouse = HIWORD (lParam);
				//Tierri: Calculate the new window coordinates
				int xWindow = (rc.left + mouse.x) - xClick;
				int yWindow = (rc.top + mouse.y) - yClick;
				//Tierri: Set the window's new screen position
				//SetPosition(xWindow, yWindow); //Rui: Was meant for debug at my client, DO NOT USE
				ClientToScreen (hWnd, &mouse);
				MoveWindow (hWnd, mouse.x - windowWidth / 2, mouse.y - windowHeight / 2, windowWidth, windowHeight, TRUE); //Tierri: Adjust center of window into mosue coords
			}
			break;
		}
	}
	return DefWindowProc (hWnd, uiMsg, wParam, lParam);
}

 

Look for:

bool CMSWindow::Create(const char* c_szName, int brush, DWORD cs, DWORD ws, HICON hIcon, int iCursorResource)
{
	Destroy();

	const char* c_szClassName = RegisterWindowClass(cs, brush, MSWindowProcedure, hIcon, iCursorResource);

	m_hWnd = CreateWindow(
		c_szClassName,
		c_szName,
		ws,
		0, 0, 0, 0,
		NULL,
		NULL,
		ms_hInstance,
		NULL);

	if (!m_hWnd)
		return false;

	SetWindowLong(m_hWnd, GWL_USERDATA, (DWORD) this);

	return true;
}

Replace with:

bool CMSWindow::Create (const char *c_szName, int brush, DWORD cs, DWORD ws, HICON hIcon, int iCursorResource)
{
	/*
	//make splash Tierri: Splash thing for board
	CSplash splash1(TEXT("Protect.bmp"), RGB(128, 128, 128));
	splash1.ShowSplash();
	Sleep(3000);
	splash1.CloseSplash();
	//end splash */
	//window creation
	//assert(ms_hInstance != NULL);
	Destroy();
	const char *c_szClassName = RegisterWindowClass (cs, brush, MSWindowProcedure, hIcon, iCursorResource);
	m_hWnd = CreateWindow (
				 c_szClassName, //Rui todo: Integrate new ClassName with antihacking analyser
				 c_szName,
				 WS_POPUP, //Tierri: HOLLY MOLLY THE SKILLS
				 0, 0, 0, 0,
				 NULL,
				 NULL,
				 ms_hInstance,
				 NULL);
	if (!m_hWnd) {
		return false;
	}
	SetWindowLong (m_hWnd, GWL_USERDATA, (DWORD) this);
	return true;
}

 

To move the window, hold CTRL while holding and dragging LEFT MOUSE BUTTON

Link to comment
Share on other sites

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...