Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Visual Basic 6 - Form trasparente ma oggetti visibili
Forum - Visual Basic 6 - Form trasparente ma oggetti visibili

Avatar
andrex91 (Member)
Pro


Messaggi: 101
Iscritto: 01/05/2009

Segnala al moderatore
Postato alle 0:19
Lunedì, 04/05/2009
Qualcuno saprebbe dirmi il modo per far si che al momento dell'esecuzione il form sia invisibile mentre restino invece visibili i command, textbox e vari oggetti?
Il codice per rendere il form trasparente ce l'ho, pero con esso spariscono anche gli oggetti.
Grazie in anticipo

PM Quote
Avatar
()
Newbie


Messaggi:
Iscritto:

Segnala al moderatore
Postato alle 10:37
Lunedì, 04/05/2009
credo che questo in vb6 non sia fattibile......tu vorresti fare l'effetto messenger.....
ho trovato in giro dei codici che facevano al caso tuo in passato , ora pero' non ricordo piu' dove,  ma la cosa e' talmente complicata che il gioco non vale la candela, e comunque non si puo' fare con tutti i componenti del form, solo con determinati che supportano alcune prorpieta'....

PM Quote
Avatar
Louis (Normal User)
Pro


Messaggi: 150
Iscritto: 22/04/2008

Segnala al moderatore
Postato alle 18:40
Lunedì, 04/05/2009
Ciao,
il seguente codice rende trasparente la Form ma non i controlli. E' testato per i controlli Txt e CmdButton, per gli altri ti devi riferire alle singole proprietà per verificarne la fattibilità:

