Results 1 to 3 of 3

Thread: Virtual light box. Almost.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2012
    Posts
    129

    Virtual light box. Almost.

    Hi folks.

    I have a need to write a kind of virtual light box, but in reverse. The need arises because of some drawing software I have that doesn't support layers very well and I need to trace outline drawings on a Wacom tablet.

    With a light box you place your picture underneath your media and draw on a clean sheet of paper on top, much the same as having an underlying layer in a graphics program. However I kind of need the opposite. Because this software 'I Need to use' doesn't handle layers well I need an overlay program that will display a graphic with adjustable opacity, that the mouse or stylus can draw through onto the application underneath.

    I've been a VB person for decades and have some limited graphical ability, but I wouldn't know where to start with this, or even if it's possible at all. Anyone have any ideas?

    Please don't say - use a better drawing app, this isn't an option.

    Thanks.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,370

    Re: Virtual light box. Almost.

    Can you save a copy of the original Image, draw onto the copy of the Image, and then save the Image back? This would only work if your drawing application allows you to save and open images.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  3. #3
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Virtual light box. Almost.

    Quote Originally Posted by tclancey View Post
    I need an overlay program that will display a graphic with adjustable opacity, that the mouse or stylus can draw through onto the application underneath.
    Quick idea, toggle the WS_EX_TRANSPARENT window flag, it should let you click thru the form and also set the opacity.,

    Note, Testing on Win7, Click-thru only works when form opacity is < 1.0D.

    vb.net Code:
    1. Imports System.Runtime.InteropServices
    2.  
    3. Public Class Form1
    4.  
    5.     Private Const hotKey_ClickThruToggle As Integer = 100 ' Our hot key ID
    6.  
    7.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    8.         ' mouse-click-thru is off by default.
    9.         Me.Text = "Click-Thru Off"
    10.  
    11.         ' register a hot key (Control+Q) to toggle mouse-click-thru option.
    12.         If Not RegisterHotKey(Me.Handle, hotKey_ClickThruToggle, fsModifier.CONTROL Or fsModifier.NOREPEAT, CUInt(Keys.Q)) Then
    13.             MessageBox.Show("RegisterHotKey 'Control+Q' failed!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
    14.         End If
    15.  
    16.         ' set default opacity to 0%, opacity can be set using a trackbar.
    17.         Me.Opacity = 1D
    18.         TrackBar1.Minimum = 0
    19.         TrackBar1.Maximum = 8 ' Limit opacity to 80%.
    20.  
    21.         ' load an image.
    22.         Me.BackgroundImageLayout = ImageLayout.None
    23.         Me.BackgroundImage = New Bitmap("m:\Windows_Vista_Logo.jpg")
    24.     End Sub
    25.  
    26.     Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    27.         ' UnRegister our hot key
    28.         UnregisterHotKey(Me.Handle, hotKey_ClickThruToggle)
    29.     End Sub
    30.  
    31.     ' Window messages
    32.     Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    33.         Static clickThruOn As Boolean
    34.         If m.Msg = WM_HOTKEY Then
    35.             If m.WParam.ToInt32 = hotKey_ClickThruToggle Then  ' Control+Q detected.
    36.                 If Not clickThruOn Then ' set click-thru on.
    37.                     clickThruOn = True
    38.                     SetWindowLong(Me.Handle, GWL_EXSTYLE, GetWindowLong(Me.Handle, GWL_EXSTYLE) Or WS_EX_TRANSPARENT)
    39.                     Me.TopMost = True
    40.                     Me.Text = "Click-Thru On"
    41.                 Else ' disable click thru
    42.                     clickThruOn = False
    43.                     SetWindowLong(Me.Handle, GWL_EXSTYLE, GetWindowLong(Me.Handle, GWL_EXSTYLE) And Not WS_EX_TRANSPARENT)
    44.                     Me.Text = "Click-Thru Off"
    45.                 End If
    46.             End If
    47.         End If
    48.         ' proc all msgs.
    49.         MyBase.WndProc(m)
    50.     End Sub
    51.  
    52.     Private Sub TrackBar1_Scroll(sender As System.Object, e As System.EventArgs) Handles TrackBar1.Scroll
    53.         ' set form opacity
    54.         Me.Opacity = 1D - (TrackBar1.Value / 10)
    55.     End Sub
    56.  
    57. #Region "API"
    58.     Private Const WM_HOTKEY As Int32 = &H312
    59.     Private Enum fsModifier As UInt32
    60.         NONE = &H0
    61.         ALT = &H1
    62.         CONTROL = &H2
    63.         SHIFT = &H4
    64.         WIN = &H8
    65.         NOREPEAT = &H4000
    66.     End Enum
    67.     <DllImport("User32.dll")> _
    68.     Private Shared Function RegisterHotKey(ByVal hwnd As IntPtr, ByVal id As Int32, ByVal fsModifiers As UInt32, ByVal vk As UInt32) As Boolean
    69.     End Function
    70.     <DllImport("User32.dll")> _
    71.     Private Shared Function UnregisterHotKey(ByVal hwnd As IntPtr, ByVal id As Int32) As Boolean
    72.     End Function
    73.  
    74.     Private Const GWL_EXSTYLE As Integer = (-20)
    75.     Private Const WS_EX_TRANSPARENT As Integer = &H20
    76.     Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
    77.     Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As IntPtr, ByVal nIndex As Integer) As Integer
    78. #End Region
    79.  
    80. End Class
    Last edited by Edgemeal; Aug 19th, 2016 at 12:38 PM. Reason: Add note.

Tags for this Thread

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