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 - Tray Icon con icona personalizzata
Forum - Visual Basic 6 - Tray Icon con icona personalizzata - Pagina 4

Pagine: [ 1 2 3 4 5 ] Precedente | Prossimo
Avatar
super rambo (Normal User)
Pro


Messaggi: 135
Iscritto: 04/06/2008

Segnala al moderatore
Postato alle 19:34
Giovedì, 04/09/2008
ragazzi a me non funziona, le dichiarazioni vanno in un modulo o nel form?? io ho messole dichiarazioni e la windows procedure in un modulo e il resto del codice nel form e mi da un errore qui:
Codice sorgente - presumibilmente VB.NET

  1. Private Sub Form_Load()
  2. AddButton Me, True, Me.fakebutton
  3. .hWnd , "Show Description", 100, False
  4. End Sub


mi dice argument non optional.. Grazie!!

PM Quote
Avatar
GrG (Member)
Guru^2


Messaggi: 3430
Iscritto: 21/08/2007

Segnala al moderatore
Postato alle 20:03
Giovedì, 04/09/2008
LoL
già mi ero dimenticato di sto post...ora rileggerlo tutto riga per riga in questo momento non mi va molto....avevo allegato ad uno dei miei post il progetto fià fatto.

PM Quote
Avatar
super rambo (Normal User)
Pro


Messaggi: 135
Iscritto: 04/06/2008

Segnala al moderatore
Postato alle 20:04
Giovedì, 04/09/2008
si, lo ho scaricato ma è un pò diverso e più complesso... cmq c'è un utente che dice che funziona. io voglio solamente sapere se mettere tutti quei codici in un modulo e o nel form... Grazie!!

PM Quote
Avatar
GrG (Member)
Guru^2


Messaggi: 3430
Iscritto: 21/08/2007

Segnala al moderatore
Postato alle 22:20
Giovedì, 04/09/2008
Si, devi mettere tutto in un modulo tranne:

Codice sorgente - presumibilmente Visual Basic 6

  1. 'il pulsante fittizzio: name= fakebutton
  2. AddButton Me, True, Me.fakebutton
  3. .hWnd, "Show Description", 100, False



che devi mettere nel fakebutton

PM Quote
Avatar
super rambo (Normal User)
Pro


Messaggi: 135
Iscritto: 04/06/2008

Segnala al moderatore
Postato alle 22:23
Giovedì, 04/09/2008
ma scusa questo codice non va nella form load e poi nel fake button metto il codice per minimizzare in trayicon??
EDIT:
Ho messo questo codice nella form_load():
Codice sorgente - presumibilmente Visual Basic 6

  1. 'il pulsante fittizzio: name= fakebutton
  2. AddButton Me, True, Me.fakebutton
  3. .hWnd, "Show Description", 100, False


e tutto il resto in un modulo ma l'errore è sempre lo stesso...

Ultima modifica effettuata da super rambo il 04/09/2008 alle 22:31
PM Quote
Avatar
GrG (Member)
Guru^2


Messaggi: 3430
Iscritto: 21/08/2007

Segnala al moderatore
Postato alle 23:21
Giovedì, 04/09/2008
Si scusa nella form_load devi mettere il codice...
Non va perchè non c'è l'accapo è una sola riga:

il pulsante fittizzio: name= fakebutton
AddButton Me, True, Me.fakebutton.hWnd, "Show Description", 100, False

PM Quote
Avatar
super rambo (Normal User)
Pro


Messaggi: 135
Iscritto: 04/06/2008

