視窗處理技巧大全

2021-05-02 05:47:41 字數 4347 閱讀 3912

'vb提供了api函式setwindowlong和getwindowlong,可以讓我們很容易取得對視窗的操作;通過對視窗屬性的操作,可以更改視窗的顯示風格。有些看來是正常情況下無法實現的視窗,現在你可以很容易的實現。只要你想到,更多希奇古怪的你也能做到。快試試下面的例子吧。

'一下例子中可能用到的api宣告和常量?變數宣告

private declare function getwindowlong lib "user32" alias "getwindowlonga" (byval hwnd as long, byval nindex as long) as long

private declare function setwindowlong lib "user32" alias "setwindowlonga" (byval hwnd as long, byval nindex as long, byval dwnewlong as long) as long

private declare function setwindowpos lib "user32" (byval hwnd as long, byval hwndinsertafter as long, byval x as long, byval y as long, byval cx as long, byval cy as long, byval wflags as long) as long

private const swp_nosize = &h1

private const swp_nozorder = &h4

private const swp_nomove = &h2

private const swp_drawframe = &h20

private const gwl_style = (-16)

private const ws_thickframe = &h40000

private const ws_dlgframe = &h400000

private const ws_popup = &h80000000

private const ws_caption = &hc00000

private const ws_sysmenu = &h80000

private const ws_minimizebox = &h20000

private const ws_maximizebox = &h10000

private const ws_minimize = &h20000000

private const ws_maximize = &h1000000

'例子一:任何乙個控制項(只要有視窗,這是我們的前提,下同),你可以在執行時隨便更改它的大小。

private sub controlsize(controlname as control, settrue as boolean)

dim dwstyle as long

dwstyle = getwindowlong(controlname.hwnd, gwl_style)

if settrue then

dwstyle = dwstyle or ws_thickframe

else

dwstyle = dwstyle - ws_thickframe

end if

dwstyle = setwindowlong(controlname.hwnd, gwl_style, dwstyle)

setwindowpos controlname.hwnd, controlname.parent.hwnd, 0, 0, 0, 0, swp_nozorder or swp_nosize or swp_nomove or swp_drawframe

end sub

'用法:controlsize picture1,true;設定第二個引數為false取消這種設定,下同

'例子二:任何乙個控制項,我們都可以控制其顯示風格為對話方塊的風格。

private sub controldialog(controlname as control, settrue as boolean)

dim dwstyle as long

dwstyle = getwindowlong(controlname.hwnd, gwl_style)

if settrue then

dwstyle = dwstyle or ws_dlgframe

else

dwstyle = dwstyle - ws_dlgframe

end if

dwstyle = setwindowlong(controlname.hwnd, gwl_style, dwstyle)

setwindowpos controlname.hwnd, controlname.parent.hwnd, 0, 0, 0, 0, swp_nozorder or swp_nosize or swp_nomove or swp_drawframe

end sub

'用法:     controlsize picture1, true

'例子三:任何乙個控制項,我們都可以控制其顯示風格為模式對話方塊的風格

private sub controlmodal(controlname as control, settrue as boolean)

dim dwstyle as long

dwstyle = getwindowlong(controlname.hwnd, gwl_style)

if settrue then

dwstyle = dwstyle or ws_popup

else

dwstyle = dwstyle - ws_popup

end if

dwstyle = setwindowlong(controlname.hwnd, gwl_style, dwstyle)

setwindowpos controlname.hwnd, controlname.parent.hwnd, 0, 0, 0, 0, swp_nozorder or swp_nosize or swp_nomove or swp_drawframe

end sub

'用法:     controlmodal picture1, true

'例子四:任何乙個控制項,我們都可以給它加上標題欄,通過拖動標題欄,可以實現控制項的執行時移動。

private sub controlcaption(controlname as control, settrue as boolean)

dim dwstyle as long

dwstyle = getwindowlong(controlname.hwnd, gwl_style)

if settrue then

dwstyle = dwstyle or ws_caption

else

dwstyle = dwstyle - ws_caption

end if

dwstyle = setwindowlong(controlname.hwnd, gwl_style, dwstyle)

setwindowpos controlname.hwnd, controlname.parent.hwnd, 0, 0, 0, 0, swp_nozorder or swp_nosize or swp_nomove or swp_drawframe

end sub

'用法:     controlcaption picture1, true

'例子五:任何乙個控制項,我們都可以給它加上controlbox(所謂controlbox,就是窗體的圖示+最小化+最大化+關閉按鈕)。

private sub controlsysmenu(controlname as control, settrue as boolean)

dim dwstyle as long

dwstyle = getwindowlong(controlname.hwnd, gwl_style)

if settrue then

dwstyle = dwstyle or ws_sysmenu

else

dwstyle = dwstyle - ws_sysmenu

end if

dwstyle = setwindowlong(controlname.hwnd, gwl_style, dwstyle)

setwindowpos controlname.hwnd, controlname.parent.hwnd, 0, 0, 0, 0, swp_nozorder or swp_nosize or swp_nomove or swp_drawframe

end sub

'用法:     controlcaption picture1, true: controlsysmenu picture1, true

XShell 技巧大全

xshell是一款windows下非常優秀的遠端連線linux主機的工具,下面將xshell的一些常用技巧分享給大家。由於在linux的shell下,ctrl c是中斷當前指令,這個快捷鍵和windows下的複製快捷鍵衝突,所以經常犯錯誤。想複製的時候按了ctrl c,結果中斷了當前指令。在xshe...

Windows視窗訊息大全

windows視窗訊息大全,全不全自己看 include afxpriv.h 訊息值的定義 include dde.h dde訊息值的定義 include cpl.h 控制面板訊息值的定義 include wfext.h 檔案管理器的訊息值的定義 include ras.h ras 遠端訪問服務 的...

SQL語句大全 技巧

三 技巧 1 1 1,1 2的使用,在sql語句組合時用的較多 where 1 1 是表示選擇全部 where 1 2 全部不選,如 if strwhere begin set strsql select count as total from tblname where strwhere ende...