Assembly code snippets
Details
Title | Restricting window size |
---|---|
Author | Thomas |
Submitted by: | Thomas |
Date added: | 2002-02-17 19:28:05 |
Date modified: | 2002-02-17 19:28:05 |
Comments
Restricts window size to a minimum size. Call this function in the WM_SIZING handler.
Snippet
RestrictWindowSize PROTO STDCALL :DWORD, :DWORD, :DWORD, :DWORD
;===============================================================================
; Restrict Window Size
;===============================================================================
; Place this procedure in the WM_SIZING handler (and pass wParam & lParam)
;
; Written by Thomas Bleeker [exagone]. http://www.madwizard.org
;
RestrictWindowSize proc wParam:DWORD, lParam:DWORD, minWidth:DWORD, minHeight:DWORD
; wParam contains a WMSZ_? constant indicating which edge is being
; resized. lParam is a pointer to a RECT structure with the new
; size of the window.
mov ecx, wParam
mov edx, lParam
assume edx:PTR RECT
; --- get height ---
mov eax, [edx].bottom
sub eax, [edx].top
; --- Check if height is less than minHeight ---
sub eax, minHeight
.IF SIGN?
; --- Yes, so ajust size ---
.IF ecx==WMSZ_TOP || ecx==WMSZ_TOPLEFT || ecx==WMSZ_TOPRIGHT
add [edx].top, eax ;note that eax is negative here (height-minHeight)
.ELSE
sub [edx].bottom, eax ;seme here
.ENDIF
.ENDIF
; --- get width ---
mov eax, [edx].right
sub eax, [edx].left
; --- Check if width is less than minWidth ---
sub eax, minWidth
.IF SIGN?
; --- Yes, so ajust size ---
.IF ecx==WMSZ_LEFT || ecx==WMSZ_TOPLEFT || ecx==WMSZ_BOTTOMLEFT
add [edx].left, eax ;note that eax is negative here (width-minWidth)
.ELSE
sub [edx].right, eax ;same here
.ENDIF
.ENDIF
assume edx:nothing
ret
RestrictWindowSize endp
;===============================================================================
; Restrict Window Size
;===============================================================================
; Place this procedure in the WM_SIZING handler (and pass wParam & lParam)
;
; Written by Thomas Bleeker [exagone]. http://www.madwizard.org
;
RestrictWindowSize proc wParam:DWORD, lParam:DWORD, minWidth:DWORD, minHeight:DWORD
; wParam contains a WMSZ_? constant indicating which edge is being
; resized. lParam is a pointer to a RECT structure with the new
; size of the window.
mov ecx, wParam
mov edx, lParam
assume edx:PTR RECT
; --- get height ---
mov eax, [edx].bottom
sub eax, [edx].top
; --- Check if height is less than minHeight ---
sub eax, minHeight
.IF SIGN?
; --- Yes, so ajust size ---
.IF ecx==WMSZ_TOP || ecx==WMSZ_TOPLEFT || ecx==WMSZ_TOPRIGHT
add [edx].top, eax ;note that eax is negative here (height-minHeight)
.ELSE
sub [edx].bottom, eax ;seme here
.ENDIF
.ENDIF
; --- get width ---
mov eax, [edx].right
sub eax, [edx].left
; --- Check if width is less than minWidth ---
sub eax, minWidth
.IF SIGN?
; --- Yes, so ajust size ---
.IF ecx==WMSZ_LEFT || ecx==WMSZ_TOPLEFT || ecx==WMSZ_BOTTOMLEFT
add [edx].left, eax ;note that eax is negative here (width-minWidth)
.ELSE
sub [edx].right, eax ;same here
.ENDIF
.ENDIF
assume edx:nothing
ret
RestrictWindowSize endp