|
-
Aug 9th, 2000, 04:46 AM
#1
Thread Starter
New Member
I am new in VB and I would greatly appreciate any help.
I have tried to access the menu of NOTEPAD (I use it to display HTML code) from within my application using the "send message" API function. Although I succeded to send commands and access all the menu items of the NOTEPAD, this didn't work with "Cut", "Copy" and "Paste" of the "Edit" menu. Is there something special with those?
Is there any alternative way to manipulate (Select, copy, etc) the text displayed in the NOTEPAD? ("Sendkeys" do not work in an already opened instance of notepad. Am I wrong?)
Many thanks in advance
-
Aug 9th, 2000, 05:52 AM
#2
Lively Member
When sending the message to Notepad, I think if you
use the constants WM_CUT, WM_COPY, WM_PASTE then it
might work. I haven't tried it yet, so please let me know if it works.
Hope it helps
IJ...
-
Aug 9th, 2000, 08:44 AM
#3
Thread Starter
New Member
Unfortunately it didn't work. The WM_COPY appears to send the message to a specific Edit CONTROL . In the case of NOTEPAD this must be the TextBox of NOTEPAD but I don't know how to find its Handle. Any idea??
THANKS
-
Aug 9th, 2000, 08:54 AM
#4
Use FindWindowEx. This will paste text into Notepad:
Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As Any, ByVal lpsz2 As Any) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_COPY = &H301
Const WM_CUT = &H300
Const WM_PASTE = &H302
Dim hParent As Long
Dim hChild As Long
Private Sub Command1_Click()
'Get the Handle of Notepad
hParent = FindWindow("Notepad", 0&)
'Get the Handle of the Edit Control
hChild = FindWindowEx(hParent, 0&, "Edit", 0&)
'Send "paste" a message to the Edit Control.
SendMessage hChild, WM_PASTE, 0&, 0&
End Sub
-
Aug 9th, 2000, 09:47 AM
#5
Thread Starter
New Member
SendMessage-stillproblem
THANKS to everybody
But still nothing has worked!
Probably Megatron, the class of Edit control of NOTEPAD is not "Edit" because the hChild is returned 0. Any other idea?
Thanks in advance
-
Aug 9th, 2000, 10:19 AM
#6
The class of the Notepad conrol is Edit. I even double checked it with a Class-Spy tool and tested it on my machine and it worked fine.
Try making a brand new project and add a CommandButton with the above code into it. Also, make sure that Notepad is openend before you run your App and also make sure that you have some text on the clipboard.
-
Aug 10th, 2000, 02:06 AM
#7
New Member
Where are your heads?? Your not supposed to use 0& when the function asks for a string. Use vbNullString. That should fix your problem. Im not going to go into the WM_PASTE constant because i dont use it. Well here is the way i would do it:
Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Const WM_SETTEXT = &HC
Private Sub Command1_Click()
'Dim variables
Dim notepad As Long, editx As Long
'Find the hWnd of the notepad window
notepad = FindWindow("notepad", vbNullString)
'Find the hWnd of the notepad textbox
editx = FindWindowEx(notepad, 0&, "edit", vbNullString)
'Set the textbox's text
SendMessageByString editx, WM_SETTEXT, 0, "Code Fixed By: ser"
End Sub
-
Aug 10th, 2000, 03:25 AM
#8
Thread Starter
New Member
THANK YOU Ser
Amazing. That was the trick. Everything works now!!!!
THANKs to everybody
THANKS
-
Aug 10th, 2000, 08:23 AM
#9
Ser. I didn't use vbNullString because I declared both arguments as Any.
Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
-
Aug 10th, 2000, 02:21 PM
#10
New Member
Oh, i am very sorry. I didnt realize it when i was looking over the code. My sincerest apologies.
Please exuse any mispeled words
Tell me and I forget.
Show me and I remember.
Teach me and I learn.
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
|