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 - visualizzazione di più msgbox
Forum - Visual Basic 6 - visualizzazione di più msgbox - Pagina 2

Pagine: [ 1 2 ] Precedente | Prossimo
Avatar
c.ronaldo (Normal User)
Expert


Messaggi: 577
Iscritto: 01/02/2007

Segnala al moderatore
Postato alle 21:37
Mercoledì, 09/05/2007
Alla prossima;)

PM Quote
Avatar
Hacker (Member)
Guru


Messaggi: 1014
Iscritto: 06/06/2006

Segnala al moderatore
Postato alle 15:40
Giovedì, 10/05/2007
ciao!;)

PM Quote
Avatar
c.ronaldo (Normal User)
Expert


Messaggi: 577
Iscritto: 01/02/2007

Segnala al moderatore
Postato alle 16:04
Venerdì, 11/05/2007
Ho trovato finalmente il progetto!

Module1 :

Codice sorgente - presumibilmente C#

  1. Attribute VB_Name = "ChangeMsg"
  2.   Option Explicit
  3.   Public Const MAX_PATH As Long = 260&
  4.  
  5.   Public Const API_TRUE As Long = 1&
  6.   Public Const API_FALSE As Long = 0&
  7.  
  8.   Public g_hBoldFont As Long
  9.  
  10.   Public Const MSGBOXTEXT As String = "In questo modo puoi cambiare anche il font del Message box!"
  11.   Public Const WM_SETFONT As Long = &H30
  12.   Public Const NV_CLOSEMSGBOX As Long = &H5000&
  13.   Public Const NV_MOVEMSGBOX As Long = &H5001&
  14.   Public Const NV_MSGBOXCHNGFONT As Long = &H5002&
  15.   Public Const MB_ICONQUESTION As Long = &H20&
  16.   Public Const MB_TASKMODAL As Long = &H2000&
  17.   Public Const SWP_NOSIZE As Long = &H1&
  18.   Public Const SWP_NOZORDER As Long = &H4&
  19.   Public Const HWND_TOP As Long = 0&
  20.  
  21.   Type RECT
  22.     Left As Long
  23.     Top As Long
  24.     Right As Long
  25.     Bottom As Long
  26.   End Type
  27.  
  28.  
  29.   Public Declare Function LockWindowUpdate& Lib "user32" (ByVal hwndLock&)
  30.   Public Declare Function GetActiveWindow& Lib "user32" ()
  31.   Public Declare Function GetDesktopWindow& Lib "user32" ()
  32.   Public Declare Function FindWindow& Lib "user32" Alias "FindWindowA" (ByVal lpClassName$, _
  33.                                                      ByVal lpWindowName$)
  34.   Public Declare Function FindWindowEx& Lib "user32" Alias "FindWindowExA" (ByVal hWndParent&, _
  35.                              ByVal hWndChildAfter&, ByVal lpClassName$, ByVal lpWindowName$)
  36.  
  37.   Public Declare Function SendMessage& Lib "user32" Alias "SendMessageA" (ByVal hWnd&, ByVal _
  38.                                                         wMsg&, ByVal wParam&, lParam As Any)
  39.  
  40.   Public Declare Function MoveWindow& Lib "user32" (ByVal hWnd&, ByVal x&, ByVal y&, _
  41.                                               ByVal nWidth&, ByVal nHeight&, ByVal bRepaint&)
  42.  
  43.   Public Declare Function ScreenToClientLong& Lib "user32" Alias "ScreenToClient" (ByVal hWnd&, _
  44.                                                                                     lpPoint&)
  45.  
  46.   Public Declare Function GetDC& Lib "user32" (ByVal hWnd&)
  47.   Public Declare Function ReleaseDC& Lib "user32" (ByVal hWnd&, ByVal hDC&)
  48.  
  49.   ' drawtext flags
  50.  Public Const DT_WORDBREAK As Long = &H10&
  51.  Public Const DT_CALCRECT As Long = &H400&
  52.  Public Const DT_EDITCONTROL As Long = &H2000&
  53.  Public Const DT_END_ELLIPSIS As Long = &H8000&
  54.  Public Const DT_MODIFYSTRING As Long = &H10000
  55.  Public Const DT_PATH_ELLIPSIS As Long = &H4000&
  56.  Public Const DT_RTLREADING As Long = &H20000
  57.  Public Const DT_WORD_ELLIPSIS As Long = &H40000
  58.  
  59.  Public Declare Function DrawText& Lib "user32" Alias "DrawTextA" (ByVal hDC&, ByVal lpsz$, _
  60.                                          ByVal cchText&, lpRect As RECT, ByVal dwDTFormat&)
  61.  
  62.  Public Declare Function SetForegroundWindow& Lib "user32" (ByVal hWnd&)
  63.  
  64.  Public Declare Function GetClassName& Lib "user32" Alias "GetClassNameA" (ByVal hWnd&, _
  65.                                                        ByVal lpClassName$, ByVal nMaxCount&)
  66.  
  67.  Public Declare Function GetWindowRect& Lib "user32" (ByVal hWnd&, lpRect As RECT)
  68.  
  69.  Public Declare Function SetWindowPos& Lib "user32" (ByVal hWnd&, ByVal hWndInsertAfter&, _
  70.                                      ByVal x&, ByVal y&, ByVal cx&, ByVal cy&, ByVal wFlags&)
  71.                                      
  72.  Public Declare Function MessageBox& Lib "user32" Alias "MessageBoxA" (ByVal hWnd&, _
  73.                                                ByVal lpText$, ByVal lpCaption$, ByVal wType&)
  74.  
  75.  Public Declare Function SetTimer& Lib "user32" (ByVal hWnd&, ByVal nIDEvent&, ByVal uElapse&, _
  76.                                                                            ByVal lpTimerFunc&)
  77.  
  78.  Public Declare Function KillTimer& Lib "user32" (ByVal hWnd&, ByVal nIDEvent&)
  79.  
  80. Public Sub TimerProc(ByVal hWnd&, ByVal uMsg&, ByVal idEvent&, ByVal dwTime&)
  81.  KillTimer hWnd, idEvent
  82.  
  83.  Select Case idEvent
  84.    Case NV_CLOSEMSGBOX
  85.      Dim hMessageBox&
  86.      
  87.         hMessageBox = FindWindow("#32770", "Chiusura a tempo Message Box")
  88.      
  89.      If hMessageBox Then
  90.        Call SetForegroundWindow(hMessageBox)
  91.        SendKeys "{enter}"
  92.      End If
  93.      
  94.    Case NV_MOVEMSGBOX
  95.      Dim hMsgBox&, xPoint&, yPoint&
  96.      Dim stMsgBoxRect As RECT, stParentRect As RECT
  97.      
  98.      
  99.      hMsgBox = FindWindow("#32770", "Posizione Message Box")
  100.    
  101.      
  102.      If hMsgBox Then
  103.        
  104.        Call GetWindowRect(hMsgBox, stMsgBoxRect)
  105.        Call GetWindowRect(hWnd, stParentRect)
  106.        
  107.        
  108.        xPoint = stParentRect.Left + (((stParentRect.Right - stParentRect.Left) \ 2) - _
  109.                                              ((stMsgBoxRect.Right - stMsgBoxRect.Left) \ 2))
  110.        yPoint = stParentRect.Top + (((stParentRect.Bottom - stParentRect.Top) \ 2) - _
  111.                                              ((stMsgBoxRect.Bottom - stMsgBoxRect.Top) \ 2))
  112.        
  113.        
  114.        If xPoint < 0 Then xPoint = 0
  115.        If yPoint < 0 Then yPoint = 0
  116.        If (xPoint + (stMsgBoxRect.Right - stMsgBoxRect.Left)) > _
  117.                                          (Screen.Width \ Screen.TwipsPerPixelX) Then
  118.          xPoint = (Screen.Width \ Screen.TwipsPerPixelX) - (stMsgBoxRect.Right - stMsgBoxRect.Left)
  119.        End If
  120.        If (yPoint + (stMsgBoxRect.Bottom - stMsgBoxRect.Top)) > _
  121.                                          (Screen.Height \ Screen.TwipsPerPixelY) Then
  122.          yPoint = (Screen.Height \ Screen.TwipsPerPixelY) - (stMsgBoxRect.Bottom - stMsgBoxRect.Top)
  123.        End If
  124.        
  125.        
  126.      
  127.        Call SetWindowPos(hMsgBox, HWND_TOP, xPoint, yPoint, _
  128.                                        API_FALSE, API_FALSE, SWP_NOZORDER Or SWP_NOSIZE)
  129.      End If
  130.      
  131.    
  132.      Call LockWindowUpdate(API_FALSE)
  133.      
  134.      
  135.    Case NV_MSGBOXCHNGFONT
  136.      hMsgBox = FindWindow("#32770", "Cambio Message Box Font")
  137.    
  138.    
  139.      If hMsgBox Then
  140.        Dim hStatic&, hButton&, stMsgBoxRect2 As RECT
  141.        Dim stStaticRect As RECT, stButtonRect As RECT
  142.        
  143.        
  144.        hStatic = FindWindowEx(hMsgBox, API_FALSE, "Static", MSGBOXTEXT)
  145.        hButton = FindWindowEx(hMsgBox, API_FALSE, "Button", "OK")
  146.        
  147.      
  148.        If hStatic Then
  149.          
  150.          Call GetWindowRect(hMsgBox, stMsgBoxRect2)
  151.          Call GetWindowRect(hStatic, stStaticRect)
  152.          Call GetWindowRect(hButton, stButtonRect)
  153.          
  154.          
  155.          Call SendMessage(hStatic, WM_SETFONT, g_hBoldFont, ByVal API_TRUE)
  156.          
  157.          With stStaticRect
  158.            
  159.            Call ScreenToClientLong(hMsgBox, .Left)
  160.            Call ScreenToClientLong(hMsgBox, .Right)
  161.            
  162.            Dim nRectHeight&, nHeightDifference&, hStaticDC&
  163.            
  164.            
  165.            nHeightDifference = .Bottom - .Top
  166.            
  167.          
  168.            hStaticDC = GetDC(hStatic)
  169.            
  170.          
  171.            nRectHeight = DrawText(hStaticDC, MSGBOXTEXT, (-1&), stStaticRect, _
  172.                                              DT_CALCRECT Or DT_EDITCONTROL Or DT_WORDBREAK)
  173.            
  174.          
  175.            Call ReleaseDC(hStatic, hStaticDC)
  176.            
  177.            
  178.            nHeightDifference = nRectHeight - nHeightDifference
  179.            
  180.            
  181.            Call MoveWindow(hStatic, .Left, .Top, .Right - .Left, nRectHeight, API_TRUE)
  182.          End With
  183.            
  184.          
  185.          With stButtonRect
  186.            
  187.            Call ScreenToClientLong(hMsgBox, .Left)
  188.            Call ScreenToClientLong(hMsgBox, .Right)
  189.            
  190.            
  191.            Call MoveWindow(hButton, .Left, .Top + nHeightDifference, .Right - .Left, .Bottom - .Top, API_TRUE)
  192.          End With
  193.          
  194.          With stMsgBoxRect2
  195.            
  196.            Call MoveWindow(hMsgBox, .Left, .Top - (nHeightDifference \ 2), .Right - .Left, (.Bottom - .Top) + nHeightDifference, API_TRUE)
  197.          
  198.            
  199.          End With
  200.        End If
  201.      End If
  202.      
  203.      
  204.      Call LockWindowUpdate(API_FALSE)
  205.  
  206.  End Select
  207.  
  208. End Sub



Codice sorgente - presumibilmente VB.NET

  1. Private Sub Command2_Click()
  2.   Call LockWindowUpdate(GetDesktopWindow())
  3.  
  4.   SetTimer hWnd, NV_MOVEMSGBOX, 10&, AddressOf TimerProc
  5.  
  6.   Call MessageBox(hWnd, "In questo modo Message Box può essere posto anche non a centro dello schermo!", _
  7.                                         "Posizione Message Box", MB_ICONQUESTION Or MB_TASKMODAL)
  8.  
  9. End Sub
  10.  
  11. Vedi,dovrebbe funzionare

;)

PM Quote
Pagine: [ 1 2 ] Precedente | Prossimo