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

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)

You might find it easier to do this with AutoIt using either vbScript to interface to the AutoItX control or the builtin AutoIt scripting feature. You can get more information at

http://www.autoitscript.com/site/autoit/

It's free, by the way.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.