Segnala al moderatore
Postato alle 12:25
Venerdì, 05/09/2008
ragà scusate se rompo ancora ma non riesco a far funzionare il codice.. ve lo posto:
modulo1:
Codice sorgente - presumibilmente Delphi

  1. 'constants required by Shell_NotifyIcon API call:
  2.      Public Const NIM_ADD = &H0
  3.      Public Const NIM_MODIFY = &H1
  4.      Public Const NIM_DELETE = &H2
  5.      Public Const NIF_MESSAGE = &H1
  6.      Public Const NIF_ICON = &H2
  7.      Public Const NIF_TIP = &H4
  8.      Public Const WM_MOUSEMOVE = &H200
  9.      Public Const WM_LBUTTONDOWN = &H201     'Button down
  10.       Public Const WM_LBUTTONUP = &H202       'Button up
  11.      Public Const WM_LBUTTONDBLCLK = &H203   'Double-click
  12.       Public Const WM_RBUTTONDOWN = &H204     'Button down
  13.      Public Const WM_RBUTTONUP = &H205       'Button up
  14.       Public Const WM_RBUTTONDBLCLK = &H206   'Double-click
  15.  
  16.      Public Declare Function SetForegroundWindow Lib "user32" _
  17.      (ByVal hWnd As Long) As Long
  18.      Public Declare Function Shell_NotifyIcon Lib "shell32" _
  19.      Alias "Shell_NotifyIconA" _
  20.      (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
  21.  
  22.      Public nid As NOTIFYICONDATA



modulo2:
Codice sorgente - presumibilmente VB.NET

  1. ' ************************************************************************
  2. ' Developer:  Robert E. Phelps
  3. ' Feel free To use this code As you wish, but please give credit To the
  4. ' author.  Do Not sell this code; If you Do, I want a piece of it :) !!!
  5. ' ************************************************************************
  6.  
  7.  
  8. Public Const HWND_PROP_lpPrevWndProc = "lpPrevWndProc"
  9. Public Const HWND_PROP_hWndMainForm = "hWndMainForm"
  10. Public Const HWND_PROP_hWndTitleBarButton = "hWndTitleBarButton"
  11. Public Const HWND_PROP_hWndTitleBarFakeButton = "hWndTitleBarFakeButton"
  12. Public Const HWND_PROP_TitleBarButtonWidth = "TitleBarButtonWidth"
  13.  
  14. ' Rectangle coordinates
  15. Public Type RECT
  16.    Left As Long
  17.    Top As Long
  18.    Right As Long
  19.    Bottom As Long
  20. End Type
  21.  
  22. ' Windows messages
  23. Public Const WM_SIZE = &H5
  24. Public Const WM_LBUTTONUP = &H202           ' Used For command button
  25. Public Const WM_WINDOWPOSCHANGED = &H47
  26. Public Const WM_SETFONT = &H30
  27.  
  28. ' Button messages
  29. Public Const BM_SETCHECK = &HF1             ' Used For toggle button
  30. Public Const BM_CLICK = &HF5                ' Used For command button
  31.  
  32. ' GetWindowLong
  33. Public Const GWL_STYLE = (-16)
  34. Public Const GWL_EXSTYLE = (-20)
  35.  
  36. ' Window styles
  37. Public Const WS_CAPTION = &HC00000
  38. Public Const WS_CHILD = &H40000000
  39. Public Const WS_EX_TOOLWINDOW = &H80
  40. Public Const WS_THICKFRAME = &H40000
  41. Public Const WS_MAXIMIZEBOX = &H10000
  42. Public Const WS_MINIMIZEBOX = &H20000
  43.  
  44. ' Button styles
  45. Public Const BS_PUSHBUTTON = &H0&           ' Used For command button
  46. Public Const BS_AUTOCHECKBOX = &H3&         ' Used For toggle button
  47. Public Const BS_PUSHLIKE = &H1000           ' Used For toggle button
  48.  
  49. ' WindProc
  50. Public Const GWL_WNDPROC As Long = -4&
  51.  
  52. ' SetWindowPos
  53. Public Const SWP_FRAMECHANGED = &H20
  54. Public Const SWP_NOACTIVATE = &H10
  55.  
  56. ' ShowWindow
  57. Public Const SW_SHOWNOACTIVATE = 4
  58.  
  59. ' SystemMetrics
  60. Public Const SM_CXFIXEDFRAME = 7
  61. Public Const SM_CXSIZEFRAME = 32
  62. Public Const SM_CXSIZE = 30
  63. Public Const SM_CXSMSIZE = 52
  64. Public Const SM_CYCAPTION = 4
  65. Public Const SM_CYSMCAPTION = 51
  66.  
  67. ' Window position
  68. Public Type WINDOWPOS
  69.         hWnd As Long
  70.         hWndInsertAfter As Long
  71.         X As Long
  72.         Y As Long
  73.         cx As Long
  74.         cy As Long
  75.         flags As Long
  76. End Type
  77.  
  78. ' Logical font
  79. Public Const LF_FACESIZE = 32
  80. Public Type LOGFONT
  81.     lfHeight As Long
  82.     lfWidth As Long
  83.     lfEscapement As Long
  84.     lfOrientation As Long
  85.     lfWeight As Long
  86.     lfItalic As Byte
  87.     lfUnderline As Byte
  88.     lfStrikeOut As Byte
  89.     lfCharSet As Byte
  90.     lfOutPrecision As Byte
  91.     lfClipPrecision As Byte
  92.     lfQuality As Byte
  93.     lfPitchAndFamily As Byte
  94.     lfFaceName(1 To LF_FACESIZE) As Byte
  95. End Type
  96.  
  97. ' SystemParametersInfo
  98. Public Const SPI_GETNONCLIENTMETRICS = 41
  99. Public Type NONCLIENTMETRICS
  100.     cbSize As Long
  101.     iBorderWidth As Long
  102.     iScrollWidth As Long
  103.     iScrollHeight As Long
  104.     iCaptionWidth As Long
  105.     iCaptionHeight As Long
  106.     lfCaptionFont As LOGFONT
  107.     iSMCaptionWidth As Long
  108.     iSMCaptionHeight As Long
  109.     lfSMCaptionFont As LOGFONT
  110.     iMenuWidth As Long
  111.     iMenuHeight As Long
  112.     lfMenuFont As LOGFONT
  113.     lfStatusFont As LOGFONT
  114.     lfMessageFont As LOGFONT
  115. End Type
  116.  
  117. ' API declarations
  118. Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
  119. Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  120. Public Declare Function CreateFontIndirect Lib "gdi32" Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long
  121. Public Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
  122. Public Declare Function DestroyWindow Lib "user32" (ByVal hWnd As Long) As Long
  123. Public Declare Function GetFocus Lib "user32" () As Long
  124. Public Declare Function GetProp Lib "user32" Alias "GetPropA" (ByVal hWnd As Long, ByVal lpString As String) As Long
  125. Public Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
  126. Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
  127. Public Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
  128. Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  129. Public Declare Function RemoveProp Lib "user32" Alias "RemovePropA" (ByVal hWnd As Long, ByVal lpString As String) As Long
  130. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  131. Public Declare Function SetFocus Lib "user32" (ByVal hWnd As Long) As Long
  132. Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
  133. Public Declare Function SetProp Lib "user32" Alias "SetPropA" (ByVal hWnd As Long, ByVal lpString As String, ByVal hData As Long) As Long
  134. Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal wNewWord As Long) As Long
  135. Public Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
  136. Public Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
  137. Public Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) As Long
  138.  
  139. Public Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, _
  140.                            ByVal wParam As Long, ByVal lParam As Long) As Long
  141.  
  142.     Dim udtRECT As RECT
  143.     Dim udtWPOS As WINDOWPOS
  144.     Dim X As Long
  145.     Dim Y As Long
  146.     Dim lCapBtnWid As Long
  147.     Dim lBrdWid As Long
  148.     Dim lBtnTop As Long
  149.     Dim lBtnLeft As Long
  150.     Dim lBtnWidth As Long
  151.     Dim lBtnHeight As Long
  152.  
  153.     Dim hWndMain As Long
  154.     Dim hWndButton As Long
  155.     Dim hWndFakeButton As Long
  156.     Dim lpWndProc As Long
  157.  
  158.  
  159.     lpWndProc = GetProp(hWnd, HWND_PROP_lpPrevWndProc)
  160.     hWndMain = GetProp(hWnd, HWND_PROP_hWndMainForm)
  161.     hWndButton = GetProp(hWnd, HWND_PROP_hWndTitleBarButton)
  162.  
  163.     Select Case hWnd
  164.     Case hWndButton
  165.         WindowProc = CallWindowProc(lpWndProc, hWnd, uMsg, wParam, lParam)
  166.         Select Case uMsg
  167.         Case WM_LBUTTONUP
  168.             If BS_AUTOCHECKBOX <> (GetWindowLong(hWnd, GWL_STYLE) And BS_AUTOCHECKBOX) Then
  169.                 ' Command button
  170.                 GetHILOWORD lParam, X, Y
  171.                 Call GetWindowRect(hWndButton, udtRECT)
  172.                 If X >= 0 And X <= udtRECT.Right - udtRECT.Left And _
  173.                    Y >= 0 And Y <= udtRECT.Bottom - udtRECT.Top Then
  174.                     ' Get the handle To control On form that currently has the focus
  175.                     Call SetFocus(hWndMain)
  176.                     hWndButton = GetFocus()
  177.  
  178.                     ' Send click message To fake button On form
  179.                     hWndFakeButton = GetProp(hWnd, HWND_PROP_hWndTitleBarFakeButton)
  180.                     Call SendMessage(hWndFakeButton, BM_CLICK, 0, 0)
  181.  
  182.                     ' Return focus To control On form that had the focus originally
  183.                     Call SetFocus(hWndButton)
  184.                 End If
  185.             End If
  186.         Case BM_SETCHECK
  187.             ' Toggle button
  188.             hWndFakeButton = GetProp(hWnd, HWND_PROP_hWndTitleBarFakeButton)
  189.             Call SendMessage(hWndFakeButton, BM_SETCHECK, wParam, 0)
  190.             Call SetFocus(hWndMain)
  191.         End Select
  192.     Case hWndMain
  193.         Select Case uMsg
  194.         Case WM_WINDOWPOSCHANGED, WM_SIZE
  195.             If uMsg = WM_WINDOWPOSCHANGED Then
  196.                 ' Get Main form RECT from WINDOWPOS passed In lParam
  197.                 CopyMemory udtWPOS, ByVal lParam, Len(udtWPOS)
  198.                 udtRECT.Left = udtWPOS.X
  199.                 udtRECT.Right = udtWPOS.X + udtWPOS.cx
  200.                 udtRECT.Top = udtWPOS.Y
  201.                 udtRECT.Bottom = udtWPOS.Y + udtWPOS.cy
  202.             Else
  203.                 ' WM_SIZE, so Get Main form RECT
  204.                 Call GetWindowRect(hWndMain, udtRECT)
  205.             End If
  206.             If WS_EX_TOOLWINDOW <> (GetWindowLong(hWnd, GWL_EXSTYLE) And WS_EX_TOOLWINDOW) Then
  207.                 If WS_THICKFRAME <> (GetWindowLong(hWnd, GWL_STYLE) And WS_THICKFRAME) Then
  208.                     ' Fixed-Single And Fixed-Dialog
  209.                     lBrdWid = GetSystemMetrics(SM_CXFIXEDFRAME)
  210.                     lCapBtnWid = GetSystemMetrics(SM_CXSIZE)
  211.                     lBtnHeight = GetSystemMetrics(SM_CYCAPTION) - 5
  212.                 Else
  213.                     ' Sizable
  214.                     lBrdWid = GetSystemMetrics(SM_CXSIZEFRAME)
  215.                     lCapBtnWid = GetSystemMetrics(SM_CXSIZE)
  216.                     lBtnHeight = GetSystemMetrics(SM_CYCAPTION) - 5
  217.                 End If
  218.             Else
  219.                 If WS_THICKFRAME <> (GetWindowLong(hWnd, GWL_STYLE) And WS_THICKFRAME) Then
  220.                     ' Fixed ToolWindow
  221.                     lBrdWid = GetSystemMetrics(SM_CXFIXEDFRAME)
  222.                     lCapBtnWid = GetSystemMetrics(SM_CXSMSIZE)
  223.                     lBtnHeight = GetSystemMetrics(SM_CYSMCAPTION) - 5
  224.                 Else
  225.                     ' Sizable ToolWindow
  226.                     lBrdWid = GetSystemMetrics(SM_CXSIZEFRAME)
  227.                     lCapBtnWid = GetSystemMetrics(SM_CXSMSIZE)
  228.                     lBtnHeight = GetSystemMetrics(SM_CYSMCAPTION) - 5
  229.                 End If
  230.             End If
  231.  
  232.             ' Button pos
  233.             lBtnTop = udtRECT.Top + lBrdWid + 2
  234.             lBtnWidth = GetProp(hWndButton, HWND_PROP_TitleBarButtonWidth)
  235.             If lBtnWidth = 0 Then
  236.                 ' Use default caption button width
  237.                 lBtnWidth = lCapBtnWid - 2
  238.             End If
  239.             If (WS_MINIMIZEBOX = (GetWindowLong(hWnd, GWL_STYLE) And WS_MINIMIZEBOX) Or _
  240.                WS_MAXIMIZEBOX = (GetWindowLong(hWnd, GWL_STYLE) And WS_MAXIMIZEBOX)) And _
  241.                WS_EX_TOOLWINDOW <> (GetWindowLong(hWnd, GWL_EXSTYLE) And WS_EX_TOOLWINDOW) Then
  242.                 ' Calculate left pos of Min button
  243.                 lBtnLeft = udtRECT.Right - lBrdWid - lCapBtnWid - lCapBtnWid - lCapBtnWid + 2
  244.                 ' Calculate left pos of Titlebar button
  245.                 lBtnLeft = lBtnLeft - lBtnWidth - 2
  246.             Else
  247.                 ' Calculate left pos of X button
  248.                 lBtnLeft = udtRECT.Right - lBrdWid - lCapBtnWid
  249.                 ' Calculate left pos of Titlebar button
  250.                 lBtnLeft = lBtnLeft - lBtnWidth - 2
  251.             End If
  252.  
  253.             ' Position the button over the Titlebar of the form; remember, no parent (0)
  254.             Call SetWindowPos(hWndButton, 0, lBtnLeft, lBtnTop, lBtnWidth, lBtnHeight, SWP_FRAMECHANGED + SWP_NOACTIVATE)
  255.         End Select
  256.         WindowProc = CallWindowProc(lpWndProc, hWnd, uMsg, wParam, lParam)
  257.     End Select
  258.  
  259. End Function
  260.  
  261. Public Sub GetHILOWORD(lParam As Long, LOWORD As Long, HIWORD As Long)
  262.  
  263.     ' LOWORD of the lParam
  264.     LOWORD = lParam And &HFFFF&
  265.     ' LOWORD now equals 65,535 Or &HFFFF
  266.  
  267.     ' HIWORD of the lParam
  268.     HIWORD = lParam \ &H10000 And &HFFFF&
  269.     ' HIWORD now equals 30,583 Or &H7777
  270.  
  271. End Sub



