WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Windows UDFs

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Disable Menu Items on Windows

Keywords:   Disable menu items on windows

We ran into one problem using the SetWindowLongA API call to disable the Size menu item. When another window overlapped our WinBatch box we were seeing leftover crud between the window border and the contents of the box itself.

After much headbanging we discovered that you need to disable the menu items before calling BoxesUp. (Naturally, the introduction of the function and the "Hey, what's that crud doing there?" observation were weeks apart, hence, a fairly brutal set of experiments looking for a culprit.)

The code below may be of use to others. Thanks again to Guido for the inner magic.

Mike Smith
Queen's University at Kingston

; Function DisableMenuItem(Handle, Item)
;
; Disable menu items on windows.  Possible ItemCode combinations are: 
;   1 - Maximize
;   2 - Minimize
;   4 - Size
;
; NOTE Call DisableMenuItem before calling BoxesUp.  Otherwise, disabling the Size item means
;      that crud gets left around the inside window border when another window overlaps your
;      WinBatch box.
#DefineFunction DisableMenuItem(dmiHandle,dmiItem)
	dmiUser32 = StrCat(DirWindows(1),"User32.DLL")
	GWL_STYLE = -16

	dmiButton = 0

	If (dmiItem & 1)
		dmiButton = dmiButton | 65536 ; WS_MAXIMIZEBOX
	EndIf

	If (dmiItem & 2)
		dmiButton = dmiButton | 131072 ; WS_MINIMIZEBOX
	EndIf

	If (dmiItem & 4)
		dmiButton = dmiButton | 262144 ; WS_SIZEBOX (WS_THICKFRAME)
	EndIf

	dmiPrevStyle = DllCall(dmiUser32, long:"GetWindowLongA", long:dmiHandle, long:GWL_STYLE)
	dmiDesStyle = dmiPrevStyle & ~dmiButton

	DllCall(dmiUser32, long:"SetWindowLongA", long:dmiHandle, long:GWL_STYLE, long:dmiDesStyle)

	return
#EndFunction

Article ID:   W15728
File Created: 2003:05:13:11:29:52
Last Updated: 2003:05:13:11:29:52