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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I tell NotePad/WordPad to save a file using messaging

Status
Not open for further replies.

SBendBuckeye

Programmer
May 22, 2002
2,166
US
I found this piece of code in the below FAQ. What commands would I use to instruct NotePad to save its file once I wrote data to it using code like below?

Thanks!

How do I send keystrokes to Notepad/Wordpad? faq222-884

Here is a simple but effective code used to send keystrokes
to Notepad / Wordpad.

Sending text to another program
------------------------------------------------------------

Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWndParent As Long, ByVal hwndChildAfter As Long, ByVal lpszClass As String, ByVal lpszWindow As String) As Long

Const WM_SETTEXT = 12

Public Sub ToNotePad(x As String)
'assuming notepad is open
Dim h As Long, ed As Long, t As Long
h = FindWindow("Notepad", "Untitled - Notepad")
If (h <> 0) Then
ed = FindWindowEx(h, 0, &quot;Edit&quot;, &quot;&quot;)
If (ed <> 0) Then
SendMessage ed, WM_SETTEXT, ByVal 0, ByVal x
Else
MsgBox &quot;Could not find notepad's edit&quot;
End If
Else
MsgBox &quot;Could not find notepad&quot;
End If
End Sub



Have a great day!

j2consulting@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top