class1:
Codice sorgente - presumibilmente VB.NET

  1. ' ************************************************************************
  2. ' Developer:  Robert E. Phelps
  3. ' Feel free To use this code As you wish, but please give credit To the
  4. ' author.  Do Not sell this code; If you Do, I want a piece of it :) !!!
  5. ' ************************************************************************
  6.  
  7.  
  8. Private hWndButton As Long
  9. Private hWndMain As Long
  10.  
  11. Public Sub AddButton(ByRef frm As Form, ByVal bToggleButton As Boolean, _
  12.                      ByVal hWndFakeButton As Long, ByVal sText As String, _
  13.                      ByVal lWidthInPixels As Long, ByVal bCaptionButtonStyle As Boolean)
  14.  
  15.     Dim udtNCM As NONCLIENTMETRICS
  16.     Dim udtLogFontCap As LOGFONT
  17.     Dim hFont As Long
  18.     Dim hWndParent As Long
  19.     Dim lpWndProc As Long
  20.  
  21.  
  22.     ' Validation
  23.     If frm.BorderStyle = 0 Then Exit Sub
  24.     If hWndFakeButton = 0 Then Exit Sub
  25.     If bCaptionButtonStyle Then
  26.         ' Use default caption button width
  27.         lWidthInPixels = 0
  28.     Else
  29.         If lWidthInPixels <= 0 Then Exit Sub
  30.     End If
  31.  
  32.     ' The button will be a free-floating window that has no parent (0)
  33.     hWndMain = frm.hWnd
  34.     hWndParent = 0
  35.  
  36.     ' Create button, remove window border, And Set parent To none
  37.     If Not bToggleButton Then
  38.         ' Command button
  39.         hWndButton = CreateWindowEx(0, "Button", sText, BS_PUSHBUTTON, 20, 20, 20, 20, hWndMain, 0, App.hInstance, 0)
  40.     Else
  41.         ' Toggle button
  42.         hWndButton = CreateWindowEx(0, "Button", sText, BS_PUSHLIKE + BS_AUTOCHECKBOX, 20, 20, 20, 20, hWndMain, 0, App.hInstance, 0)
  43.     End If
  44.     Call SetWindowLong(hWndButton, GWL_STYLE, GetWindowLong(hWndButton, GWL_STYLE) - WS_CAPTION)
  45.     Call SetParent(hWndButton, hWndParent)
  46.  
  47.     ' Get Non-Client Metrics
  48.     udtNCM.cbSize = Len(udtNCM)
  49.     Call SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, udtNCM, 0)
  50.  
  51.     ' Select caption font For BorderStyle
  52.     Select Case frm.BorderStyle
  53.         Case 1, 2, 3: udtLogFontCap = udtNCM.lfCaptionFont
  54.         Case 4, 5: udtLogFontCap = udtNCM.lfSMCaptionFont
  55.     End Select
  56.  
  57.     ' Use absolute value For font height
  58.     udtLogFontCap.lfHeight = Abs(udtLogFontCap.lfHeight)
  59.     If WS_EX_TOOLWINDOW = (GetWindowLong(hWndMain, GWL_EXSTYLE) And WS_EX_TOOLWINDOW) Then
  60.         ' Reduce font size For ToolWindow
  61.         udtLogFontCap.lfHeight = udtLogFontCap.lfHeight - 1
  62.     End If
  63.  
  64.     ' Get handle To retrieved caption font And Set font To button
  65.     hFont = CreateFontIndirect(udtLogFontCap)
  66.     Call SendMessage(hWndButton, WM_SETFONT, hFont, ByVal True)
  67.  
  68.     ' Sub-class Main form And Set window properties For callback Function
  69.     lpWndProc = SetWindowLong(hWndMain, GWL_WNDPROC, AddressOf WindowProc)
  70.     Call SetProp(hWndMain, HWND_PROP_lpPrevWndProc, lpWndProc)
  71.     Call SetProp(hWndMain, HWND_PROP_hWndMainForm, hWndMain)
  72.     Call SetProp(hWndMain, HWND_PROP_hWndTitleBarButton, hWndButton)
  73.  
  74.     ' Sub-class Titlebar button And Set window properties For callback Function
  75.     lpWndProc = SetWindowLong(hWndButton, GWL_WNDPROC, AddressOf WindowProc)
  76.     Call SetProp(hWndButton, HWND_PROP_lpPrevWndProc, lpWndProc)
  77.     Call SetProp(hWndButton, HWND_PROP_hWndMainForm, hWndMain)
  78.     Call SetProp(hWndButton, HWND_PROP_hWndTitleBarButton, hWndButton)
  79.     Call SetProp(hWndButton, HWND_PROP_TitleBarButtonWidth, lWidthInPixels)
  80.     Call SetProp(hWndButton, HWND_PROP_hWndTitleBarFakeButton, hWndFakeButton)
  81.  
  82.     ' Set the Fake TitleBar toggle button To Unchecked by default
  83.     If bToggleButton Then Call SendMessage(hWndFakeButton, BM_SETCHECK, 0, 0)
  84.  
  85.     ' Set button pos before showing, must be called twice
  86.     Call PostMessage(hWndMain, WM_SIZE, 0, 0)
  87.     Call PostMessage(hWndMain, WM_SIZE, 0, 0)
  88.     Call ShowWindow(hWndButton, SW_SHOWNOACTIVATE)
  89.  
  90.     ' Return focus To Main form
  91.     Call SetFocus(hWndMain)
  92. End Sub


