-
Mar 26th, 2025, 05:16 AM
#1
[RESOLVED] UserControl -> Full screen; taskbar still visible
Based on https://stackoverflow.com/questions/...hiding-taskbar and some changes based on https://devblogs.microsoft.com/oldne...12-00/?p=14353, I'm using the following code to expand a UserControl hwnd to fullscreen:
Code:
Private Function EnterFullscreen() As Long
Dim hMon As LongPtr
Dim mi As MONITORINFO
hMon = MonitorFromWindow(UserControl.hWnd, MONITOR_DEFAULTTONEAREST)
mi.cbSize = LenB(mi)
GetMonitorInfo hMon, mi
Dim windowHDC As LongPtr
Dim fullscreenWidth As Long, fullscreenHeight As Long
Dim colourBits As Long, refreshRate As Long
windowHDC = GetDC(UserControl.hWnd)
fullscreenWidth = GetDeviceCaps(windowHDC, DESKTOPHORZRES)
fullscreenHeight = GetDeviceCaps(windowHDC, DESKTOPVERTRES)
colourBits = GetDeviceCaps(windowHDC, BITSPIXEL)
refreshRate = GetDeviceCaps(windowHDC, VREFRESH)
Dim fullscreenSettings As DEVMODE
Dim isChangeSuccessful As BOOL
Dim windowBoundary As RECT
EnumDisplaySettingsW(0, 0, fullscreenSettings)
fullscreenSettings.dmPelsWidth = fullscreenWidth
fullscreenSettings.dmPelsHeight = fullscreenHeight
fullscreenSettings.dmBitsPerPel = colourBits
fullscreenSettings.dmDisplayFrequency = refreshRate
fullscreenSettings.dmFields = DM_PELSWIDTH Or _
DM_PELSHEIGHT Or _
DM_BITSPERPEL Or _
DM_DISPLAYFREQUENCY
dwStyleOld = CLng(GetWindowLongPtr(UserControl.hWnd, GWL_STYLE))
dwStyleExOld = CLng(GetWindowLongPtr(UserControl.hWnd, GWL_EXSTYLE))
hParOld = GetParent(UserControl.hWnd)
SetParent UserControl.hWnd, 0
SetWindowLongPtr(UserControl.hWnd, GWL_EXSTYLE, WS_EX_APPWINDOW Or WS_EX_TOPMOST)
SetWindowLongPtr(UserControl.hWnd, GWL_STYLE, WS_POPUP Or WS_VISIBLE)
SetWindowPos(UserControl.hWnd, HWND_TOP, 0, 0, fullscreenWidth, fullscreenHeight, SWP_NOOWNERZORDER Or SWP_FRAMECHANGED)
isChangeSuccessful = ChangeDisplaySettings(fullscreenSettings, CDS_FULLSCREEN) = DISP_CHANGE_SUCCESSFUL
SetWindowPos(UserControl.hWnd, HWND_TOP, 0, 0, fullscreenWidth, fullscreenHeight, SWP_NOOWNERZORDER Or SWP_FRAMECHANGED) 'this was added after the original without didn't work
ShowWindow(UserControl.hWnd, SW_MAXIMIZE)
EnterFullscreen = isChangeSuccessful
End Function
Private Function ExitFullscreen() As Long
Dim isChangeSuccessful As BOOL
ShowWindow(UserControl.hWnd, SW_RESTORE)
SetWindowLongPtr(UserControl.hWnd, GWL_EXSTYLE, dwStyleExOld)
SetWindowLongPtr(UserControl.hWnd, GWL_STYLE, dwStyleOld)
isChangeSuccessful = ChangeDisplaySettings(vbNullPtr, CDS_RESET) = DISP_CHANGE_SUCCESSFUL
SetWindowPos(UserControl.hWnd, HWND_NOTOPMOST, 0, 0, UserControl.ScaleWidth, UserControl.ScaleHeight, SWP_SHOWWINDOW)
SetParent UserControl.hWnd, hParOld
ExitFullscreen = isChangeSuccessful
End Function
Everything says that window should now be recognized as fullscreen and the taskbar should get out of the way, it's not (but does for other apps).
Also when I exit full screen, the uc is on top of the entire form until I resize the form manually (UserControl.Width +1/-1 doesn't trigger the update).
Is there a better way that will result in autohiding? Or is this just a problem because it's not originally a top level window.
The video player it's for correctly plays in the full screen mode at least 
(PS- Creating a new window originally top level isnt ideal because the video player would have to be recreated from scratch, the file reopened, and seeked to the old position... very not idead)
Edit: I've solved the 2nd issue with Get/SetWindowPlacement; first issue I removed the ChangeDisplaySettings call so it does nothing but what's on Raymond Chen's article, taskbar is still there.
Last edited by fafalone; Mar 26th, 2025 at 07:16 AM.
-
Mar 26th, 2025, 07:31 AM
#2
Re: UserControl -> Full screen; taskbar still visible
Nevermind I got it, it started working after ShowWindow was removed and some others. Final working version:
Code:
Private Function EnterFullscreen() As Long
Dim hMon As LongPtr
Dim mi As MONITORINFO
hMon = MonitorFromWindow(UserControl.hWnd, MONITOR_DEFAULTTONEAREST)
mi.cbSize = LenB(mi)
If hMon = 0 Then Exit Function
GetMonitorInfo hMon, mi
GetWindowPlacement(UserControl.hWnd, mOldPlacement)
dwStyleOld = CLng(GetWindowLongPtr(UserControl.hWnd, GWL_STYLE))
dwStyleExOld = CLng(GetWindowLongPtr(UserControl.hWnd, GWL_EXSTYLE))
hParOld = GetParent(UserControl.hWnd)
SetParent UserControl.hWnd, GetDesktopWindow()
SetWindowLongPtr(UserControl.hWnd, GWL_STYLE, WS_POPUP Or WS_VISIBLE)
SetWindowPos(UserControl.hWnd, HWND_TOP, mi.rcMonitor.Left, mi.rcMonitor.Top, _
mi.rcMonitor.Right - mi.rcMonitor.Left, _
mi.rcMonitor.Bottom - mi.rcMonitor.Top, SWP_NOOWNERZORDER Or SWP_FRAMECHANGED)
EnterFullscreen = 1
End Function
Private Function ExitFullscreen() As Long
ShowWindow(UserControl.hWnd, SW_RESTORE)
SetWindowLongPtr(UserControl.hWnd, GWL_EXSTYLE, dwStyleExOld)
SetWindowLongPtr(UserControl.hWnd, GWL_STYLE, dwStyleOld)
SetWindowPos(UserControl.hWnd, HWND_NOTOPMOST, 0, 0, UserControl.ScaleWidth, UserControl.ScaleHeight, SWP_SHOWWINDOW)
SetParent UserControl.hWnd, hParOld
SetWindowPlacement UserControl.hWnd, mOldPlacement
UserControl.Width = UserControl.Width - 1
UserControl.Width = UserControl.Width + 1
ExitFullscreen = 1
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|