就是想用API控制視窗的BorderStyle,讓它可以在Sizable與Fixed Dialog之間切換。 請問如何實作?
uj5u.com熱心網友回復:
setwindowlong gwl_style加上/去掉WS_BORDERuj5u.com熱心網友回復:
謝謝版主,我試了下,不能去掉WS_BORDER(去掉了則標題欄都沒了,成了一個白板)。我的代碼如下,倒是可以變成和Fixed Dialog一個樣子,但是FixedDialog樣式在任務欄是不顯示圖示、按鈕的,而我這樣做卻有,和真正的FixedDialog樣式還是有本質的不一樣,還有什么改進或是重點所在嗎?
Function FrmStyle(hwnd As Long)
oStyle = GetWindowLong(hwnd, GWL_STYLE)
nStyle = oStyle Xor WS_SIZEBOX Xor WS_MAXIMIZEBOX Xor WS_MINIMIZEBOX
SetWindowLong hwnd, GWL_STYLE, nStyle
If bMenu Then
DeleteMenu hMenu, SC_SIZE, MF_BYCOMMAND
DeleteMenu hMenu, SC_MINIMIZE, MF_BYCOMMAND
DeleteMenu hMenu, SC_MAXIMIZE, MF_BYCOMMAND
Else
AppendMenu hMenu, MF_BYCOMMAND, SC_SIZE, "大小"
AppendMenu hMenu, MF_BYCOMMAND, SC_MINIMIZE, "最小化"
AppendMenu hMenu, MF_BYCOMMAND, SC_MAXIMIZE, "最大化"
End If
DrawMenuBar hMenu
bMenu = Not bMenu
wFlags = SWP_FRAMECHANGED Or SWP_NOMOVE Or SWP_NOSIZE
SetWindowPos hwnd, -1, 0, 0, 0, 0, wFlags
End Function
uj5u.com熱心網友回復:
設定完了要再發個重繪的訊息。uj5u.com熱心網友回復:
什么訊息?
uj5u.com熱心網友回復:
InvalidateRect
The InvalidateRect function adds a rectangle to the specified window's update region. The update region represents the portion of the window's client area that must be redrawn.
BOOL InvalidateRect(
HWND hWnd, // handle of window with changed update region
CONST RECT *lpRect,
// address of rectangle coordinates
BOOL bErase // erase-background flag
);
Parameters
hWnd
Handle to the window whose update region has changed. If this parameter is NULL, the system invalidates and redraws all windows, and sends theWM_ERASEBKGND and WM_NCPAINT messages to the window procedure before the function returns.
lpRect
Pointer to a RECT structure that contains the client coordinates of the rectangle to be added to the update region. If this parameter is NULL, the entire client area is added to the update region.
bErase
Specifies whether the background within the update region is to be erased when the update region is processed. If this parameter is TRUE, the background is erased when the BeginPaint function is called. If this parameter is FALSE, the background remains unchanged.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero.
Windows NT: To get extended error information, callGetLastError.
Remarks
The invalidated areas accumulate in the update region until the region is processed when the next WM_PAINT message occurs or until the region is validated by using the ValidateRect or ValidateRgn function.
The system sends a WM_PAINT message to a window whenever its update region is not empty and there are no other messages in the application queue for that window.
If the bErase parameter is TRUE for any part of the update region, the background is erased in the entire region, not just in the given part.
Windows CE: The hWnd parameter cannot be NULL.
QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 1.0 or later.
Header: Declared in winuser.h.
Import Library: Use user32.lib.
See Also
Painting and Drawing Overview, Painting and Drawing Functions, BeginPaint, InvalidateRgn, RECT, ValidateRect, ValidateRgn,WM_ERASEBKGND, WM_NCPAINT, WM_PAINT
uj5u.com熱心網友回復:
重繪了沒有,任務欄上依然有程式的按鈕在,說明它只是樣子像FixedDialog樣式,實際不是。轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/93876.html
標籤:API
