Results 1 to 2 of 2

Thread: Transparent Png Control by vb6

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Transparent Png Control by vb6

    PngBall2.AutoSize = False
    Call PngBall2.LoadPng("", "GLOBE", "PNG")

    PngBall1.LoadPng ("01Alpha_Png.png")

    GetWindowRect disables the display zoom (right-click of the program) when the GetWindowRect is set to high DPI, the pixels are not correct, what is the reason?

    How to get the check of "Disable display scaling when high DPI setting" is checked


    'Check, the desktop size is 3840,2160
    'Unchecked, desktop size 1920*1080

    Code:
    Public Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    '将客户区坐标系中的点转换为屏幕坐标
    Public Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
    Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    Public Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long
    Public Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    Public Type POINTAPI
            x As Long
            y As Long
    End Type
    Declare Function GetDesktopWindow Lib "user32" () As Long
      
    Sub Main()
    Dim Wnd As Long
    Wnd = GetDesktopWindow
    Dim WinRect1 As RECT, ClientWh1 As RECT, ClientXY1 As POINTAPI
    Dim WinRect2 As RECT, ClientWh2 As RECT, ClientXY2 As POINTAPI
    
    GetWindowRect Wnd, WinRect1
    MsgBox "桌面坐标:" & WinRect1.Left & "," & WinRect1.Right & "," & WinRect1.Top & "," & WinRect1.Bottom
    '获取【Form】的客户区坐标系(Right=宽度,Bottom=高度),重要,ABCD
    GetClientRect Wnd, ClientWh1
    '将客户区坐标系中的点p(0,0)转换为屏幕坐标(左上角位置),重要,ABCD
    ClientToScreen Wnd, ClientXY1
    
    End Sub
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by xiaoyao; Mar 30th, 2021 at 08:58 AM.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: Transparent Png Control by vb6

    I set the monitor to 2x DPI scaling
    while copy from GetDesktopWindow ,Double the size and position?
    Code:
    If GetDesktopWindow = Wnd Then
    'bit from GetDesktopWindow 
    
        StretchBlt MyHdc, 0, 0, W2, H2, ParentDc, _
        2 * (ClientXY1.x - WinRect1.Left + (ClientXY2.x - ClientXY1.x)), _
        2 * (ClientXY1.y - WinRect1.Top + (ClientXY2.y - ClientXY1.y)) _
        , W2 * 2, H2 * 2, vbSrcCopy
        
    Else
    'bit from form1.dc to picture1.hdc
        BitBlt MyHdc, 0, 0, W2, H2, ParentDc, ClientXY1.x - WinRect1.Left + (ClientXY2.x - ClientXY1.x), ClientXY1.y - WinRect1.Top + (ClientXY2.y - ClientXY1.y), vbSrcCopy
    End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width