|
-
Feb 20th, 2003, 11:15 AM
#1
Thread Starter
Member
selecting text from msgbox
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......
-
Feb 20th, 2003, 11:17 AM
#2
Re: selecting text from msgbox
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......
you mean a message box from another program?? nope...
-
Feb 20th, 2003, 04:34 PM
#3
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
-
Feb 25th, 2003, 04:27 AM
#4
Thread Starter
Member
cheers - i'll give it a go
-
Feb 25th, 2003, 11:59 AM
#5
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.
-
Jun 26th, 2003, 11:25 AM
#6
Thread Starter
Member
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
-
Jun 26th, 2003, 12:11 PM
#7
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.
-
Jun 27th, 2003, 05:41 AM
#8
Thread Starter
Member
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
-
Jun 27th, 2003, 05:58 AM
#9
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
-
Jun 27th, 2003, 06:00 AM
#10
Well you could write you're own msgbox function, with a form.
-
Jun 27th, 2003, 06:12 AM
#11
Thread Starter
Member
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........
-
Jun 30th, 2003, 09:19 AM
#12
Thread Starter
Member
any more on this one or can it be closed ?!!!
-
Jun 30th, 2003, 09:39 AM
#13
Frenzied Member
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
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Jul 4th, 2003, 10:23 AM
#14
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
I picked up this code from someone else a while back. #32770 is apparently the VB class name of a MsgBox.
As was suggested by Lightning, the best solution for you is probably to use your own form.
-
Jul 4th, 2003, 02:57 PM
#15
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
Do you have the code for this application, or is it one you installed on ya machine that was written by someone else?
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
-
Jul 7th, 2003, 04:27 AM
#16
Thread Starter
Member
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
-
Jul 7th, 2003, 05:10 AM
#17
Hyperactive Member
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.
-
Jul 7th, 2003, 05:17 AM
#18
Thread Starter
Member
not quite sure i understand what you mean.......
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|