Codice sorgente - presumibilmente VB.NET

  1. Private Const REG_OR = 2
  2. Private Const REG_MIN = 4
  3. Private Const HWND_TOPMOST = -1
  4. Private Const HWND_NOTOPMOST = -2
  5. Private Const SWP_NOMOVE = &H2
  6. Private Const SWP_NOSIZE = &H1
  7. Private Const TOPMOST_FLAGS = SWP_NOMOVE Or SWP_NOSIZE
  8. Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, _
  9.     ByVal X2 As Long, ByVal Y2 As Long) As Long
  10. Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, _
  11.     ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
  12. Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, _
  13.     ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
  14. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  15. Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _
  16.     ByVal hWndInsertAfter As Long, ByVal x As Long, Y, ByVal cx As Long, _
  17.     ByVal cy As Long, ByVal wFlags As Long) As Long
  18.  
  19. Dim GlassForm As Long
  20. ' ------------------------------------------------------------------------------------
  21. Private Sub Form_Click()
  22. TraspGlass 2
  23. ' TraspGlass 0 x tornare allo stato precedente non-glass
  24. ' TraspGlass 1 ' ...Glass PARZIALE (Resta la caption del form)
  25. ' TraspGlass 2 ' ...Glass TOTALE (restano solo i controlli senza form)
  26. End Sub
  27. ' ------------------------------------------------------------------------------------
  28. Private Sub Form_Initialize()
  29.  
  30. ' Creazione di due controlli per il test di trasparenza form:
  31.  
  32. ' Primo controllo (TextBox)
  33. Dim MyCTRL1 As String
  34. Dim NewTextBox As TextBox
  35. MyCTRL1 = "NewTextBox"
  36. Set NewTextBox = Controls.Add("VB.TextBox", MyCTRL1)
  37. NewTextBox.BorderStyle = 1
  38. NewTextBox.Appearance = 0
  39. NewTextBox.Text = "TEXT BOX nr. 1"
  40. NewTextBox.Left = 120
  41. NewTextBox.Top = 120
  42. NewTextBox.Height = 300
  43. NewTextBox.Width = 2200
  44. NewTextBox.Visible = True
  45.  
  46. ' Secondo controllo (CommandButton)
  47. Dim MyCTRL2 As String
  48. Dim NewCmdButton As CommandButton
  49. MyCTRL2 = "NewCmdButton"
  50. Set NewCmdButton = Controls.Add("VB.CommandButton", MyCTRL2)
  51. NewCmdButton.Height = 300
  52. NewCmdButton.Width = 2200
  53. NewCmdButton.Left = 120
  54. NewCmdButton.Top = 444
  55. NewCmdButton.Caption = "CMD DI PROVA"
  56. NewCmdButton.Visible = True
  57.  
  58. Me.Height = 1890
  59. Me.Width = 6000
  60. ' Non modificare!!!
  61. Me.ScaleMode = vbPixels
  62. Me.Caption = "Un click con il tasto del mouse su questo form..."
  63.  
  64. End Sub
  65. ' ------------------------------------------------------------------------------------
  66. Private Sub TraspGlass(GlassFX As Integer)
  67.  
  68.     Dim w As Single, h As Single, Contorno As Single, topEye As Single
  69.     Dim i As Long, k As Long, n As Long, q As Long
  70.     Dim PosTop As Double, PosLeft As Double
  71.    
  72.     ' Conversione su assi X/Y | width/height | scalewidth/scaleheight
  73.     w = ScaleX(Width, vbTwips, vbPixels)
  74.     h = ScaleY(Height, vbTwips, vbPixels)
  75.    
  76.     ' Verifica lo stato...
  77.     If GlassFX = 0 Then
  78.         GlassForm = CreateRectRgn(0, 0, w, h)
  79.         SetWindowRgn hwnd, GlassForm, True
  80.         Exit Sub
  81.     End If
  82.    
  83.     GlassForm = CreateRectRgn(0, 0, 0, 0)
  84.     Contorno = (w - ScaleWidth) / 2
  85.     topEye = h - Contorno - ScaleHeight
  86.    
  87.     If GlassFX = 1 Then
  88.         k = CreateRectRgn(0, 0, w, h)
  89.         n = CreateRectRgn(Contorno, topEye, w - Contorno, h - Contorno)
  90.         CombineRgn GlassForm, k, n, REG_MIN
  91.     End If
  92.    
  93.     ' Traspone la nuova regione sul form...
  94.     For i = 0 To Me.Controls.Count - 1
  95.         If Me.Controls(i).Visible = True Then
  96.             PosLeft = ScaleX(Me.Controls(i).Left, Me.ScaleMode, vbPixels) + Contorno
  97.             PosTop = ScaleX(Me.Controls(i).Top, Me.ScaleMode, vbPixels) + topEye
  98.             q = CreateRectRgn(PosLeft, PosTop, _
  99.             PosLeft + ScaleX(Me.Controls(i).Width, Me.ScaleMode, vbPixels), PosTop + ScaleY(Me.Controls(i).Height, Me.ScaleMode, vbPixels))
  100.             CombineRgn GlassForm, q, GlassForm, REG_OR
  101.         End If
  102.     Next
  103.    
  104.     ' Esegue...
  105.     SetWindowRgn hwnd, GlassForm, True
  106.  
  107. End Sub
  108. ' ------------------------------------------------------------------------------------
  109. Private Sub Form_Load()
  110.     ' Centra il form
  111.     CentraForm Form1
  112.     ' On Top
  113.     MakeTopMost Me.hwnd
  114. End Sub
  115. ' ------------------------------------------------------------------------------------
  116. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  117.     ' Scarca l'oggetto GlassForm dalla memoria.
  118.     SetWindowRgn hwnd, 0, False
  119.     DeleteObject GlassForm
  120.     ' Scarica il form dalla memoria
  121.     Unload Form1
  122.     Set Form1 = Nothing
  123. End Sub
  124. ' ------------------------------------------------------------------------------------
  125. Public Sub CentraForm(MyForm As Form)
  126.     ' Centra il form
  127.     MyForm.Top = (Screen.Height - MyForm.Height) / 2
  128.     MyForm.Left = (Screen.Width - MyForm.Width) / 2
  129. End Sub
  130. ' ------------------------------------------------------------------------------------
  131. Sub MakeNormal(Handle As Long)
  132.     SetWindowPos Handle, HWND_NOTOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
  133. End Sub
  134. ' ------------------------------------------------------------------------------------
  135. Sub MakeTopMost(Handle As Long)
  136.     SetWindowPos Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
  137. End Sub


:k:

PM Quote