Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can we change button capiton in message box!!!!!!!!! 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0

hai,
i want to chage button caption in message box.
is it possible?.if anyone knows kindly help me....
thanks in advance.......

bye
ch padma raju
 
I would have thought with some fancy API usong FindWindow, GetDlgItem and SetWindowText would be able to do just this....... unless the buttons are like the "start" button, which i think is graphics-based so you can't. oh well.

Phr3-|-

for some of my muzic...
 
Yes, you can do it. Here's one method. it's just a variant technique for getting the hWnd of a button in a message box. Note that it is illustrative only, in that it only properly deals with the case of a single button in the message box. Once you get the idea, it should be pretty easy for you to extend it to multiple buttons:
[tt]Option Explicit
' Necessary constants for hooking, and changinf cursor
Private Const HCBT_ACTIVATE = 5
Private Const HCBT_DESTROYWND = 4
'Private Const GWL_HINSTANCE = (-6)
Private Const WH_CBT = 5

' Working variables that require global scope in hooking module
Private hHook As Long

' The API declarations we need
Public 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
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Const GW_CHILD = 5
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Public mButtonCaption As String

' Our wrapper for the normal MsgBox function takes an additional optional
' parameter that defines the new button caption
Public Function vbMsgBox(Prompt As String, Optional Buttons As VbMsgBoxStyle = vbOKOnly, Optional Title As String, Optional HelpFile As String, Optional Context As Long, Optional ButtonCaption As String = "") As Long
hHook = SetWindowsHookEx(WH_CBT, AddressOf WinProc, App.hInstance, 0) 'Thread)
mButtonCaption = ButtonCaption ' Make note of required cursor type
vbMsgBox = MsgBox(Prompt, Buttons, Title, HelpFile, Context)
End Function

Private Function WinProc(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Static hwndMessageBox As Long
Static OldClassCursor As Long

If lMsg = HCBT_ACTIVATE Then
If hwndMessageBox = 0 Then hwndMessageBox = wParam ' Save MsgBox hWnd
If hwndMessageBox = wParam Then
If mButtonCaption <> &quot;&quot; Then
' Note you may want to change the size of the command button here,
' particularly if the new text is longer than the original text. You
' could use MoveWindow to achieve that.
SetWindowText GetWindow(hwndMessageBox, GW_CHILD), mButtonCaption
' At this point you could also save the hwndMessagebox, in case
' you wanted to do anything else
hwndMessageBox = 0
End If
UnhookWindowsHookEx hHook ' Unhook straightaway
End If
End If

WinProc = False
End Function
[/tt]
 

thanks for giving reply to my question. specially the code given by strongm. but i didn't have full idea of API programming.when i executed that code it is giving error
saying that invalid use of &quot;addressof&quot; parameter.
can u send me project file.i will be very thankfull to you.

bye
ch padma raju....
(padmaraju_ch@rediffmail.com)
 
Due to a VB quirk, Address Of cannot be used by itself to return a value.

So where it says AddressOf WinProc, replace that with DummyFunc(AddressOf WinProc)
with DummyFunc defined as

Private Function DummyFunc(byval lngParam as long) as long
DummyFunc = lngParam
End Function

This should work
 
I'm afraid that mwardle is being slightly misleading concerning the quirk. The actual 'quirk' is that AddressOf can only return a value when used in a function. i.e you can't say:

Jim = Addressof Sarah

and you have to resort to the DummyFunc technique to get an assignment like this to work.

But use as a function parameter is perfectly OK (indeed, the DummyFunc technique makes use of that fact). The only caveat is that the code must be in a standard code module, not in a form or class module - and I neglected to point out that my code should be cut and pasted into such a module.

I suspect that Padma has pasted the code into a form, hence the error message.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top