View Single Post
Old 20th April 2016, 07:54   #9
r2du-soft
Senior Member
 
r2du-soft's Avatar
 
Join Date: Nov 2013
Location: Iran
Posts: 342
Thanks for helping
Often i have a problem with this codes:


HTML Code:
;--------------------------------
!include "Win\COM.nsh"
!include "Win\PropKey.nsh"
!include "LogicLib.nsh"
;--------------------------------

;----------
Var Handle1
Var Handle2
Var GetForegroundWindow_hwnd
#--------------


Section

MessageBox MB_YESNO|MB_TOPMOST|MB_SETFOREGROUND|MB_ICONEXCLAMATION "Return?" IDYES true IDNO false

true:

	CheckAgainWindow:
	Sleep 1000
	;------------
	;Sleep 500
	FindWindow $Handle1 "CalcFrame" ""
	SendMessage $Handle1 0x0010 0 0
	;------------
	Sleep 1000
	;------------
	Exec "Calc.exe"
	;------------
	Sleep 1000
	;------------
	FindWindow $Handle2 "CalcFrame" ""
	Sleep 500
	System::Call 'user32::SetForegroundWindow(i $Handle2)'
	;------------
	Sleep 1000
	;------------
	System::Call user32::GetForegroundWindow('')i.r0
	StrCpy $GetForegroundWindow_hwnd $0
	;------------
	Sleep 1000
	;------------
	StrCmp $Handle2 $GetForegroundWindow_hwnd ContinueWindow CheckAgainWindow 
	#--------------------------
	

	ContinueWindow:
	
	${NSISCOMIFACEDECL}IWshShell2 AppActivate 17 (i,i,*i)i
	${NSISCOMIFACEDECL}IWshShell2 SendKeys 18 (i,i)i
	;System::Call 'OLE32::CLSIDFromProgID(w "WScript.Shell",g.r1)i.r0'
	;!insertmacro ComHlpr_CreateInProcInstance $1 "{24BE5A30-EDFE-11d2-B933-00104B365C9F}" r0 ""
	!insertmacro ComHlpr_CreateInProcInstance "{72c24dd5-d70a-438b-8a42-98424b88afb8}" "{24BE5A30-EDFE-11d2-B933-00104B365C9F}" r0 "" 
${If} $0 <> 0
		System::Call 'OLEAUT32::SysAllocString(w "Calculator")i.r9'
		System::Call '*${SYSSTRUCT_PROPVARIANT}(${VT_BSTR},,ir9)i.r1'
		System::Call '*${SYSSTRUCT_PROPVARIANT}(${VT_BOOL},,${VARIANT_TRUE})i.r2'
		StrCpy $5 0
		startedapp:
		${IWshShell2::AppActivate} $0 '(r1,r2,${VARIANT_FALSE}r3)i.r4'
	${If} $3 <> ${VARIANT_FALSE}
	${AndIf} $4 = 0
		;-------------------------------------------------------------------------
		System::Call 'OLEAUT32::SysFreeString(ir9)'
		System::Call 'OLEAUT32::SysAllocString(w "1 + 2 =")i.r9'
		${IWshShell2::SendKeys} $0 '(r9,r2)i.r4'
		;------------
		Sleep 2000
		;------------
		System::Call 'OLEAUT32::SysFreeString(ir9)'
		System::Call 'OLEAUT32::SysAllocString(w "{DEL}")i.r9'
		${IWshShell2::SendKeys} $0 '(r9,r2)i.r4'
		;------------
		Sleep 1000
		;------------
		System::Call 'OLEAUT32::SysFreeString(ir9)'
		System::Call 'OLEAUT32::SysAllocString(w "3 + 4 =")i.r9'
		${IWshShell2::SendKeys} $0 '(r9,r2)i.r4'
		;-------------------------------------------------------------------------
	${Else}
		Exec calc.exe
		Sleep 1111
		IntOp $5 $5 + 1
		IntCmpU $5 1 "" "" +2
		goto startedapp
	${EndIf}
System::Call 'OLEAUT32::SysFreeString(ir9)'
System::Free $2
System::Free $1
${IUnknown::Release} $0 ""
${EndIf}
	##----------------------------------

false:

SectionEnd


When i use from code MessageBox at the beginning of the program,some times calculator crashed and show me Close the program and some times no send any key to calculator!

and i have another problem:
i try to fix that but i did not succeed...
i want send

i send 1 + 2 = to calculator and after sleep 2 Sec delete that and send 3 + 4 = to calculator but after run app just see 34 in calculator and i didn't see 12 !!
how can fix that?

Except this method to send key i can send key with System::Call ???
before that you say can send key with keybd_event() and SendInput() , is possible give me a example from keybd_event() and SendInput() for send key?
Thanks
r2du-soft is offline   Reply With Quote