Strange request, and I'm pretty sure it's not supported, but is there any any way to allow the text from a message box to be copied and then pasted elsewhere......
Printable View
Strange request, and I'm pretty sure it's not supported, but is there any any way to allow the text from a message box to be copied and then pasted elsewhere......
you mean a message box from another program?? nope...Quote:
Originally posted by chris22moore
Strange request, and I'm pretty sure it's not supported, but is there any any way to allow the text from a message box to be copied and then pasted elsewhere......
If it's from a VB MsgBox then do this:
VB Code:
Option Explicit Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long Public Const GW_CHILD = 5 Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long Public Const GW_HWNDNEXT = 2 Public Sub GetMsgBoxText(strCaption As String) Dim strBuffer As String, hOK Dim hChild As Long Dim strClassName As String Dim hMsg As Long Dim sName As String Dim sGoodText As String hMsg = FindWindow("#32770", strCaption) hChild = GetWindow(hMsg, GW_CHILD) ' Start looping through all child windows Do 'Get the window class name strClassName = Space$(128) strBuffer = GetClassName(hChild, ByVal strClassName, 128) strClassName = Left$(strClassName, strBuffer) If strClassName = "Button" Then ' If you want to look at the text of a button sName = Space$(128) strBuffer = GetWindowText(hChild, sName, 128) If strBuffer > 0 Then sName = Left$(sName, strBuffer) End If End If If strClassName = "Static" Then ' It's a label or msgbox sName = Space$(128) strBuffer = GetWindowText(hChild, sName, 128) If strBuffer > 0 Then sName = Left$(sName, strBuffer) MsgBox sName Exit Do End If End If ' Get the next child window handle. hChild = GetWindow(hChild, GW_HWNDNEXT) Loop While hChild <> 0 End Sub Public Sub Main() ' Enter the text in the MsgBox caption GetMsgBoxText "Project1" End Sub
cheers - i'll give it a go
BTW, since you can also find the command button(s) in the msgbox, you have the ability to click them which allows you to create a "self-closing" msgbox if you want one.
Unfortunately after writing the original request I was pulled onto something else so have only now been abke to give it a go.
This may seem a bit naive, but how do you implement the code example given. And how is this going to allow me to display a msgbox, from which I can then copy the text of the prompt ?
cheers
Create a project named Project1 that displays any message box. Create Project2, add a code module, and copy my code to the code module. Run Project1 and display its msgbox. While it is displayed, run Project2 and it will display the text of the message box from Project1.
Cool
Got that working and it's possible something I could use. The thing is it's not quite what I was after. Basically the system I'm looking at uses the VB message box to display system information to users. Some of this information consists of reference numbers which it would be useful to copy and paste elsewhere.
I therefore need the message box itself to allow a user to select and copy the text from the prompt portion of the message box. Is this possible or do you have any other ideas ?
One other thing - you pass "#32770" to FindWindow - what does this value represent ?
Cheers
May'be it is helpful to know that [ctrl]-[shift]-C copy the text of a msgbox. Not all msgbox's but most of them
Well you could write you're own msgbox function, with a form.
ctrl shift c copies the text for title, prompt and button text which is noit what I'm after really.
I could write my own msgbox, but I fancy playing especially if it involves some windows api stuff as I could do with a bit of practice at this........
any more on this one or can it be closed ?!!!
A really whacky way is to use an INPUTBOX instead of a MSGBOX with the referred numbers being set as the default text. You just have to ignore any returned values of the INPUTBOX and have to make do with "OK" and "CANCEL" buttons only.
Regards
KayJay :)
I picked up this code from someone else a while back. #32770 is apparently the VB class name of a MsgBox.Quote:
Originally posted by chris22moore
Cool
Got that working and it's possible something I could use. The thing is it's not quite what I was after. Basically the system I'm looking at uses the VB message box to display system information to users. Some of this information consists of reference numbers which it would be useful to copy and paste elsewhere.
I therefore need the message box itself to allow a user to select and copy the text from the prompt portion of the message box. Is this possible or do you have any other ideas ?
One other thing - you pass "#32770" to FindWindow - what does this value represent ?
Cheers
As was suggested by Lightning, the best solution for you is probably to use your own form.
Do you have the code for this application, or is it one you installed on ya machine that was written by someone else?Quote:
Originally posted by chris22moore
Cool
Got that working and it's possible something I could use. The thing is it's not quite what I was after. Basically the system I'm looking at uses the VB message box to display system information to users. Some of this information consists of reference numbers which it would be useful to copy and paste elsewhere.
I therefore need the message box itself to allow a user to select and copy the text from the prompt portion of the message box. Is this possible or do you have any other ideas ?
One other thing - you pass "#32770" to FindWindow - what does this value represent ?
Cheers
If you have the code for it, then change the code so instead of displaying the info in a MsgBox, create a custom form that displays the infor in text boxs...
Woka
in the end i created my own msgbox using form + textbox.
I guess I just wanted to play with the win api.
cheers for all the advice
It's funny, if you pull the text from the message box that YOUR program created, and even add the code to press the button on the message box to self close it, now the question arises? Why creating such a message box? Instead of Msgbox "This text here needs to be copied", use str = "This text here needs to be copied", and than msgbox istr (if you still need to show the message box). If it's an error from a dll or what not, i know there's an API to get the last error, but I don't remember it.
not quite sure i understand what you mean.......