hi !
I want to develop an application in vb.net which can save any open Text Document , Notepad ,Ms-Word ,Ms-Excel etc , The main theme is that my application simple send the SAVE command .
i use SendKeys.send("^S") , SendKeys.send("^ + S"),SendKeys.send("{^+S}"),SendKeys.send("{^}+{S}"),SendKeys.send("{Ctrl}+ {S}") . but nothing happening.can Any one guide me how to make it possible :(

Thanks in advanced ,

Regards

Waqas aslam meo

Edited 5 Years Ago by M.Waqas Aslam: n/a

You need to grab the handle of the application for which you want to save the document.
In order to achieve this, you need to use Windows API to grab and perform.

''' A couple of APIs
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindow(ByVal lpcClassName As String, ByVal lpWindowName As String) As IntPtr
End Function

<DllImport("user32.dll", EntryPoint:="FindWindow", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindowByClass( _
     ByVal lpClassName As String, _
     ByVal zero As IntPtr) As IntPtr
End Function

<DllImport("user32.dll", EntryPoint:="FindWindow", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindowByCaption( _
     ByVal zero As IntPtr, _
     ByVal lpWindowName As String) As IntPtr
End Function

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, _
                      ByVal childAfter As IntPtr, _
                      ByVal lclassName As String, _
                      ByVal windowTitle As String) As IntPtr
End Function

<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Function SendNotifyMessage( _
     ByVal hWnd As IntPtr, _
     ByVal msg As UInteger, _
     ByVal wParam As UIntPtr, _
     ByVal lParam As IntPtr _
     ) As Boolean
End Function 

''' General methods
Const BM_CLICK As Uinteger = &HF5
Dim WindowHandle As IntPtr
Dim ButtonHandle As IntPtr

'First grab the actual window of the application
WindowHandle = FindWindowByCaption(IntPtr.Zero, "Caption of Notepad window")
'Second, grab the desired function/button within the window/application, in this case the Save button
ButtonHandle = FindWindowEx(WindowHandle, 0, "Button", "&Save")

'Send a message to the grabbed window/button to perform an action, in this case click the Save button
SendNotifyMessage(ButtonHandle, BM_CLICK, 0, 0)
This question has already been answered. Start a new discussion instead.