Jump to content

Windows opening at the wrong position


Gurgarath

Recommended Posts

4 minutes ago, TMP4 said:

Can we edit the playable area? I think the best method to solve the height problem is to subtract some pixel, if it's possible.
(So the taskbar will not hide the bottom of the client)

isn't this what marty said above?

 

2 hours ago, martysama0134 said:

I cut it in order to see the whole client in 1920x1080 res (otherwise the Windows taskbar will eat up some pixels), Set titlebarSize to 0, otherwise set titlebarSize to 0 only if m_pySystem.GetHeight() >= 1000.

auto titlebarSize = (m_pySystem.GetHeight() >= 1000) ? 10 : 0;

 

 

Link to comment
Share on other sites

  • Contributor
20 minutes ago, HaiosMotan said:

isn't this what marty said above?

 

 

No, actually what Marty suggested there is to not substract the titlebar from the position 'y', but then you are where the coast breaks again because the taskbar will hide the bottom of the client.

I asked to actually shrink the playable area (not position y substaction) so the titlebar can be 100% visible while the taskbar will not hide the bottom of the client.

Edited by TMP4
  • Good 1
Link to comment
Share on other sites

19 hours ago, martysama0134 said:

I used GetWindowRect to calculate the dropshadow area automatically:

		AdjustSize(m_pySystem.GetWidth(), m_pySystem.GetHeight());

		if (Windowed)
		{
			m_isWindowed = true;
			RECT rc{};
			GetClientRect(&rc);
			auto windowWidth = rc.right - rc.left;
			auto windowHeight = (rc.bottom - rc.top);
			//TraceError("windowWidth %d == %d windowHeight %d == %d", windowWidth, m_pySystem.GetWidth(), windowHeight, m_pySystem.GetHeight());
			RECT rc2{};
			GetWindowRect(&rc2);
			auto windowWidth2 = rc2.right - rc2.left;
			auto windowHeight2 = (rc2.bottom - rc2.top);
			//TraceError("windowWidth2 %d windowHeight2 %d", windowWidth2, windowHeight2);
			auto windowWidthDiff = windowWidth2 - windowWidth;
			auto windowHeightDiff = windowHeight2 - windowHeight;
			//TraceError("windowWidthDiff %d windowHeightDiff %d", windowWidthDiff, windowHeightDiff);
			//TraceError("GetLastError %d", ::GetLastError());
			constexpr auto taskbarSize = 80;
			auto dropshadowSize = (windowWidthDiff / 2 != 0) ? (windowWidthDiff / 2 - 1) : 0;
			CMSApplication::SetPosition(((GetScreenWidth() - windowWidth) / 2) - dropshadowSize, (GetScreenHeight() - windowHeight - taskbarSize) / 2);
		}
		else
		{
			m_isWindowed = false;
			SetPosition(0, 0);
		}

This one is for 1920x1080 res

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowrect

Old way with second window:

		AdjustSize(m_pySystem.GetWidth(), m_pySystem.GetHeight());

		if (Windowed)
		{
			m_isWindowed = true;
			RECT rc{};
			GetClientRect(&rc);
			auto windowWidth = rc.right - rc.left;
			auto windowHeight = (rc.bottom - rc.top);
			//TraceError("windowWidth %d == %d windowHeight %d == %d", windowWidth, m_pySystem.GetWidth(), windowHeight, m_pySystem.GetHeight());
			RECT rc2{};
			GetWindowRect(&rc2);
			auto windowWidth2 = rc2.right - rc2.left;
			auto windowHeight2 = (rc2.bottom - rc2.top);
			//TraceError("windowWidth2 %d windowHeight2 %d", windowWidth2, windowHeight2);
			auto windowWidthDiff = windowWidth2 - windowWidth;
			auto windowHeightDiff = windowHeight2 - windowHeight;
			//TraceError("windowWidthDiff %d windowHeightDiff %d", windowWidthDiff, windowHeightDiff);
			//TraceError("GetLastError %d", ::GetLastError());
			auto dropshadowSize = (windowWidthDiff / 2 != 0) ? (windowWidthDiff / 2 - 1) : 0;
#ifdef ENABLE_CENTERED_CLIENT_WINDOW
			constexpr auto taskbarSize = 80;
			CMSApplication::SetPosition(((GetScreenWidth() - windowWidth) / 2) - dropshadowSize, (GetScreenHeight() - windowHeight - taskbarSize) / 2);
#else
			constexpr auto taskbarSize = 73;
			constexpr auto titlebarSize = 10;
			if (bAnotherWindow)
				CMSApplication::SetPosition(GetScreenWidth() - windowWidth - dropshadowSize, GetScreenHeight() - windowHeight - taskbarSize);
			else
				SetPosition(-dropshadowSize, -titlebarSize);
#endif
		}
		else
		{
			m_isWindowed = false;
			SetPosition(0, 0);
		}

 

