Announcement

Collapse
No announcement yet.

Invisible window

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Patrice Terrier
    replied
    Semen--

    You can create "holes" in your transparent window using regions.
    This will allow you to click in some areas.

    You could also create your transparent window as a static window and
    make it a child of the desktop window, and let it pass mouse click to
    its parent using %SS_NOTIFY, but then there is no advantage in using
    a transparent window.




    ------------------
    Patrice Terrier
    mailto[email protected][email protected]</A>

    Leave a comment:


  • Semen Matusovski
    replied
    Patrice --
    I tested under Win95 - WS_EX_TRANSPARENT also works fine.
    But now - a new problem.
    In certain cases I need to pass events (processing should be the same as w/o "transparent" window).
    For example, mouse click in some areas.
    I guess that it's possible to move transparent window outside screen, to execute MouseEvent, and to return transparent window back.

    But looks enough stupid. Is there another way ?

    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Semen Matusovski
    replied
    Patrice --
    I tested under Win2000.
    Fantastic. Thanks a lot



    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Patrice Terrier
    replied
    Semen--

    >> 2) more important (what I want to avoid) - a lot of operations
    >> Permanent redrawing of whole screen during moving/sizing of "GUI window".
    See hWndMain for the minor change I did to your code to avoid permanent redrawing
    while moving/sizing of your hWndChild.
    See also the code '*' that has been disabled (rem)
    This has been tested on 98 not on other platforms.


    Code:
       
       #Compile Exe
       #Dim All
       #Register None
       #Include "WIN32API.INC"
    
       Global hWndMain As Long, hWndChild As Long
    
       Function WndProc1 (ByVal hWnd As Long, ByVal wMsg As Long, _
          ByVal wParam As Long, ByVal lParam As Long) As Long
          
          Select Case wMsg
             Case %WM_ACTIVATEAPP, %WM_SETTINGCHANGE, %WM_WININICHANGE
                Dim hDC As Long, hMemDC As Static Long, hWndD As Long, bmp As Static BITMAP, hMemBmp As Static Long, hBmpOld As Long
                
                If (wMsg = %WM_ACTIVATEAPP) And (wParam = 0) Then
                Else
    '*'               DeleteObject hMemDC: DeleteObject hMemBmp
    '*'               hWndD = GetDesktopWindow
    '*'               hDC = GetWindowDC(hWndD)
    '*'
    '*'               bmp.bmBitsPixel = GetDeviceCaps(hdc, %BITSPIXEL)
    '*'               bmp.bmPlanes =  GetDeviceCaps(hdc, %PLANES)
    '*'               bmp.bmWidth = GetDeviceCaps(hdc, %HORZRES)
    '*'               bmp.bmHeight = GetDeviceCaps(hdc, %VERTRES)
    '*'               bmp.bmWidthBytes = Fix((bmp.bmWidth + 15) / 16) * 2
    '*'
    '*'               hMemBmp = CreateBitmap(bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, ByVal 0&)
    '*'               hMemDC = CreateCompatibleDC (hDC)
    '*'               hBmpOld = SelectObject (hMemDC, hMemBmp)
    '*'               BitBlt hMemDC, 0, 0, bmp.bmWidth, bmp.bmHeight, hdc, 0, 0, %SRCCOPY
    '*'               ReleaseDC hWndD, hDC
                End If
             Case %WM_LBUTTONDOWN
                Beep
             Case %WM_ERASEBKGND
    '*'            BitBlt wParam, 0, 0, bmp.bmWidth, bmp.bmHeight, hMemdc, 0, 0, %SRCCOPY
                Function = 1: Exit Function
             Case %WM_DESTROY
                PostQuitMessage 0
           End Select
          
           Function = DefWindowProc(hWnd, wMsg, wParam, lParam)
       End Function
    
       Function WndProc2 (ByVal hWnd As Long, ByVal wMsg As Long, _
          ByVal wParam As Long, ByVal lParam As Long) As Long
          Select Case wMsg
             Case %WM_DESTROY
                PostQuitMessage 0
          End Select
    
          Function = DefWindowProc(hWnd, wMsg, wParam, lParam)
       End Function
    
       Function PbMain
    
          Local wc As WNDCLASSEX
          Local szClassName As Asciiz * 80
          szClassName = "W1"
          wc.cbSize = SizeOf(wc)
          wc.style = %CS_HREDRAW Or %CS_VREDRAW
          wc.lpfnWndProc = CodePtr(WndProc1)
          wc.cbClsExtra = 0
          wc.cbWndExtra = 0
          wc.hInstance = GetModuleHandle("")
          wc.hIcon = LoadIcon(wc.hInstance, "PROGRAM" )
          wc.hCursor = LoadCursor(ByVal 0&, ByVal %IDC_ARROW )
          wc.hbrBackground = GetStockObject(%NULL_BRUSH)
          wc.lpszMenuName = 0
          wc.lpszClassName = VarPtr(szClassName)
          wc.hIconSm = LoadIcon(ByVal 0&, ByVal %IDI_APPLICATION)
          RegisterClassEx wc
    
        ' Semen see the use of %WS_EX_TRANSPARENT below
          hWndMain = CreateWindowEx(%WS_EX_TRANSPARENT, szClassName, "GUI Window", %WS_POPUP Or %WS_CLIPCHILDREN, 0, 0, _
             GetSystemMetrics(%SM_CXSCREEN), GetSystemMetrics(%SM_CYSCREEN), _
             0, ByVal %Null, wc.hInstance, ByVal %NULL)
    
          ShowWindow hWndMain, %SW_SHOW
          UpdateWindow hWndMain
    
          szClassName = "W2"
          wc.lpfnWndProc = CodePtr(WndProc2)
          wc.hbrBackground = GetStockObject(%LTGRAY_BRUSH)
          RegisterClassEx wc
    
          hWndChild = CreateWindowEx (0, szClassName, "GUI Window", %WS_OVERLAPPEDWINDOW Or %WS_VISIBLE, 100, 100, _
             200, 200, hWndMain, ByVal %Null, wc.hInstance, ByVal %NULL)
    
          Dim Msg As tagMsg
          While GetMessage(Msg, %NULL, %NULL, %NULL)
             TranslateMessage Msg
             DispatchMessage Msg
          Wend
    
      End Function

    ------------------
    Patrice Terrier
    mailto[email protected][email protected]</A>

    Leave a comment:


  • Semen Matusovski
    replied
    Patrice --
    Nice code, but actually another situation.

    I added some statements to show, what I want.
    Click button outside "GUI window". Should be BEEP (under NT/2000).
    This talks that invisible window is present.
    Try to move "GUI window".

    But there are some problems:
    1) it doesn't work after switching to another app (it's possible to fix)
    2) more important (what I want to avoid) - a lot of operations
    Permanent redrawing of whole screen during moving/sizing of "GUI window".

    Code:
       #Compile Exe
       #Dim All
       #Register None
       #Include "WIN32API.INC"
    
       Global hWndMain As Long, hWndChild As Long
    
       Function WndProc1 (ByVal hWnd As Long, ByVal wMsg As Long, _
          ByVal wParam As Long, ByVal lParam As Long) As Long
          
          Select Case wMsg
             Case %WM_ACTIVATEAPP, %WM_SETTINGCHANGE, %WM_WININICHANGE
                Dim hDC As Long, hMemDC As Static Long, hWndD As Long, bmp As Static BITMAP, hMemBmp As Static Long, hBmpOld As Long
                
                If (wMsg = %WM_ACTIVATEAPP) And (wParam = 0) Then
                Else
                   DeleteObject hMemDC: DeleteObject hMemBmp
                   hWndD = GetDesktopWindow
                   hDC = GetWindowDC(hWndD)
    
                   bmp.bmBitsPixel = GetDeviceCaps(hdc, %BITSPIXEL)
                   bmp.bmPlanes =  GetDeviceCaps(hdc, %PLANES)
                   bmp.bmWidth = GetDeviceCaps(hdc, %HORZRES)
                   bmp.bmHeight = GetDeviceCaps(hdc, %VERTRES)
                   bmp.bmWidthBytes = Fix((bmp.bmWidth + 15) / 16) * 2
    
                   hMemBmp = CreateBitmap(bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, ByVal 0&)
                   hMemDC = CreateCompatibleDC (hDC)
                   hBmpOld = SelectObject (hMemDC, hMemBmp)
                   BitBlt hMemDC, 0, 0, bmp.bmWidth, bmp.bmHeight, hdc, 0, 0, %SRCCOPY
                   ReleaseDC hWndD, hDC
                   
                End If
             Case %WM_LBUTTONDOWN
                Beep
             Case %WM_ERASEBKGND
                BitBlt wParam, 0, 0, bmp.bmWidth, bmp.bmHeight, hMemdc, 0, 0, %SRCCOPY
                Function = 1: Exit Function
             Case %WM_DESTROY
                PostQuitMessage 0
           End Select
          
           Function = DefWindowProc(hWnd, wMsg, wParam, lParam)
       End Function
    
       Function WndProc2 (ByVal hWnd As Long, ByVal wMsg As Long, _
          ByVal wParam As Long, ByVal lParam As Long) As Long
          Select Case wMsg
             Case %WM_DESTROY
                PostQuitMessage 0
          End Select
    
          Function = DefWindowProc(hWnd, wMsg, wParam, lParam)
       End Function
    
       Function PbMain
    
          Local wc As WNDCLASSEX
          Local szClassName As Asciiz * 80
          szClassName = "W1"
          wc.cbSize = SizeOf(wc)
          wc.style = %CS_HREDRAW Or %CS_VREDRAW
          wc.lpfnWndProc = CodePtr(WndProc1)
          wc.cbClsExtra = 0
          wc.cbWndExtra = 0
          wc.hInstance = GetModuleHandle("")
          wc.hIcon = LoadIcon(wc.hInstance, "PROGRAM" )
          wc.hCursor = LoadCursor(ByVal 0&, ByVal %IDC_ARROW )
          wc.hbrBackground = GetStockObject(%NULL_BRUSH)
          wc.lpszMenuName = 0
          wc.lpszClassName = VarPtr(szClassName)
          wc.hIconSm = LoadIcon(ByVal 0&, ByVal %IDI_APPLICATION)
          RegisterClassEx wc
    
          hWndMain = CreateWindowEx(0, szClassName, "GUI Window", %WS_POPUP Or %WS_CLIPCHILDREN, 0, 0, _
             GetSystemMetrics(%SM_CXSCREEN), GetSystemMetrics(%SM_CYSCREEN), _
             0, ByVal %Null, wc.hInstance, ByVal %NULL)
    
          ShowWindow hWndMain, %SW_SHOW
          UpdateWindow hWndMain
    
          szClassName = "W2"
          wc.lpfnWndProc = CodePtr(WndProc2)
          wc.hbrBackground = GetStockObject(%LTGRAY_BRUSH)
          RegisterClassEx wc
    
          hWndChild = CreateWindowEx (0, szClassName, "GUI Window", %WS_OVERLAPPEDWINDOW Or %WS_VISIBLE, 100, 100, _
             200, 200, hWndMain, ByVal %Null, wc.hInstance, ByVal %NULL)
    
          Dim Msg As tagMsg
          While GetMessage(Msg, %NULL, %NULL, %NULL)
             TranslateMessage Msg
             DispatchMessage Msg
          Wend
    
      End Function
    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Scott Turchin
    replied
    I guess I'm confused too but someone here helped me when I had to make my window invisible for a spy program, so here's the window portion of that code:
    I know that you are creative enough to run with this

    Scott


    Code:
    wndclass.cbSize = SizeOf(WndClass)
    wndclass.style = %CS_HREDRAW Or %CS_VREDRAW
    wndclass.lpfnWndProc = CodePtr( WndProc )
    wndclass.cbClsExtra = 0
    wndclass.cbWndExtra = 0
    wndclass.hInstance = hInstance
    wndclass.hIcon = LoadIcon (hInstance, "WINICO")
    wndclass.hCursor = LoadCursor( %NULL, ByVal %IDC_ARROW)
    wndclass.hbrBackground = GetStockObject(%LTGRAY_BRUSH)
    wndclass.lpszMenuName = %NULL
    wndclass.lpszClassName = VarPtr( szClassName )
    wndclass.hIconSm = LoadIcon( hInstance,"WINICO")
    RegisterClassEx wndclass
    
    
    '--------------------------------------------------------------
    '*Get the handle of an existing window and pass this on as the
    ' parent to this window so we can hide our process from showing
    ' up on the task bar
    '--------------------------------------------------------------
    'hdTopWnd& = GetDeskTopWindow()
     hNextWnd = GetTopWindow(0)
     hParent  = GetParent(hNextWnd)
    '--------------------------------------------------------------
    'hParent& = %NULL
    
    hWnd = CreateWindowEx(0,szClassName, _
                          "", _
                          %WS_POPUP Or %WS_DLGFRAME,_
                          %CW_USEDEFAULT, _
                          %CW_USEDEFAULT, _
                          %CW_USEDEFAULT, _
                          %CW_USEDEFAULT, _
                          hParent, _ '<-- assign to a parent window
                          %NULL, _
                          hInstance, _
                          ByVal %NULL)
    
    'ShowWindow hWnd, iCmdShow
    UpdateWindow hWnd
    
    'Remove from Task list
    pid = GetCurrentProcessId()
    RegisterServiceProcess pid, 1
                     
    
    'Do more stuff here then to the message pump:
    
    While GetMessage(Msg, %NULL, 0, 0)
     TranslateMessage Msg
     DispatchMessage Msg
    Wend
    
    Function = Msg.wParam
    CloseHandle hMutex
    End Function  ' WinMain  
    
    
    '
    '
    Function WndProc (ByVal hWnd As Long, _
                      ByVal wMsg As Long, _
                      ByVal wParam As Long, _
                      ByVal lParam As Long) Export As Long    
    
    
    Messages here
    End Function
    ------------------
    Scott

    Leave a comment:


  • Patrice Terrier
    replied
    Semen--

    I don't know if we speak about the same thing.
    Try this:

    Code:
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"
    
    GLOBAL hInst&
    
    FUNCTION WinMain& (BYVAL hInst&, BYVAL hPrevInst&, lpCmdLine AS ASCIIZ PTR, _
                      BYVAL iCmdShow&)
    
        LOCAL Msg         AS tagMsg
        LOCAL zTmp        AS ASCIIZ * 80
    
        Xout& = 200: Yout& = 176
    
        sX& = GetSystemMetrics(%SM_CXSCREEN)
        sY& = GetSystemMetrics(%SM_CYSCREEN)
    
        x& = (sX& - Xout&) \ 2
        y& = (sY& - Yout&) \ 2
    
        LOCAL wc AS WndClassEx
    
        zTmp = "DIABOX"
    
        wc.cbSize        = SIZEOF(wc)
        wc.style         = %CS_HREDRAW OR %CS_VREDRAW
        wc.lpfnWndProc   = CODEPTR(WndProc)
        wc.cbClsExtra    = 0
        wc.cbWndExtra    = 0
        wc.hInstance     = hInst&
        wc.hIcon         = 0
        wc.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
        wc.hbrBackground = %NULL
        wc.lpszMenuName  = %NULL
        wc.lpszClassName = VARPTR(zTmp)
        wc.hIconSm       = 0
        CALL RegisterClassEx(wc)
    
    %SWP_SHOWME = %SWP_FRAMECHANGED Or %SWP_NOMOVE Or %SWP_NOSIZE
    
        Style& = %WS_POPUP OR %WS_VISIBLE
        StyleEx& = %WS_EX_TRANSPARENT
    
        hWnd& = CreateWindowEx(StyleEx&, zTmp, _
                               "", _
                               Style&, _
                               X&, _
                               Y&, _
                               Xout&, _
                               Yout&, _
                               hOwner&, 0, hInst&, BYVAL %NULL)
    
      ' Display the window on the screen
        ShowWindow hWnd&, iCmdShow&
    
        SetWindowPos hwnd&, %HWND_NOTOPMOST, 0&, 0&, 0&, 0&, %SWP_SHOWME
    
        UpdateWindow hWnd&
    
        WHILE GetMessage(Msg, %NULL, 0, 0)
           TranslateMessage Msg
           DispatchMessage Msg
        WEND
    
        FUNCTION = msg.wParam
    
    END FUNCTION
    
    FUNCTION WndProc (BYVAL hWnd AS LONG, BYVAL wMsg AS LONG, _
                      BYVAL wParam AS LONG, BYVAL lParam AS LONG) EXPORT AS LONG
    
    
      ' The SELECT CASE is used to catch only those messages which the message
      ' handler needs to process.  All other messages are passed through the
      ' tests to the default handler.
    
        SELECT CASE wMsg
    
        CASE %WM_CREATE
    
        CASE %WM_ERASEBKGND
             FUNCTION = 1: EXIT FUNCTION
    
        CASE %WM_PAINT
    
             CALL PaintIt(hWnd&)
    
             FUNCTION = 0: EXIT FUNCTION
    
        CASE %WM_DESTROY
    
             PostQuitMessage 0
             FUNCTION = 0: EXIT FUNCTION
    
        CASE %WM_LBUTTONDOWN
    
           ' Allow dragging of the form, even
           ' without a titlebar.
             CALL ReleaseCapture
             CALL SendMessage(hWnd, %WM_NCLBUTTONDOWN, %HTCAPTION, BYVAL %NULL)
             FUNCTION = 0:  EXIT FUNCTION
    
    
        CASE %WM_RBUTTONDOWN
    
           ' Always nice to have a way out :-)
             CALL PostQuitMessage(0)
             FUNCTION = 0: EXIT FUNCTION
    
        END SELECT
    
    
      ' Any message which is not handled in the above SELECT CASE reaches this
      ' point and is process by Windows default message handler.
    
        FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)
    
    END FUNCTION
    
    SUB DrawLine(BYVAL hDC&, BYVAL xStart&, BYVAL yStart&, BYVAL xEnd&, BYVAL yEnd&, BYVAL Size&, BYVAL Color&)
    
        LOCAL lp AS LOGPEN
        LOCAL p AS POINTAPI
    
        p.X = Size&: p.Y = Size&
        lp.lopnStyle = %PS_SOLID
        lp.lopnWidth = p
        lp.lopnColor = Color&
        hPen& = CreatePenIndirect(lp)
        oldPen& = SelectObject(hDC&, hPen&)
    
        CALL MoveToEx(hDC&, xStart&, yStart&, BYVAL %NULL)
        CALL LineTo(hDC&, xEnd&, yEnd&)
    
        IF OldPen& THEN CALL SelectObject(hDC&, OldPen&)
        CALL DeleteObject(hPen&)
    
    END SUB
    
    SUB PaintIt(BYVAL hWnd&)
    
        STATIC C&
    
        LOCAL rc AS RECT
        LOCAL ps AS PAINTSTRUCT
    
        CALL GetClientRect(hWnd&, rc)
        Xin& = rc.nRight - rc.nLeft
        Yin& = rc.nBottom - rc.nTop
        hDC& = GetDC(hWnd&)
    
           CALL SetBkMode(hDC&, %TRANSPARENT)
    
           LineSize& = 12
           B& = LineSize&
           CALL DrawLine(hDC&, 6 + B&, 7, Xin& - 7 - B&, 7, LineSize&, RGB(0,0,255))
           CALL DrawLine(hDC&, Xin& - 6, 7 + B&, xIn& - 6, Yin& - 6 - B&, LineSize&, RGB(0,255,0))
           CALL DrawLine(hDC&, 7 + B&, Yin& - 6, xIn& - 7 -B&, Yin& - 6, LineSize&, RGB(255,255,0))
           CALL DrawLine(hDC&, 6, 7 + B&, 6, Yin& - 6 - B&, LineSize&, RGB(0,255,255))
    
           CALL SetTextColor(hDC&, RGB(255,255,255))
    
           Af$ ="Drag me" + CHR$(13) + "Right click to close."
           rc.nTop = rc.nTop + 67
           CALL DrawText(hDC&, BYVAL STRPTR(Af$), LEN(AF$), rc, %DT_CENTER OR %DT_VCENTER)
    
        CALL ReleaseDC(hWnd&, hDC&)
        SLEEP 10
    END SUB

    ------------------
    Patrice Terrier
    mailto[email protected][email protected]</A>

    Leave a comment:


  • Semen Matusovski
    replied
    Patrice --
    try this. Move the second window over the screen.

    To cancel - Alt-F4.
    Code:
       #Compile Exe
       #Register None
       #Include "WIN32API.INC"
    
       Function WndProc1 (ByVal hWnd As Long, ByVal wMsg As Long, _
          ByVal wParam As Long, ByVal lParam As Long) As Long
          Select Case wMsg
             Case %WM_DESTROY
                PostQuitMessage 0
                Exit Function
          End Select
          Function = DefWindowProc(hWnd, wMsg, wParam, lParam)
       End Function
    
       Function WndProc2 (ByVal hWnd As Long, ByVal wMsg As Long, _
          ByVal wParam As Long, ByVal lParam As Long) As Long
          Function = DefWindowProc(hWnd, wMsg, wParam, lParam)
       End Function
    
       Function PbMain
    
          Local wc As WNDCLASSEX
          Local szClassName As Asciiz * 80
          Local hWndMain As Long
          szClassName = "W1"
          wc.cbSize = SizeOf(wc)
          wc.style = %CS_HREDRAW Or %CS_VREDRAW
          wc.lpfnWndProc = CodePtr(WndProc1)
          wc.cbClsExtra = 0
          wc.cbWndExtra = 0
          wc.hInstance = GetModuleHandle("")
          wc.hIcon = LoadIcon(wc.hInstance, "PROGRAM" )
          wc.hCursor = LoadCursor(ByVal 0&, ByVal %IDC_ARROW )
          wc.hbrBackground = GetStockObject(%NULL_BRUSH)
          wc.lpszMenuName = 0
          wc.lpszClassName = VarPtr(szClassName)
          wc.hIconSm = LoadIcon(ByVal 0&, ByVal %IDI_APPLICATION)
          RegisterClassEx wc
    
          hWndMain = CreateWindowEx(0, szClassName, "GUI Window", %WS_POPUP Or %WS_CLIPCHILDREN, 0, 0, _
             GetSystemMetrics(%SM_CXSCREEN), GetSystemMetrics(%SM_CYSCREEN), _
             0, ByVal %Null, wc.hInstance, ByVal %NULL)
    
          ShowWindow hWndMain, %SW_SHOW
          UpdateWindow hWndMain
          
          szClassName = "W2"
          wc.lpfnWndProc = CodePtr(WndProc2)
          wc.hbrBackground = GetStockObject(%LTGRAY_BRUSH)
          RegisterClassEx wc
          
          CreateWindowEx 0, szClassName, "GUI Window", %WS_OVERLAPPEDWINDOW Or %WS_VISIBLE, 100, 100, _
             200, 200, hWndMain, ByVal %Null, wc.hInstance, ByVal %NULL
    
          Dim Msg As tagMsg
          While GetMessage(Msg, %NULL, %NULL, %NULL)
             TranslateMessage Msg
             DispatchMessage Msg
          Wend
    
    
      End Function
    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Patrice Terrier
    replied
    Semen,

    I do use a CreateWindowEx popup window using a %NULL brush for background
    in such a case.



    ------------------
    Patrice Terrier
    mailto[email protected][email protected]</A>

    Leave a comment:


  • Semen Matusovski
    started a topic Invisible window

    Invisible window

    Guys --
    I want to create "transparent" popup window.
    This means that windows, which covers my window should be visible so, like w/o my window.
    But if user clicks a mouse, for example, this event will come to my window.

    Simple preventing redrawing in WM_ERASEBKGND doesn't help. Exactly it helps on initial step only.
    To invalidate desktop window each time is not interesting.

    Any ideas ?



    ------------------
    E-MAIL: [email protected]
Working...
X