Sign in to follow this  
Followers 0
Lapo

Dllcall Playing

8 posts in this topic

#1 ·  Posted (edited)

DllCall playing

(thanks Larry)

;Declare Function ShowWindow Lib "user32" Alias "ShowWindow" 
;(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
;Global Const $SW_SHOWNORMAL = 5

 DllCall("Shell32.dll", "int", "ShellExecute", "hwnd", 0, "str", 'open', "str","calc.exe", "str", '', "str", @WorkingDir, "int", 10)
sleep(500)
 $hwndCalc = DllCall("user32.dll","long","FindWindow","str","SciCalc","str","Calculator")
;MsgBox(262144, "",@error )
 
 DllCall("Shell32.dll", "int", "ShellExecute", "hwnd", 0, "str", 'open', "str","c:\windows\notepad.exe", "str", '', "str", @WorkingDir, "int", 10)

Sleep(500)
$hwnd  = DllCall("user32.dll","long","FindWindow","str","Notepad","str","Untitled - Notepad")
 
 $hwnd3 = DLLCall("user32.dll","long","FindWindowEx","hwnd",$hwnd[0] ,"int","0","int","","int","")
  
  MsgBox(262144, ""," Notepad's Edit hwnd  " & $hwnd3[0])
 
;Declare Function ShowWindow Lib "user32" Alias "ShowWindow" 
; (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

$EM_SETSEL= 177
 $SW_RESTORE = 9
 $SW_SHOWMAXIMIZED = 3
 $SW_SHOWNORMAL = 1
 $WM_CLOSE = 16
$WM_SETTEXT = 12
 
 $ret3 = DLLCall("user32.dll","long","ShowWindow","hwnd",$hwndCalc[0],"int", $SW_SHOWMAXIMIZED )
 $goal = DLLCall("user32.dll","long","SetForegroundWindow","hwnd",$hwndCalc[0])
 
 Sleep(1000)
  $goal = DLLCall("user32.dll","long","SetForegroundWindow","hwnd",$hwnd[0])
 

 #cs
  $ret = DLLCall("user32.dll","int","AttachThreadInput","long",$me[0],"long",$you[0],"int",1)
  If $ret[0] = 0 Then Return 0
 #ce
  
 
 $ret = DLLCall("user32.dll","long","SendMessage","hwnd",$hwnd3[0],"int",$WM_SETTEXT,"int","","str","ciao2")
Sleep(2000)
DLLCall("user32.dll","long","SendMessage","hwnd",$hwnd3[0],"int",$EM_SETSEL,"int",0,"int",-1)
  
  
    $goal = DLLCall("user32.dll","long","SetForegroundWindow","hwnd",$hwnd[0])
;;;;;;;While 1  buono anche questo
For $i = 1 to 20
$f = DllCall("user32","int","FlashWindow","hwnd",$hwnd[0],"int",1)
sleep(100)
;;;;;;;;;Wend
Next
  
  
  $WM_GETTEXTLENGTH = 14
  $ret = DLLCall("user32.dll","long","SendMessage","hwnd",$hwnd3[0],"int",$WM_GETTEXTLENGTH)
  MsgBox(262144, "", $ret[0])
  $WM_GETTEXT = 13
  $ret = DLLCall("user32.dll","long","SendMessage","hwnd",$hwnd3[0],"int",$WM_GETTEXT ,"int","","str","ciao2")
  MsgBox(262144, "", $ret[0])
  
  #cs
  Declare Function SetClipboardData Lib "user32" Alias "SetClipboardDataA" 
  (ByVal wFormat As Long, ByVal hMem As Long) As Long

   DLLCall("user32.dll","long","SetClipboardData","long",$WM_SETTEXT,"str","Cippo")
  msgBox(262144, "", @error)
   $get = DLLCall("user32.dll","long","GetClipboardData","int","$WM_GETTEXT")
  msgBox(262144, "", @error)
    #ce
;Declare Function CloseWindow Lib "user32" Alias "CloseWindow" 
; (ByVal hwnd As Long) As Long
  
  $ret = DLLCall("user32.dll","long","PostMessage","hwnd",$hwnd[0],"int",$WM_CLOSE,"int","","int","")
;MsgBox(262144, "", @error)
 
; DLLCall("user32.dll","int","AttachThreadInput","long",$me[0],"long",$you[0],"int",0)

$ret3 = DLLCall("user32.dll","long","ShowWindow","hwnd",$hwndCalc[0],"int",  $SW_SHOWNORMAL )
 MsgBox(262144, "", "Calc hwnd  "&$hwndCalc[0])
sleep(2000)
MsgBox(262144, "", "Mininizing")
DLLCall("user32.dll","long","CloseWindow","hwnd",$hwndCalc[0])
MsgBox(262144, "", "Closing")

; to check
;$ret = DLLCall("user32.dll","long","PostMessage","hwnd",$hwndCalc[0],"int",$WM_CLOSE,"int","","int","")

#cs
Func _MakeLong($LoWord,$HiWord)
  Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc
#ce
Edited by Lapo

Share this post


Link to post
Share on other sites



DllCall playing

(thanks Larry)

$hwndCalc = DllCall("user32.dll","long","FindWindow","str","SciCalc","str","Calculator")

;Declare Function ShowWindow Lib "user32" Alias "ShowWindow" 
;(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
;Global Const $SW_SHOWNORMAL = 5

 DllCall("Shell32.dll", "int", "ShellExecute", "hwnd", 0, "str", 'open', "str","c:\windows\calc.exe", "str", '', "str", @WorkingDir, "int", 10)
sleep(500)
 $hwndCalc = DllCall("user32.dll","long","FindWindow","str","SciCalc","str","Calculator")
;MsgBox(262144, "",@error )
 
 DllCall("Shell32.dll", "int", "ShellExecute", "hwnd", 0, "str", 'open', "str","c:\windows\notepad.exe", "str", '', "str", @WorkingDir, "int", 10)

Sleep(500)
$hwnd  = DllCall("user32.dll","long","FindWindow","str","Notepad","str","Untitled - Notepad")
 
 $hwnd3 = DLLCall("user32.dll","long","FindWindowEx","hwnd",$hwnd[0] ,"int","0","int","","int","")
  
  MsgBox(262144, ""," Notepad's Edit hwnd  " & $hwnd3[0])
 
;Declare Function ShowWindow Lib "user32" Alias "ShowWindow" 
; (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

$EM_SETSEL= 177
 $SW_RESTORE = 9
 $SW_SHOWMAXIMIZED = 3
 $SW_SHOWNORMAL = 1
 $WM_CLOSE = 16
$WM_SETTEXT = 12
 
 $ret3 = DLLCall("user32.dll","long","ShowWindow","hwnd",$hwndCalc[0],"int", $SW_SHOWMAXIMIZED )
 $goal = DLLCall("user32.dll","long","SetForegroundWindow","hwnd",$hwndCalc[0])
 
 Sleep(1000)
  $goal = DLLCall("user32.dll","long","SetForegroundWindow","hwnd",$hwnd[0])
 

 
;  $ret = DLLCall("user32.dll","int","AttachThreadInput","long",$me[0],"long",$you[0],"int",1)
;  If $ret[0] = 0 Then Return 0
 
  
 
 $ret = DLLCall("user32.dll","long","SendMessage","hwnd",$hwnd3[0],"int",$WM_SETTEXT,"int","","str","ciao2")
Sleep(2000)
DLLCall("user32.dll","long","SendMessage","hwnd",$hwnd3[0],"int",$EM_SETSEL,"int",0,"int",-1)
  
  
    $goal = DLLCall("user32.dll","long","SetForegroundWindow","hwnd",$hwnd[0])
;;;;;;;While 1  buono anche questo
For $i = 1 to 20
$f = DllCall("user32","int","FlashWindow","hwnd",$hwnd[0],"int",1)
sleep(100)
;msgbox(0, "", $f) 
Next
  
  
  $WM_GETTEXTLENGTH = 14
  $ret = DLLCall("user32.dll","long","SendMessage","hwnd",$hwnd3[0],"int",$WM_GETTEXTLENGTH)
  MsgBox(262144, "", $ret[0])
  $WM_GETTEXT = 13
  $ret = DLLCall("user32.dll","long","SendMessage","hwnd",$hwnd3[0],"int",$WM_GETTEXT ,"int","","str","ciao2")
  MsgBox(262144, "", $ret[0])
  
  #cs
  Declare Function SetClipboardData Lib "user32" Alias "SetClipboardDataA" 
  (ByVal wFormat As Long, ByVal hMem As Long) As Long

   DLLCall("user32.dll","long","SetClipboardData","long",$WM_SETTEXT,"str","Cippo")
  msgBox(262144, "", @error)
   $get = DLLCall("user32.dll","long","GetClipboardData","int","$WM_GETTEXT")
  msgBox(262144, "", @error)
    #ce
;Declare Function CloseWindow Lib "user32" Alias "CloseWindow" 
; (ByVal hwnd As Long) As Long
  
  $ret = DLLCall("user32.dll","long","PostMessage","hwnd",$hwnd[0],"int",$WM_CLOSE,"int","","int","")
;MsgBox(262144, "", @error)
  If $ret[0] = 0 Then Return 0
  Sleep(100)
 
; DLLCall("user32.dll","int","AttachThreadInput","long",$me[0],"long",$you[0],"int",0)

$ret3 = DLLCall("user32.dll","long","ShowWindow","hwnd",$hwndCalc[0],"int",  $SW_SHOWNORMAL )
 MsgBox(262144, "", "Calc hwnd  "&$hwndCalc[0])
sleep(2000)
MsgBox(262144, "", "Mininizing")
DLLCall("user32.dll","long","CloseWindow","hwnd",$hwndCalc[0])
MsgBox(262144, "", "Closing")
$ret = DLLCall("user32.dll","long","PostMessage","hwnd",$hwndCalc[0],"int",$WM_CLOSE,"int","","int","")

#cs
Func _MakeLong($LoWord,$HiWord)
  Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc
#ce
Hmmm, it only opens Notepad.exe for me :think:

Had to open Calc.exe manually to see what it did to that.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hmmm, it only opens Notepad.exe for me :think:

Had to open Calc.exe manually to see what it did to that.

Have you an English language OS ?

I have modified the code try it again

Edit :

arghhhhhhh >> c:\windows\calc.exe -- modified in calc.exe

Edited by Lapo

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

set windows title text

DllCall("Shell32.dll", "int", "ShellExecute", "hwnd", 0, "str", 'open', "str","c:\windows\notepad.exe", "str", '', "str", @WorkingDir, "int", 10)

Sleep(500)
$hwnd  = DllCall("user32.dll","long","FindWindow","str","Notepad","str","Untitled - Notepad")
 
 $hwnd3 = DLLCall("user32.dll","long","FindWindowEx","hwnd",$hwnd[0] ,"int","0","int","","int","")
   #cs
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" 
(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" 
(ByVal hwnd As Long, ByVal lpString As String) As Long

  #ce
  
 $result = DllCall("user32.dll", "int", "GetWindowText", "hwnd", $hwnd[0], "str", "", "int", 32768)
msgbox(0, "", $result[0]); number of chars returned
msgbox(0, "", $result[2]); Text returned in param 2
$result = DllCall("user32.dll", "long", "SetWindowText", "hwnd", $hwnd[0], "str", "ciao")

; get class

DllCall("Shell32.dll", "int", "ShellExecute", "hwnd", 0, "str", 'open', "str","c:\windows\notepad.exe", "str", '', "str", @WorkingDir, "int", 10)


;Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, 
;ByVal lpWindowName As String) As Long
Sleep(500)
$hwnd  = DllCall("user32.dll","long","FindWindow","str","Notepad","str","Untitled - Notepad")
MsgBox(262144, "", _WinGetClassName($hWnd[0]))

#cs
Declare Function GetClassName Lib "user32" Alias "GetClassNameA"
 (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
#ce

Func _WinGetClassName($hWnd)
    $x = DLLCall("user32.dll","int","GetClassName","hWnd",$hWnd,"str","","int",64)
    If Not @error And $x[0] <> 0 Then Return $x[2]
    Return ""
EndFunc
Edited by Lapo

Share this post


Link to post
Share on other sites

Move window

$SW_RESTORE = 9
 $SW_SHOWMAXIMIZED = 3
 $SW_SHOWNORMAL = 1
 $SW_HIDE = 0
run("notepad")
  Sleep(500)
$hwnd  = DllCall("user32.dll","long","FindWindow","str","Notepad","str","Untitled - Notepad")
DLLCall("user32.dll","long","MoveWindow","hwnd",$hwnd[0],"ptr","0","ptr","10","ptr","300","ptr","300","int","1")

DLLCall("user32.dll","long","ShowWindow","hwnd",$hwnd[0],"int", $SW_HIDE)
sleep(300)
DLLCall("user32.dll","long","MoveWindow","hwnd",$hwnd[0],"ptr","0","ptr","10","ptr","300","ptr","300","int","1")
 ;MsgBox(262144, "", @error)
  
  Sleep(1000)
  DLLCall("user32.dll","long","ShowWindow","hwnd",$hwnd[0],"int",$SW_RESTORE)

Share this post


Link to post
Share on other sites

Have you an English language OS ?

I have modified the code try it again

Edit :

arghhhhhhh >> c:\windows\calc.exe -- modified in calc.exe

Sorry I never replied, yes it worked.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Sorry I never replied, yes it worked.

Yes I forgot calc.exe is NOT in c:\windows on XP

I have not figured out why :

$ret = DLLCall("user32.dll","long","PostMessage","hwnd",$hwnd[0],"int",$WM_CLOSE,"int","","int","")

works with notepad but NOT with calc.exe :- (

EDIT :

it doesn't work with VB6 too ... CTRL+ALT+CAN and calc is still there

Vb6 code

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal _
 lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal _
 hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal _
 hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Const SW_SHOWNORMAL = 1
Const WM_CLOSE = &H10
Const gcClassnameCALC = "SciCalc"
Const gcClassnameNotePad = "Notepad"
Const gcClassnameMyVBApp = "ThunderForm"

Private Sub Form_Load()
    Dim WinWnd As Long, Ret As String, RetVal As Long, lpClassName As String
    WinWnd = FindWindow("SciCalc", "Calcolatrice")
     'WinWnd = FindWindow("Notepad", "Senza nome - Blocco note")
    lpClassName = Space(256)
    RetVal = GetClassName(WinWnd, lpClassName, 256)
    PostMessage WinWnd, WM_CLOSE, 0&, 0&
     
End Sub
Edited by Lapo

Share this post


Link to post
Share on other sites

GetSystemMetrics Simple

;Declare Function GetSystemMetrics Lib "user32" 
;Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long

$SM_CYDOUBLECLK = 37
$SM_MOUSEPRESENT = 19 ; true or false
$SM_SWAPBUTTON = 23 ; true or false
$SM_CXFULLSCREEN = 16;Width of client area of maximized window
$SM_CYFULLSCREEN = 17;Height of client area of maximized window
$SM_CXICON = 11;Width of standard icon
$SM_CYICON = 12; Height of standard icon
 

 $Get = DllCall("user32.dll","long","GetSystemMetrics","int",$SM_CYDOUBLECLK)
;MsgBox(262144, "",@error )
MsgBox(262144, "","double click area   " & $Get[0])
 $Get = DllCall("user32.dll","long","GetSystemMetrics","int",$SM_MOUSEPRESENT )
MsgBox(262144, "","Is Mouse present ?  " &$Get[0])
$Get = DllCall("user32.dll","long","GetSystemMetrics","int",$SM_SWAPBUTTON )
MsgBox(262144, "", "Is Mouse swaped ?   "& $Get[0])
$Client1 = DllCall("user32.dll","long","GetSystemMetrics","int",$SM_CXFULLSCREEN )
$Client2 = DllCall("user32.dll","long","GetSystemMetrics","int",$SM_CXFULLSCREEN )
MsgBox(262144, "", "Client Area  "& $Client1[0] & "  " & $Client2[0])
$Get = DllCall("user32.dll","long","GetSystemMetrics","int",$SM_CXICON )
$Get1 = DllCall("user32.dll","long","GetSystemMetrics","int",$SM_CYICON )
MsgBox(262144, "","Width and Height of standard icon   " & $Get[0] & "   " & $Get1[0])

; ecc

added :

apiEnums.bas WINUSER.H GetSystemMetricsFull.au3

apiEnums.zip

GetSystemMetrics_Full.au3

WINUSER.H.zip

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0