News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Win32 status bar recipe

Started by NoCforMe, December 12, 2023, 07:43:00 AM

Previous topic - Next topic

NoCforMe

Since there seems to be some confusion about how to do this, here's the recipe for a nice tasty status bar at the bottom of your window.

$SBID EQU 1111
$SBX EQU 0
$numStatusParts EQU 4 ;Remove if no status bar parts.
$SBlastPartOffset EQU 600 ;Remove if no status bar parts.
$SB_styles EQU WS_CHILD OR WS_VISIBLE

.data
StatusParts DD 75, 350, $SBlastPartOffset, -1
NullString DB 0

.data?
StatusHandle HWND ?
SBheight DD ?

.code
; Create the status bar:
INVOKE CreateStatusWindow, $SB_styles, OFFSET NullString, MainWinHandle, $SBID
MOV StatusHandle, EAX

; Get the height of the status bar:
INVOKE GetWindowRect, StatusHandle, ADDR gpRect
MOV EAX, gpRect.bottom
SUB EAX, gpRect.top
MOV SBheight, EAX

; Divide status bar into parts:
INVOKE SendMessage, StatusHandle, SB_SETPARTS, $numStatusParts, OFFSET StatusParts

; To set the status bar text:
INVOKE  SendMessage, StatusHandle, SB_SETTEXT, <index #>, <pointer to text>

; WM_SIZE handler:
INVOKE GetClientRect, hWin, ADDR gpRect

; Get new size from message:
MOVZX EAX, WORD PTR lParam
MOV newMainWinWidth, EAX
MOVZX EAX, WORD PTR lParam + 2
MOV newMainWinHeight, EAX

; Position status bar:
MOV EAX, newMainWinHeight
SUB EAX, SBheight
INVOKE MoveWindow, StatusHandle, 0,  EAX, gpRect.right, SBheight, TRUE
That's it. If you only need one field in the status bar you can skip all the stuff that divides it into parts and just use index 0 to display messages.
Assembly language programming should be fun. That's why I do it.

TimoVJL

#1
Statusbar resize itself, when gets WM_SIZE message and params are not used.
EDIT: typo with 'params'
May the source be with you

NoCforMe

Quote from: TimoVJL on December 12, 2023, 08:24:39 AM... and params are not used.

What does that mean, "params are not used"? Which params?

Maybe you mean something like in this reply elsewhere, where you just pass the WM_SIZE message on to the status window?
Assembly language programming should be fun. That's why I do it.