Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Da i Ne u msgbox-u

[es] :: Visual Basic 6 :: Da i Ne u msgbox-u

[ Pregleda: 6663 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

jc denton

Član broj: 2358
Poruke: 1705
*.ptt.yu



Profil

icon Da i Ne u msgbox-u12.03.2002. u 13:35 - pre 269 meseci
Verujem da ce ovo biti interesantno parce koda, zato sto je i mene od uvek kopkalo kako se moze doci do window handle-a, a da nam nije dostupan direktno u VB-u za neku kontrolu ili prozor. Uz malo napora, moglo bi sto sta da se 'prevede', common dialogs na primer.
Ako neko ima elegantnije resenje za ovo ili sl., neka posalje.

Da bi ovo radilo kako treba mora da se pokrene kao .exe ili ce kod biti stopiran dok se ne klikne na neko dugme u msgbox-u.

ovo ide u modul :

Code:
' za ostale window konstante najbolje je koristiti API Viewer
Public Const GW_HWNDNEXT = 2
Public Const GW_CHILD = 5

' ove api fn su opisane u Window Functions sekciji u MSDN-u
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Public Declare Function GetNextWindow Lib "user32" Alias "GetWindow" _
(ByVal hwnd As Long, ByVal wFlag As Long) As Long

Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" _
(ByVal hwnd As Long, ByVal lpString As String) As Long


Private Sub Command1_Click()

Timer1.Interval = 50 ' sto pre to bolje
Timer1.Enabled = True ' tajmer koji ce da promeni 'yes' i 'no' u 'da' i 'ne'

' postavljamo msgbox, caption je inace obavezan i trebalo bi da bude jedinstven
MsgBox "Sto mora da pise 'Yes' i 'No' ?", vbYesNo, "'domaci' msgbox"

End Sub

Private Sub Timer1_Timer()

Dim hendl As Long

' timer je odradio svoje
Timer1.Enabled = False

' nalazimo hWnd od msgbox-a preko njegovog caption-a
hendl = FindWindow(vbNullString, "'domaci' msgbox")

' nalazimo hWnd prvog child prozora, u ovom slucaju je to dugme 'Yes'
hendl = GetNextWindow(hendl, GW_CHILD)
' menjamo caption u 'Da'
SetWindowText hendl, "&Da"

' sada ide hWnd za sledece dugme - 'No'
hendl = GetNextWindow(hendl, GW_HWNDNEXT)
' menjamo caption u 'Ne'
SetWindowText hendl, "&Ne"

End Sub




[Ovu poruku je menjao Shadowed dana 18.08.2005. u 17:03 GMT+1]
fire, walk with me
 
Odgovor na temu

vujkev
Beograd

Član broj: 8072
Poruke: 1347
*.scnet.yu



+104 Profil

icon Re: Da i Ne u msgbox-u10.09.2004. u 11:16 - pre 238 meseci
Evo jednog malo boljeg nacina za dodavanje custom teksta
Code:
Option Explicit

' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' Ovo ide u modul
' !!!!!!!!!!!!!!!!!!!!

'uType parameters
Private Const MB_ICONINFORMATION As Long = &H40&
Private Const MB_ABORTRETRYIGNORE As Long = &H2&
Private Const MB_TASKMODAL As Long = &H2000&

'Windows-defined Return values. The return
'values and control IDs are identical.
Public Const IDOK = 1
Public Const IDCANCEL = 2
Public Const IDABORT = 3
Public Const IDRETRY = 4
Public Const IDIGNORE = 5
Public Const IDYES = 6
Public Const IDNO = 7

'VBnet-defined control ID for the message prompt
Private Const IDPROMPT = &HFFFF&

'misc constants
Private Const WH_CBT = 5
Private Const GWL_HINSTANCE = (-6)
Private Const HCBT_ACTIVATE = 5

'UDT for passing data through the hook
Private Type MSGBOX_HOOK_PARAMS
   hwndOwner   As Long
   hHook       As Long
End Type

'need this declared at module level as
'it is used in the call and the hook proc
Private MSGHOOK As MSGBOX_HOOK_PARAMS

Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long

Public Declare Function GetDesktopWindow Lib "user32" () As Long

Private Declare Function GetWindowLong Lib "user32" _
   Alias "GetWindowLongA" _
  (ByVal hwnd As Long, _
   ByVal nIndex As Long) As Long

Private Declare Function MessageBox Lib "user32" _
   Alias "MessageBoxA" _
  (ByVal hwnd As Long, _
   ByVal lpText As String, _
   ByVal lpCaption As String, _
   ByVal wType As Long) As Long
   
Private Declare Function SetDlgItemText Lib "user32" _
   Alias "SetDlgItemTextA" _
  (ByVal hDlg As Long, _
   ByVal nIDDlgItem As Long, _
   ByVal lpString As String) As Long
      
Private Declare Function SetWindowsHookEx Lib "user32" _
   Alias "SetWindowsHookExA" _
  (ByVal idHook As Long, _
   ByVal lpfn As Long, _
   ByVal hmod As Long, _
   ByVal dwThreadId As Long) As Long
   
Private Declare Function SetWindowText Lib "user32" _
   Alias "SetWindowTextA" _
  (ByVal hwnd As Long, _
   ByVal lpString As String) As Long

Private Declare Function UnhookWindowsHookEx Lib "user32" _
   (ByVal hHook As Long) As Long
    


Public Function MessageBoxH(hwndThreadOwner As Long, hwndOwner As Long) As Long

  'Wrapper function for the MessageBox API

   Dim hInstance As Long
   Dim hThreadId As Long
   
  'Set up the CBT (computer-based training) hook
   hInstance = GetWindowLong(hwndThreadOwner, GWL_HINSTANCE)
   hThreadId = GetCurrentThreadId()

  'set up the MSGBOX_HOOK_PARAMS values
  'By specifying a Windows hook as one
  'of the params, we can intercept messages
  'sent by Windows and thereby manipulate
  'the dialog
   With MSGHOOK
      .hwndOwner = hwndOwner
      .hHook = SetWindowsHookEx(WH_CBT, _
                                AddressOf MsgBoxHookProc, _
                                hInstance, hThreadId)
   End With

  'call the MessageBox API and return the
  'value as the result of the function. The 
  'Space$(120) statements assures the messagebox 
  'is wide enough for the message that will 
  'be set in the hook.
  '
  'NOTE: I am setting the text in the hook only 
  'for demo purposes, to show how its done. You 
  'certainly can pass the title and prompt text 
  'right in the API call instead.
   MessageBoxH = MessageBox(hwndOwner, _
                Space$(120), _
                Space$(120), _
                MB_ABORTRETRYIGNORE Or MB_ICONINFORMATION)

End Function


Public Function MsgBoxHookProc(ByVal uMsg As Long, _
                               ByVal wParam As Long, _
                               ByVal lParam As Long) As Long
      
  'When the message box is about to be shown,
  'we'll change the titlebar text, prompt message
  'and button captions
   If uMsg = HCBT_ACTIVATE Then
   
     'in a HCBT_ACTIVATE message, wParam holds
     'the handle to the messagebox
         
      SetWindowText wParam, "VBnet MessageBox Hook Demo"
      
     'the ID's of the buttons on the message box
     'correspond exactly to the values they return,
     'so the same values can be used to identify
     'specific buttons in a SetDlgItemText call.
      SetDlgItemText wParam, IDABORT, "Search C:\"
      SetDlgItemText wParam, IDRETRY, "Search D:\"
      SetDlgItemText wParam, IDIGNORE, "Cancel"
      
     'Change the dialog prompt text ...
      SetDlgItemText wParam, IDPROMPT, "MyApp will now locate the application." & _
                                       "Please select the drive to search."
                                             
     'we're done with the dialog, so release the hook
      UnhookWindowsHookEx MSGHOOK.hHook
               
   End If
   
  'return False to let normal processing continue
   MsgBoxHookProc = False

End Function
Code:

' !!!!!!!!!!!!!!!!!!!!!!!!!
' Ovo naravno u formu
' !!!!!!!!!!!!!!!!!!!!!!!!!

Option Explicit

Private Sub Command1_Click()
  
  'Display our wrapper message box.
  'The first parameter passed is
  'required for GetWindowLong, and
  'specifies the window who's instance
  'will be passed to SetWindowsHookEx.
  'The second parameter is used in the
  'hook and MessageBox call, and indicates
  'who receives error messages and where
  'the dialog will appear.
   Select Case MessageBoxH(Me.hwnd, GetDesktopWindow())
      Case IDABORT:  Text1.Text = "Scan C selected"
      Case IDRETRY:  Text1.Text = "Scan D selected"
      Case IDIGNORE: Text1.Text = "Cancel selected"
   End Select
   
End Sub


Preuzeto sa http://vbnet.mvps.org/index.html?code/hooks/messageboxhook.htm
Naučio sam...
Da je važnije biti ljubazan nego biti u pravu
 
Odgovor na temu

MACTEPx

Član broj: 47593
Poruke: 341
*.dialup.neobee.net.



+5 Profil

icon Re: Da i Ne u msgbox-u18.08.2005. u 12:49 - pre 227 meseci
a moze li ovaj srpski msgbox (post 2) da bude modalan tj. da ne moze da se nista drugo radi u programu dok se ne odgovori na msgbox odnosno kao klasicni msgbox?
#include <iostream.h>
void main()
{
cout << "Pozdrav...";
}
 
Odgovor na temu

[es] :: Visual Basic 6 :: Da i Ne u msgbox-u

[ Pregleda: 6663 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.