form1:
Codice sorgente - presumibilmente VB.NET

  1. Private Sub fakebutton_Click()
  2. 'the form must be fully visible before calling Shell_NotifyIcon
  3.        Me.Show
  4.        Me.Refresh
  5.        With nid
  6.         .cbSize = Len(nid)
  7.         .hWnd = Me.hWnd
  8.         .uId = vbNull
  9.         .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
  10.         .uCallBackMessage = WM_MOUSEMOVE
  11.         .hIcon = Me.Icon
  12.         .szTip = "Your ToolTip" & vbNullChar
  13.        End With
  14.        Shell_NotifyIcon NIM_ADD, nid
  15. Me.Hide
  16. End Sub
  17.  
  18. Private Sub Form_Load()
  19. Class1.AddButton Me, True, Form1.fakebutton.hWnd, ".", 100, False
  20. End Sub
  21.  
  22.      Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  23.       'this procedure receives the callbacks from the System Tray icon.
  24.       Dim Result As Long
  25.       Dim msg As Long
  26.        'the value of X will vary depending upon the scalemode setting
  27.        If Me.ScaleMode = vbPixels Then
  28.         msg = X
  29.        Else
  30.         msg = X / Screen.TwipsPerPixelX
  31.        End If
  32.        Select Case msg
  33.         Case Module1.WM_LBUTTONUP        '514 restore form window
  34.          Me.WindowState = vbNormal
  35.          Result = SetForegroundWindow(Me.hWnd)
  36.          Me.Show
  37.         Case WM_LBUTTONDBLCLK    '515 restore form window
  38.          Me.WindowState = vbNormal
  39.          Result = SetForegroundWindow(Me.hWnd)
  40.          Me.Show
  41.         Case WM_RBUTTONUP        '517 display popup menu
  42.          Result = SetForegroundWindow(Me.hWnd)
  43.          Me.PopupMenu Me.mPopupSys
  44.        End Select
  45.       End Sub
  46.  
  47.       Private Sub Form_Resize()
  48.        'this is necessary to assure that the minimized window is hidden
  49.        If Me.WindowState = vbMinimized Then Me.Hide
  50.       End Sub
  51.  
  52.       Private Sub Form_Unload(Cancel As Integer)
  53.        'this removes the icon from the system tray
  54.        Shell_NotifyIcon NIM_DELETE, nid
  55.       End Sub
  56.  
  57.       Private Sub mPopExit_Click()
  58.        'called when user clicks the popup menu Exit command
  59.        Unload Me
  60.       End Sub
  61.  
  62.       Private Sub mPopRestore_Click()
  63.        'called when the user clicks the popup menu Restore command
  64.        Me.WindowState = vbNormal
  65.        Result = SetForegroundWindow(Me.hWnd)
  66.        Me.Show
  67.       End Sub


L'errore che mi da appena faccio partire il programma è object required... Grazie!!

PM Quote
Avatar
GrG (Member)
Guru^2


Messaggi: 3430
Iscritto: 21/08/2007

Segnala al moderatore
Postato alle 12:36
Venerdì, 05/09/2008
Ecco il progetto rifatto con un modulo e un form


GrG ha allegato un file: fakebutton.zip (5026 bytes)
Clicca qui per scaricare il file

Ultima modifica effettuata da GrG il 05/09/2008 alle 12:53
PM Quote
Pagine: [ 1 2 3 4 5 ] Precedente | Prossimo