-------------------------------------------------- ------------------------------
Open Windows, watching the four-four party Fangli on the desktop, are you tired? Don't worry, in the Window world, as long as you can "heart", life is always beautiful and wonderful. Therefore, many "diverse" CFANs have made their own windows "transparent", "irregular". The author also has a bloody, making his window a "projected stereo window", see Figure 1: How? Cool!
In fact, it is not very difficult to make such a three-dimensional window, the principle is such a stereo): Name the left projection, DOWNFORM - below the left, RDForm- The lower right corner projection; 2. Get the location information of the three projection windows on the screen, write it in three projection windows according to the black gradient principle. Note: You cannot write its projected information into the screen DC, otherwise, the desktop will be painted by your painting. In addition: The window should be re-drawn when moving, changing the size. This is not very easy to do in VB, so we need to add a Timer control to the Timer event monitored this series of actions.
Ok, let's start doing this effect:
1. Start VB6.0, establish a new standard EXE project file, name "mainform", set the main window Formname, and set the scalemode to 3, and add three windows to the new window, name "Leftform", "Downform", "RDForm", and set its "borderStyle" to "0-none", write the respective GotFocus events as follows:
Mainform.setfocus
2. Create a new module API.BAS (you can use the "API browser" in "Add Programs" to insert the following code:
Public const srcopy = & hcc0020
PUBLIC TYPE RECT LEFT AS Long Top As Long Right As Long Bottom As Longend Type Public Declare Function SelectObject LIB "GDI32" (Byval Hobject As Long) As long
Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal DWROP As long) As longpublic declare function setpixel lib "gdi32" (Byval X as long, byval y as long, byval crcolor as long) As long
Public Declare Function Getpixel LIB "GDI32" (Byval X as long, Byval Y as long) As long
Public Declare Function CreateCompatibleDC LIB "GDI32" (Byval HDC As Long) As long
Public Declare Function CreateCompatibleBitmap lib "GDI32" (Byval NWIDTH AS Long, Byval NHEIGHT AS long) As long
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As LongPublic Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As LongPublic Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetWindowRect LIB "User32" (Byval n MOD 256 & End Function) AS Integer GetRed = n mod 256
'Value of Green in Color PUBLIC FUNCTION GETGREEN (BYVAL N As Long) AS Integer getGreen = (N / 256 &) MOD 256 & END FUNCTION
'Take the value of the color of the color PUBLIC FUNCTION GETBLUE (BYVAL N as long) AS integer getBlue = N / 65536End Function' Get Gradient Color Value 'Entry Parameters: Srccolor Original Color' Steps Steps 'Curstep Current Step' Dstcolor Target Color 'Return Value: Color Function Gettriencolor (Byval Scrcolor As Long, Byval Steder) AS Long Dim Sr, SG, SB, DR, DG, DB AS INTEGER SR, BYVAL STEGER SR, BYVAL STEGER SR = Getred (SCRCOLOR) SG = getGreen (SCRCOLOR) SB = getBlue (Scrcolor) DR = getred (dstcolor) DG = getGreen (dstcolor) DB = getBlue (dstcolor) SR = SR Curstep * (DR - SR) / Steps SG = SG CURSTEP * (DG - SG) / Steps SB = SB Curstep * (DB - SB) / Steps Gettriencolor = RGB (SR, SG, SB) End Function
The structure of its engineering file is shown in Figure 2: Figure 2 3, the mainform form is designed as shown in Figure 3, and the form code is added to the following code:
Option Explicitdim ShowdawdePth AS INTEGERDIM WINX, WINY, WINW, WINH, WX, WY, XW, XH AS Longdim showdawcolor as long
Private sub getwandh () DIM R AS RECT WY = MainForm.top wx = mainform.left call getWindowRect (mainform.hwnd, r) 'Get the location of the current window on the screen Winx = r.Left Winy = R.top WinH = R .Bottom - R.TOP 1 WINW = R.right - R.LEFT 1 'Re-adjust the left projection location Leftform.Left = ClNG (Scalex (R.Right, 3, 1) 0.5) Leftform.top = CLNG (Scaley (R.TOP, 3, 1) 0.5) Leftform.width = xw Leftform.Height = ClNG (Scaley (WinH, 3, 1) 0.5) 'Re-Adjusting the position of the projection below DOWNFORM.WIDTH = CLNG (Scalex (WINW, 3, 1) 0.5) DOWNFORM.HEIGHT = XH DOWNFORM.TOP = CLNG (Scaley (R.Bottom, 3, 1) 0.5) Downform.Left = ClNG (Scalex (R.Left, 3, 1) 0.5) 'Re-adjust the position of the projection of the lower right corner RdForm.top = ClNG (Scaley (R.Bottom, 3, 1) 0.5) Rdform.Left = ClNG (Scalex (R.Right, 3, 1) 0.5) RdForm.Width = xw RdForm.Height = xhEnd SubPrivate Sub Command1_Click () Unload MainFormEnd Sub Private Sub Form_Load () ShowdawDepth = 10 xh = CLng (ScaleY (ShowdawDepth, 3, 1) 0.5) xw = CLng (ScaleX (ShowdawDepth, 3 1) 0.5) showdawcolor = 0 Timer1.Interval = 100 dlg.cancelerro R = true labcolor.borderstyle = 1 labcolor.backstyle = 1 labcolor.backcolor = showdawcolorend SUB
Private Sub Paint () 'window drawing Dim hScreenDc, hMemLeftDc, hMemDownDc, hMemRdDc, x, y As Long Dim hMemLeftBit, hMemDownBit, hMemRdBit, curColor, srcColor As Long LeftForm.Visible = False DoEvents DownForm.Visible = False DoEvents RdForm.Visible = false DoEvents hScreenDc = GetDC (0) 'Get the desktop DC hMemLeftDc = CreateCompatibleDC (hScreenDc) hMemLeftBit = CreateCompatibleBitmap (hScreenDc, ShowdawDepth, WinH) SelectObject hMemLeftDc, hMemLeftBit hMemDownDc = CreateCompatibleDC (hScreenDc) hMemDownBit = CreateCompatibleBitmap (hScreenDc, WinW, ShowdawDepth) SelectObject hMemDownDc , hMemDownBit hMemRdDc = CreateCompatibleDC (hScreenDc) hMemRdBit = CreateCompatibleBitmap (hScreenDc, ShowdawDepth, ShowdawDepth) SelectObject hMemRdDc, hMemRdBit For y = 0 to WinH - 1 For x = 0 to ShowdawDepth - 1 'left projection srcColor = GetPixel (hScreenDc, WinW WinX X, Winy Y) if srccolor <> -1 Then If Y
GetTrienColor (ShowdawColor, srcColor, ShowdawDepth, x) End If SetPixel hMemRdDc, x, y, curColor End If Next x Next y For y = 0 To ShowdawDepth - 1 For x = 0 To WinW - 1 srcColor = GetPixel (hScreenDc, WinX x, WinY WinH y) If srcColor <> -1 Then If y
Private Sub Form_Unload (Cancel As Integer) Unload LeftForm Unload DownForm Unload RdFormEnd Sub Private Sub labColor_Click () On Error GoTo exitLabColor dlg.ShowColor ShowdawColor = dlg.Color labColor.BackColor = ShowdawColor Call Paint exitLabColor: End SubPrivate Sub Timer1_Timer () If MainForm. WindowState = VBNORMAL AND (Mainform.Left <> wx or mainform.top <> Wy) THEN CALL GETWANDH CALL PAINT End End End Sub
Private Sub Form_Paint () Call getWandh Call Paintend Sub
Private Sub UpDown_Change () ShowdawDepth = UpDown.Max UpDown.Min - UpDown.Value ShowSize.Text = ShowdawDepth xh = CLng (ScaleY (ShowdawDepth, 3, 1) 0.5) xw = CLng (ScaleX (ShowdawDepth, 3, 1) 0.5) Call getWandh Call Paintend Sub