Quote from: Claude-Crype on September 12, 2025, 02:09:24 AMI need to create an unusual and provocative question for a tech forum related to Windows programming and similar topics. The format includes a topic line, like "Month Calendar Control - MONTHDAYSTATE," followed by a brief elaboration in a few sentences. It's a challenge to balance intrigue while staying relevant and tech-focused. I wonder what unique angles I can explore that would spark interest and engagement in this forum! Let's get creative!Presenting a tech questionThis sounds like a AI bot generated question especially as it's a new user account and first post?
' docking window winapi, 12-09-2025, frank bruebach
' freebasic
#Include "windows.bi"
Dim Shared hDock As HWND
Dim Shared hClient As HWND
Dim Shared isDragging As BOOL = FALSE
Dim Shared dragOffsetX As Integer, dragOffsetY As Integer
Const DOCK_WIDTH = 240
Const DOCK_HEIGHT = 160
Enum DockPos
DOCK_NONE
DOCK_LEFT
DOCK_RIGHT
DOCK_TOP
DOCK_BOTTOM
DOCK_FLOAT
End Enum
Dim Shared dockState As DockPos = DOCK_LEFT
Function WndProc(hWnd As HWND, msg As UINT, wParam As WPARAM, lParam As LPARAM) As LRESULT
Select Case msg
Case WM_CREATE
' Dockbares Panel
hDock = CreateWindowEx(WS_EX_CLIENTEDGE, "STATIC", "Dock Panel move me", _
WS_CHILD Or WS_VISIBLE Or SS_CENTER, _
20, 20, DOCK_WIDTH, 100, _
hWnd, Cast(HMENU, 1001), GetModuleHandle(NULL), NULL)
' Client Bereich
hClient = CreateWindowEx(0, "STATIC", "Client Area", _
WS_CHILD Or WS_VISIBLE Or SS_CENTER, _
10, 10, 200, 200, _
hWnd, 0, GetModuleHandle(NULL), NULL)
Return 0
Case WM_SIZE
Dim cx As Integer = LoWord(lParam)
Dim cy As Integer = HiWord(lParam)
Select Case dockState
Case DOCK_LEFT
MoveWindow(hDock, 0, 0, DOCK_WIDTH, cy, TRUE)
MoveWindow(hClient, DOCK_WIDTH, 0, cx-DOCK_WIDTH, cy, TRUE)
Case DOCK_RIGHT
MoveWindow(hDock, cx-DOCK_WIDTH, 0, DOCK_WIDTH, cy, TRUE)
MoveWindow(hClient, 0, 0, cx-DOCK_WIDTH, cy, TRUE)
Case DOCK_TOP
MoveWindow(hDock, 0, 0, cx, DOCK_HEIGHT, TRUE)
MoveWindow(hClient, 0, DOCK_HEIGHT, cx, cy-DOCK_HEIGHT, TRUE)
Case DOCK_BOTTOM
MoveWindow(hDock, 0, cy-DOCK_HEIGHT, cx, DOCK_HEIGHT, TRUE)
MoveWindow(hClient, 0, 0, cx, cy-DOCK_HEIGHT, TRUE)
'Case DOCK_FLOAT
' ' bleibt an aktueller Position
' MoveWindow(hClient, 0, 0, cx, cy, TRUE)
End Select
Return 0
Case WM_LBUTTONDOWN
Dim pt As POINT
pt.x = LoWord(lParam)
pt.y = HiWord(lParam)
Dim rc As RECT
GetWindowRect(hDock, @rc)
ScreenToClient(hWnd, Cast(LPPOINT, @rc.Left))
ScreenToClient(hWnd, Cast(LPPOINT, @rc.Right))
If PtInRect(@rc, pt) Then
isDragging = TRUE
SetCapture(hWnd)
dragOffsetX = pt.x - rc.Left
dragOffsetY = pt.y - rc.Top
EndIf
Return 0
Case WM_MOUSEMOVE
If isDragging Then
Dim pt As POINT
pt.x = LoWord(lParam)
pt.y = HiWord(lParam)
' Panel folgt Maus
MoveWindow(hDock, pt.x - dragOffsetX, pt.y - dragOffsetY, 120, 80, TRUE)
EndIf
Return 0
Case WM_LBUTTONUP
If isDragging Then
ReleaseCapture()
isDragging = FALSE
' Dock-Bereich ermitteln
Dim As Integer cx,cy
Dim rc As RECT
GetClientRect(hWnd, @rc)
cx = rc.Right
cy = rc.Bottom
Dim dockRc As RECT
GetWindowRect(hDock, @dockRc)
ScreenToClient(hWnd, Cast(LPPOINT, @dockRc.Left))
ScreenToClient(hWnd, Cast(LPPOINT, @dockRc.Right))
If dockRc.Left < 50 Then
dockState = DOCK_LEFT
ElseIf dockRc.Right > cx-50 Then
dockState = DOCK_RIGHT
ElseIf dockRc.Top < 50 Then
dockState = DOCK_TOP
ElseIf dockRc.Bottom > cy-50 Then
dockState = DOCK_BOTTOM
Else
dockState = DOCK_FLOAT
EndIf
' neu zeichnen
SendMessage(hWnd, WM_SIZE, 0, cy Shl 16 Or cx)
EndIf
Return 0
Case WM_DESTROY
PostQuitMessage(0)
Return 0
End Select
Return DefWindowProc(hWnd, msg, wParam, lParam)
End Function
Function WinMain(hInstance As HINSTANCE, hPrevInstance As HINSTANCE, szCmdLine As String, nCmdShow As Integer) As Integer
Dim wc As WNDCLASS
Dim msg As MSG
Dim hWnd As HWND
wc.style = CS_HREDRAW Or CS_VREDRAW
wc.lpfnWndProc = @WndProc
wc.cbClsExtra = 0
wc.cbWndExtra = 0
wc.hInstance = hInstance
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION)
wc.hCursor = LoadCursor(NULL, IDC_ARROW)
wc.hbrBackground = GetStockObject(WHITE_BRUSH)
wc.lpszMenuName = NULL
wc.lpszClassName = @"DockTest"
If RegisterClass(@wc) = FALSE Then Return 0
hWnd = CreateWindowEx(0, @"DockTest", "Docking Drag Example", WS_OVERLAPPEDWINDOW, _
CW_USEDEFAULT, CW_USEDEFAULT, 700, 500, _
NULL, NULL, hInstance, NULL)
ShowWindow(hWnd, nCmdShow)
UpdateWindow(hWnd)
While GetMessage(@msg, NULL, 0, 0) <> FALSE
TranslateMessage(@msg)
DispatchMessage(@msg)
Wend
Return msg.wParam
End Function
End WinMain(GetModuleHandle(NULL), NULL, Command(), SW_NORMAL)
'ends
' ########################################################################################
' Microsoft Windows
' File: CW_MonthValendar_MonthDayState.bas
' Contents: CWindow - Month calendar - Month day state
' Compiler: FreeBasic 32 & 64 bit
' Copyright (c) 2025 José Roca. Freeware. Use at your own risk.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#define UNICODE
#INCLUDE ONCE "AfxNova/CWindow.inc"
' // MCN_GETDAYSTATE is wrongly defined in the FreeBasic headers
#undef MCN_GETDAYSTATE
#define MCN_GETDAYSTATE culng(-747)
USING AfxNova
DECLARE FUNCTION wWinMain (BYVAL hInstance AS HINSTANCE, _
BYVAL hPrevInstance AS HINSTANCE, _
BYVAL pwszCmdLine AS WSTRING PTR, _
BYVAL nCmdShow AS LONG) AS LONG
END wWinMain(GetModuleHandleW(NULL), NULL, wCommand(), SW_NORMAL)
' // Forward declaration
DECLARE FUNCTION WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT
CONST IDC_MONTHCAL = 1001
#define BOLDDAY(ds, iDay) ds = ds OR (1 SHL (iDay - 1))
' ========================================================================================
' Main
' ========================================================================================
FUNCTION wWinMain (BYVAL hInstance AS HINSTANCE, _
BYVAL hPrevInstance AS HINSTANCE, _
BYVAL pwszCmdLine AS WSTRING PTR, _
BYVAL nCmdShow AS LONG) AS LONG
' // Set process DPI aware
SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE)
' // Enable visual styles without including a manifest file
AfxEnableVisualStyles
' // Creates the main window
DIM pWindow AS CWindow = "MyClassName" ' Use the name you wish
DIM hWin AS HWND = pWindow.Create(NULL, "CWindow - Month calendar", @WndProc)
' // Sizes it by setting the wanted width and height of its client area
pWindow.SetClientSize(400, 220)
' // Centers the window
pWindow.Center
' // Adds the control
pWindow.AddControl("SysMonthCal32", hWin, IDC_MONTHCAL, "", _
10, 10, pWindow.ClientWidth - 20, pWindow.ClientHeight - 20, WS_VISIBLE OR WS_TABSTOP OR MCS_DAYSTATE)
' // Anchors the control
pWindow.AnchorControl(IDC_MONTHCAL, AFX_ANCHOR_HEIGHT_WIDTH)
' // Displays the window and dispatches the Windows messages
FUNCTION = pWindow.DoEvents(nCmdShow)
END FUNCTION
' ========================================================================================
' ========================================================================================
' Main window procedure
' ========================================================================================
FUNCTION WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT
' Array to hold day states
STATIC rgDayState(11) AS MONTHDAYSTATE
SELECT CASE uMsg
' // If an application processes this message, it should return zero to continue
' // creation of the window. If the application returns –1, the window is destroyed
' // and the CreateWindowExW function returns a NULL handle.
CASE WM_CREATE
AfxEnableDarkModeForWindow(hwnd)
RETURN 0
' // Theme has changed
CASE WM_THEMECHANGED
AfxEnableDarkModeForWindow(hwnd)
RETURN 0
' // Sent when the user selects a command item from a menu, when a control sends a
' // notification message to its parent window, or when an accelerator keystroke is translated.
CASE WM_COMMAND
SELECT CASE CBCTL(wParam, lParam)
CASE IDCANCEL
' // If ESC key pressed, close the application by sending an WM_CLOSE message
IF CBCTLMSG(wParam, lParam) = BN_CLICKED THEN SendMessageW(hwnd, WM_CLOSE, 0, 0)
END SELECT
RETURN 0
CASE WM_NOTIFY
' // Process notification messages
DIM ptnmsc AS NMSELCHANGE PTR = CAST(NMSELCHANGE PTR, lParam)
' // Get selected date
IF ptnmsc->nmhdr.code = MCN_SELCHANGE THEN
DIM wszDate AS WSTRING * 260
wszDate = "Day: " & WSTR(ptnmsc->stSelStart.wDay) & " " & _
"Month: " & WSTR(ptnmsc->stSelStart.wMonth) & " " & _
"Year: " & WSTR(ptnmsc->stSelStart.wYear)
SendMessageW hwnd, WM_SETTEXT, 0, CAST(LPARAM, @wszDate)
' Note: Don't use MessageBox here or you will get non-stop messages!
EXIT FUNCTION
END IF
' // Set the day state
DIM pnmhdr AS LPNMHDR = CAST(LPNMHDR, lParam)
IF pnmhdr->code = MCN_GETDAYSTATE THEN
DIM pDayState AS LPNMDAYSTATE = CAST(LPNMDAYSTATE, lParam)
FOR i AS INTEGER = 0 TO pDayState->cDayState - 1
rgDayState(i) = 0
BOLDDAY(rgDayState(i), 1)
BOLDDAY(rgDayState(i), 15)
NEXT
pDayState->prgDayState = @rgDayState(0)
RETURN TRUE
END IF
CASE WM_DESTROY
' // End the application by sending an WM_QUIT message
PostQuitMessage(0)
RETURN 0
END SELECT
' // Default processing of Windows messages
FUNCTION = DefWindowProcW(hwnd, uMsg, wParam, lParam)
END FUNCTION
' ========================================================================================
pWindow.AddControl("Frame", hWin, IDC_FRAME, "Frame", 20, 20, 360, 120)
pWindow.AddControl("Frame", hWin, IDC_FRAME, "", 20, 20, 360, 120)