isn't there any way of using

HWND taskBar = FindWindow(L"Shell_traywnd", NULL);

to find the exact height of the taskbar? some use big taskbar(default) others use "Use small taskbar buttons".

tried 2 ways from the comments and both leave gaps between m2 client and taskbar(ofcourse,i can increase the number of pixels for me,but it could make it worse for others)

  • Metin2 Dev 2
Link to comment
Share on other sites

  • Active Member
11 hours ago, HaiosMotan said:

isn't there any way of using

HWND taskBar = FindWindow(L"Shell_traywnd", NULL);

to find the exact height of the taskbar? some use big taskbar(default) others use "Use small taskbar buttons".

tried 2 ways from the comments and both leave gaps between m2 client and taskbar(ofcourse,i can increase the number of pixels for me,but it could make it worse for others)

//EterLib/MSWindow.h 
//after void GetWindowRect(RECT* prc);
//add this

bool GetWindowRect(HWND hWnd, LPRECT lpRect);

//EterLib/MSWindow.cpp
//after void CMSWindow::GetWindowRect(RECT* prc) {...}
//add this

bool CMSWindow::GetWindowRect(HWND hWnd, LPRECT lpRect)
{
	return ::GetWindowRect(hWnd, lpRect);
}

//UserInterface/PythonApplication.cpp
//under unsigned __GetWindowMode(bool windowed) {...}
//add this
int CPythonApplication::getTaskBarHeight()
{
	RECT rect{};
	HWND taskBar = FindWindow("Shell_traywnd", NULL);
	if (taskBar && GetWindowRect(taskBar, &rect)) {
		return rect.bottom - rect.top;
	}
}


//now you can use this function
int taskbarSize = getTaskBarHeight();

I have windows 10
The standard size of the taskbar is 40.
Every time we raise the taskbar up, 41 is added.
It works strangely.

40
81
122
163
204
etc...

Edited by Helia01
  • Metin2 Dev 1
Link to comment
Share on other sites

  • Forum Moderator
10 hours ago, TMP4 said:

Can we edit the playable area? I think the best method to solve the height problem is to subtract some pixel, if it's possible.
(So the taskbar will not hide the bottom of the client)

As far as I remember, this topic fixes it and play around with the playable area.

 

11 hours ago, HaiosMotan said:

isn't there any way of using

HWND taskBar = FindWindow(L"Shell_traywnd", NULL);

to find the exact height of the taskbar? some use big taskbar(default) others use "Use small taskbar buttons".

tried 2 ways from the comments and both leave gaps between m2 client and taskbar(ofcourse,i can increase the number of pixels for me,but it could make it worse for others)

I personnally use this to get my metrics. Note that I am using W11 and that Taskbar isn't really easy to tweak without going into regedit. Only available option is to hide it and the metrics catch it greatly.

Spoiler
			RECT work_area{0,0,0,0};
			SystemParametersInfo(SPI_GETWORKAREA, 0, &work_area, 0);

			// Get Screen Size with Taskbar
			const int32_t work_area_width = work_area.right - work_area.left;
			const int32_t work_area_height = work_area.bottom - work_area.top;
			
			// Get Application (caption) Size
			const int32_t caption_height = GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CXPADDEDBORDER);

			// Get Maximum Available Resolution
			const int32_t screen_width = GetScreenWidth();
			const int32_t screen_height = GetScreenHeight();

			// Get Metin2.cfg desired size
			const int32_t window_width = m_pySystem.GetWidth();
			const int32_t window_height = m_pySystem.GetHeight();

			// Get Taskbar Size
			const int32_t taskbar_height = GetScreenHeight() - work_area_height;
			
			TraceError("Caption Height %d", caption_height);
			TraceError("Taskbar Height %d", taskbar_height);
			TraceError("Screen Resolution %dx%d", screen_width, screen_height);
			TraceError("Maximum Available Resolution %dx%d", work_area_width, work_area_height);
			TraceError("CFG Resolution %dx%d", window_width, window_height);

unknown.png

 

Edited by Metin2 Dev
Core X - External 2 Internal
  • Love 3

Gurgarath
coming soon

Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.