平码公式规律出肖|平码可以买3个平码吗

VBGood網站全文搜索 Google

搜索VBGood全站網頁(全文搜索)
首頁 - 經驗之談 - 奇形怪狀的窗體
發表評論(0)作者:不詳, 平臺:VB6.0+Win98, 閱讀:9418, 日期:2001-06-25
奇形怪狀的窗體
普通的窗體都是方方的,使用API函數可以做出一些奇怪的形狀。比如,窗體是圓角矩形,在中間挖一個橢圓形的洞。

先要理解一個重要的概念:區域。區域是描述設備場景中某一塊的GDI對象,每個區域都有一個句柄。一個區域可以是矩形,也可以是復雜的多邊形,甚至是幾個區域組織在一起。窗體默認的區域就是我們看到的矩形,當然它并非一定要用這個默認的區域

現在開始,首先在窗體上做一個圓角矩形區域,這是窗體的大致輪廓。在圓角矩形里再確定一個橢圓形的區域,然后把這兩個區域組織成一個區域,并設置窗體的區域為這個組織出來的區域。

CreateRoundRectRgn函數用于創建一個圓角矩形區域;CreateEllipticRgn用于創建一個橢圓區域;CombineRgn函數用于將兩個區域組合為一個新區域;SetWindowRgn函數允許您改變窗口的區域。使用其他的函數還可以做出其他更奇怪的窗體。

源代碼如下:

Option Explicit

注釋: API 函數聲明

Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long

注釋:常數聲明

Private Const RGN_DIFF = 4
注釋: 目標區域被設置為兩個區域不相交的部分

注釋:模塊級變量聲明

Private OutRgn As Long
注釋: 外邊的圓角矩形區域
Private InRgn As Long
注釋: 里邊的橢圓區域
Private MyRgn As Long
注釋: 圓角區域剪切掉橢圓區域后的區域,也是窗體最終的形狀

Private Sub Form_Click()
If OutRgn <> 0 And InRgn <> 0 And MyRgn <> 0 Then Exit Sub
Dim w As Long, h As Long
w = ScaleX(Form1.Width, vbTwips, vbPixels)
h = ScaleY(Form1.Height, vbTwips, vbPixels)
MyRgn = CreateRectRgn(0, 0, 0, 0)
OutRgn = CreateRoundRectRgn(30, 30, w - 30, h - 30, 100, 100)
InRgn = CreateEllipticRgn(100, 100, w - 100, h - 100)
Call CombineRgn(MyRgn, OutRgn, InRgn, RGN_DIFF)
Call SetWindowRgn(Form1.hWnd, MyRgn, True)
Form1.BackColor = QBColor(4)
End Sub

Private Sub Form_DblClick()
Unload Form1
End Sub

Private Sub Form_Load()
OutRgn = 0
InRgn = 0
MyRgn = 0
Form1.Width = 7800
Form1.Height = 6000
End Sub

Private Sub Form_Unload(Cancel As Integer)
If MyRgn <> 0 Then DeleteObject MyRgn
If OutRgn <> 0 Then DeleteObject OutRgn
If InRgn <> 0 Then DeleteObject InRgn
End Sub

這個程序運行后,在窗體上單擊,窗體就會變形,雙擊窗體程序結束。要注意的是,在卸載窗體時,用DeleteObject函數刪除已定義的區域。
平码公式规律出肖 新手炒股指南 牛弘配资 排名前十的股票配资平台 商赢配资 雀神麻将推倒胡技巧 哈尔滨麻将单机版 一定牛湖北快三 快三贵州 欧冠足球赛 今晚cctv5直播