i made this as a quick/incomplete example. you should adjust the offsets, and take a look at microsofts dwm api. you should also consider doing your own painting. but that would go beyond the scope of what i was trying to demonstrate, with this short example.MSDN wrote:To remove the standard window frame, you must handle the WM_NCCALCSIZE message, specifically when its wParam value is TRUE and the return value is 0. By doing so, your application uses the entire window region as the client area, removing the standard frame.
also keep in mind that its recommended to create a linker option file, that specifically targets windows vista and higher: /SUBSYSTEM:WINDOWS,6.0. this way windows will not interfere with your size and position, and you will actually get what you actually see.
anyway, i hope it can be of some use.
Code: Select all
;Sizeable & Moveable Borderless-Window, with Snap-To-Edge & Aero-Snap by nco2k
EnableExplicit
;adjust to match your skin.
Global BorderWidth = GetSystemMetrics_(#SM_CXSIZEFRAME)
Global BorderHeight = GetSystemMetrics_(#SM_CYSIZEFRAME)
Global TitleBarHeight = GetSystemMetrics_(#SM_CYCAPTION)
;dont set too high or too low. 5-10 is the sweet-spot.
Global SnapWidth = 10
Global SnapHeight = 10
;dont modify!
Global IsSnappedX = #False
Global IsSnappedY = #False
Procedure.w GET_X_LPARAM(lParam)
ProcedureReturn lParam
EndProcedure
Procedure.w GET_Y_LPARAM(lParam)
ProcedureReturn lParam >> 16
EndProcedure
Procedure WndProc(hWnd, uMsg, wParam, lParam)
Protected Result = #PB_ProcessPureBasicEvents, *minmaxinfo.MINMAXINFO, CXSIZEFRAME, CYSIZEFRAME, CYCAPTION, *nccalcsize_params.NCCALCSIZE_PARAMS, WorkAreaRect.RECT, *WindowRect.RECT, WindowRect.RECT, WindowWidth, WindowHeight, MouseX, MouseY, IsCaption, IsTop, IsBottom, IsLeft, IsRight
Select uMsg
Case #WM_GETMINMAXINFO
Result = #False
*minmaxinfo = lParam
*minmaxinfo\ptMinTrackSize\x = GetSystemMetrics_(#SM_CXMINTRACK)
*minmaxinfo\ptMinTrackSize\y = BorderHeight * 2 + TitleBarHeight + 1
Case #WM_NCCALCSIZE
Result = #False
If wParam = #True
CXSIZEFRAME = GetSystemMetrics_(#SM_CXSIZEFRAME)
CYSIZEFRAME = GetSystemMetrics_(#SM_CYSIZEFRAME)
CYCAPTION = GetSystemMetrics_(#SM_CYCAPTION)
*nccalcsize_params = lParam
*nccalcsize_params\rgrc[0]\left - CXSIZEFRAME
*nccalcsize_params\rgrc[0]\top - CYCAPTION - CYSIZEFRAME
*nccalcsize_params\rgrc[0]\right + CXSIZEFRAME
*nccalcsize_params\rgrc[0]\bottom + CYSIZEFRAME
EndIf
Case #WM_NCHITTEST
Result = #HTNOWHERE
If GetWindowRect_(hWnd, @WindowRect) And WindowRect\right > WindowRect\left And WindowRect\bottom > WindowRect\top
MouseX = GET_X_LPARAM(lParam) - WindowRect\left
MouseY = GET_Y_LPARAM(lParam) - WindowRect\top
If MouseX > -1 And MouseY > -1
If MouseY >= BorderHeight And MouseY < TitleBarHeight + BorderHeight And MouseX >= BorderWidth And MouseX < WindowRect\right - WindowRect\left - BorderWidth
IsCaption = #True
Else
If MouseY < BorderHeight
IsTop = #True
ElseIf MouseY >= WindowRect\bottom - WindowRect\top - BorderHeight
IsBottom = #True
EndIf
If MouseX < BorderWidth
IsLeft = #True
ElseIf MouseX >= WindowRect\right - WindowRect\left - BorderWidth
IsRight = #True
EndIf
EndIf
If IsCaption = #True
Result = #HTCAPTION
ElseIf IsTop = #True
If IsLeft = #True
Result = #HTTOPLEFT
ElseIf IsRight = #True
Result = #HTTOPRIGHT
Else
Result = #HTTOP
EndIf
ElseIf IsBottom = #True
If IsLeft = #True
Result = #HTBOTTOMLEFT
ElseIf IsRight = #True
Result = #HTBOTTOMRIGHT
Else
Result = #HTBOTTOM
EndIf
ElseIf IsLeft = #True
Result = #HTLEFT
ElseIf IsRight = #True
Result = #HTRIGHT
Else
Result = #HTCLIENT
EndIf
EndIf
EndIf
Case #WM_MOVING
Result = #True
If SystemParametersInfo_(#SPI_GETWORKAREA, 0, @WorkAreaRect, 0) And WorkAreaRect\right > WorkAreaRect\left And WorkAreaRect\bottom > WorkAreaRect\top
*WindowRect = lParam
WindowWidth = *WindowRect\right - *WindowRect\left
WindowHeight = *WindowRect\bottom - *WindowRect\top
If WindowWidth > 0 And WindowHeight > 0
If (IsSnappedX = #False And *WindowRect\left >= WorkAreaRect\left And *WindowRect\left < WorkAreaRect\left + SnapWidth) Or (IsSnappedX = #True And *WindowRect\left = WorkAreaRect\left - 1)
*WindowRect\left = WorkAreaRect\left
*WindowRect\right = *WindowRect\left + WindowWidth
IsSnappedX = #True
ElseIf (IsSnappedX = #False And *WindowRect\right > WorkAreaRect\right - SnapWidth And *WindowRect\right <= WorkAreaRect\right) Or (IsSnappedX = #True And *WindowRect\right = WorkAreaRect\right + 1)
*WindowRect\left = WorkAreaRect\right - WindowWidth
*WindowRect\right = *WindowRect\left + WindowWidth
IsSnappedX = #True
ElseIf IsSnappedX = #True
If *WindowRect\left > WorkAreaRect\left And *WindowRect\left < WorkAreaRect\left + SnapWidth
*WindowRect\left = WorkAreaRect\left + SnapWidth
*WindowRect\right = *WindowRect\left + WindowWidth
IsSnappedX = #False
ElseIf *WindowRect\right > WorkAreaRect\right - SnapWidth And *WindowRect\right < WorkAreaRect\right
*WindowRect\left = WorkAreaRect\right - WindowWidth - SnapWidth
*WindowRect\right = *WindowRect\left + WindowWidth
IsSnappedX = #False
EndIf
EndIf
If (IsSnappedY = #False And *WindowRect\top >= WorkAreaRect\top And *WindowRect\top < WorkAreaRect\top + SnapHeight) Or (IsSnappedY = #True And *WindowRect\top = WorkAreaRect\top - 1)
*WindowRect\top = WorkAreaRect\top
*WindowRect\bottom = *WindowRect\top + WindowHeight
IsSnappedY = #True
ElseIf (IsSnappedY = #False And *WindowRect\bottom > WorkAreaRect\bottom - SnapHeight And *WindowRect\bottom <= WorkAreaRect\bottom) Or (IsSnappedY = #True And *WindowRect\bottom = WorkAreaRect\bottom + 1)
*WindowRect\top = WorkAreaRect\bottom - WindowHeight
*WindowRect\bottom = *WindowRect\top + WindowHeight
IsSnappedY = #True
ElseIf IsSnappedY = #True
If *WindowRect\top > WorkAreaRect\top And *WindowRect\top < WorkAreaRect\top + SnapHeight
*WindowRect\top = WorkAreaRect\top + SnapHeight
*WindowRect\bottom = *WindowRect\top + WindowHeight
IsSnappedY = #False
ElseIf *WindowRect\bottom > WorkAreaRect\bottom - SnapHeight And *WindowRect\bottom < WorkAreaRect\bottom
*WindowRect\top = WorkAreaRect\bottom - WindowHeight - SnapHeight
*WindowRect\bottom = *WindowRect\top + WindowHeight
IsSnappedY = #False
EndIf
EndIf
EndIf
EndIf
EndSelect
ProcedureReturn Result
EndProcedure
OpenWindow(0, 200, 200, 800, 600, "Sizeable & Moveable Borderless-Window", #PB_Window_Invisible | #PB_Window_BorderLess | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
SetWindowCallback(@WndProc(), 0)
SetClassLongPtr_(WindowID(0), #GCL_HBRBACKGROUND, GetStockObject_(#DKGRAY_BRUSH))
SetWindowPos_(WindowID(0), 0, 0, 0, 0, 0, #SWP_NOZORDER | #SWP_NOMOVE | #SWP_NOSIZE | #SWP_NOREDRAW | #SWP_FRAMECHANGED)
HideWindow(0, #False)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow : End
edit2+3: quick infotext added.
c ya,
nco2k