VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

An Easy Way to Create a Transparent Form

Kwyshell  (3 Submissions)   Custom Controls/Forms/Menus   Visual Basic 3.0   Unknown Difficulty   Wed 3rd February 2021

I provide an easy to create the non-rectangle form with usercontrol. We may use the control to design a non-rectange form or a desktop animation easily.

Assumes
Sometime we will want to create a non-rectangle window to make our UI so Cool! But the only way to create a non-rectangle windows is just using the windows regions API.We can use the SetWindowRgn to change the window region. So to create a non-rectangle region is only thing we have to do and it's also the only problem we need to resolve. How to create an non-rectangle region ? The only way I know to do this is using the Region API then find a mask picture and assign a mask color to be transparent color. Now use the CombineRgn and scan each pixel of the mask picture. If we find the pixel holding the mask color attribute then we have to combine the region which has the same position as the pixel we found and assign the region size as one pixel size ( CreateRegion(x,y,1,1)). After scanning all of pixels of the mask picture ,the non-rectangle region has been done. Now assign the region to the windows to make the window non-rectangle. But I don't think this a good way to do this. The method is not fast enough. I don't know how to create the region faster. I find VB's UserControl has a powerful way to create a non-rectangle region. Sometime you may create the transparent control with UserControl in VB. You only have to set the backgtound property of UserControl to Transparent and assign a mask picture to the control. After doing this, VB have created the region for you. You can use the SetWindowRgn to change the region of the window. ~Gwyshell

API Declarations
Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function GetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long) As Long

Rate An Easy Way to Create a Transparent Form (17(17 Vote))
An Easy Way to Create a Transparent Form.bas

An Easy Way to Create a Transparent Form Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters