Voici une illustration de ce que j'aimerai réaliser sur la fenêtre B:

Est-ce possible ou simple fantasme?
Code : Tout sélectionner
;==========================================================================
; Program: Add a functional button to the Windows Calculator
; Author: netmaestro
; Date: June 11, 2007
; Target Compiler: PureBasic 4.0 and later
; Target OS: Microsoft Windows XP Only
;==========================================================================
Global oldproc, quit=0, cebutton, clearbutton, one, two, three
Global four, five, six, seven, eight, nine, zero, point
Procedure ButtonProc(hwnd, msg, wParam, lParam)
Select msg
Case #WM_NCDESTROY
End
Case #WM_LBUTTONUP
SendMessage_(cebutton, #BM_CLICK, 0,0)
SendMessage_(three, #BM_CLICK, 0,0)
SendMessage_(point, #BM_CLICK, 0,0)
SendMessage_(one, #BM_CLICK, 0,0)
SendMessage_(four, #BM_CLICK, 0,0)
SendMessage_(one, #BM_CLICK, 0,0)
SendMessage_(five, #BM_CLICK, 0,0)
EndSelect
ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wParam, lParam)
EndProcedure
Procedure GetClearButtons(hwnd, param)
wt.s = Space(10)
SendMessage_(hwnd, #WM_GETTEXT, 10, @wt)
If wt = "C"
clearbutton = hwnd
ElseIf wt = "CE"
cebutton = hwnd
EndIf
ProcedureReturn 1
EndProcedure
Procedure GetNumbers(hwnd, param)
wt.s = Space(10)
SendMessage_(hwnd, #WM_GETTEXT, 10, @wt)
Select wt
Case "1" : one = hwnd
Case "2" : two = hwnd
Case "3" : three = hwnd
Case "4" : four = hwnd
Case "5" : five = hwnd
Case "6" : six = hwnd
Case "7" : seven = hwnd
Case "8" : eight = hwnd
Case "9" : nine = hwnd
Case "0" : zero = hwnd
Case "." : point = hwnd
EndSelect
ProcedureReturn 1
EndProcedure
RunProgram("calc.exe")
start = ElapsedMilliseconds()
Repeat
c = FindWindow_(0, "Calculatrice")
Delay(1)
Until c Or ElapsedMilliseconds()-start > 500
If c
EnumChildWindows_(c, @GetClearButtons(), 0)
EnumChildWindows_(c, @GetNumbers(), 0)
SetWindowPos_(clearbutton, 0,0,0,28,29,#SWP_NOZORDER|#SWP_NOMOVE|#SWP_FRAMECHANGED)
InitCommonControls_()
GetWindowRect_(c, @cr.RECT)
w = cr\right-cr\left
If w > 270 ; Scientific
button = CreateWindowEx_(0,"Button", "PI", #WS_CHILD|#WS_VISIBLE,432,62,28,29,c,0,GetModuleHandle_(0),0)
Else ; Standard
button = CreateWindowEx_(0,"Button", "PI", #WS_CHILD|#WS_VISIBLE,216,37,28,29,c,0,GetModuleHandle_(0),0)
EndIf
Else
MessageRequester("OOPS!", "Can't find the Calculator!", #MB_ICONERROR)
End
EndIf
oldproc = SetWindowLong_(button, #GWL_WNDPROC, @ButtonProc())
result = GetMessage_(@msg.MSG, #Null, #Null, #Null)
While result <> 0
If result = -1 ; GetMessage failed
MessageRequester("OOPS!", "Failure in GetMessage Loop", #MB_ICONERROR)
End
EndIf
TranslateMessage_(msg)
DispatchMessage_(msg)
result = GetMessage_(@msg.MSG, #Null, #Null, #Null)
Wend
Code : Tout sélectionner
;==========================================================================
; Program: Add a functional button to the Windows Calculator
; Author: netmaestro
;==========================================================================
Global oldproc, quit=0, cebutton, clearbutton, one, two, three
Global four, five, six, seven, eight, nine, zero, point
Procedure ButtonProc(hwnd, msg, wParam, lParam)
Select msg
Case #WM_NCDESTROY
End
Case #WM_LBUTTONUP
SendMessage_(cebutton, #BM_CLICK, 0,0)
SendMessage_(three, #BM_CLICK, 0,0)
SendMessage_(point, #BM_CLICK, 0,0)
SendMessage_(one, #BM_CLICK, 0,0)
SendMessage_(four, #BM_CLICK, 0,0)
SendMessage_(one, #BM_CLICK, 0,0)
SendMessage_(five, #BM_CLICK, 0,0)
EndSelect
ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wParam, lParam)
EndProcedure
Procedure GetClearButtons(hwnd, param)
CtrlID = GetDlgCtrlID_(hwnd)
If CtrlID = 81
clearbutton = hwnd
ElseIf CtrlID = 82
cebutton = hwnd
EndIf
ProcedureReturn 1
EndProcedure
Procedure GetNumbers(hwnd, param)
Select GetDlgCtrlID_(hwnd)
Case 124 : zero = hwnd
Case 125 : one = hwnd
Case 126 : two = hwnd
Case 127 : three = hwnd
Case 128 : four = hwnd
Case 129 : five = hwnd
Case 130 : six = hwnd
Case 131 : seven = hwnd
Case 132 : eight = hwnd
Case 133 : nine = hwnd
Case 85 : point = hwnd
EndSelect
ProcedureReturn 1
EndProcedure
CalcProgramID = RunProgram("Calc.Exe", "", "", #PB_Program_Open)
If CalcProgramID
CalcProcessID = ProgramID(CalcProgramID)
Count = 0
Repeat
Delay(100) ; Avoid hanging of windows during start of application while searching for the window
Count = Count + 1 ; Security counter to avoid hanging
WinHandle = FindWindow_(0,0)
While WinHandle <> 0
GetWindowThreadProcessId_(WinHandle, @ProcessID)
If ProcessID = CalcProcessID
c = WinHandle
Break
EndIf
WinHandle = GetWindow_(WinHandle, #GW_HWNDNEXT)
Wend
Until c Or (Count=50) ; Wait up to 5 seconds for window to occur
EndIf
If c
EnumChildWindows_(c, @GetClearButtons(), 0)
EnumChildWindows_(c, @GetNumbers(), 0)
SetWindowPos_(clearbutton, 0,0,0,28,29,#SWP_NOZORDER|#SWP_NOMOVE|#SWP_FRAMECHANGED)
InitCommonControls_()
GetWindowRect_(c, @cr.RECT)
w = cr\right-cr\left
If w > 270 ; Scientific
button = CreateWindowEx_(0,"Button", "PI", #WS_CHILD|#WS_VISIBLE,432,62,28,29,c,0,GetModuleHandle_(0),0)
Else ; Standard
button = CreateWindowEx_(0,"Button", "PI", #WS_CHILD|#WS_VISIBLE,216,37,28,29,c,0,GetModuleHandle_(0),0)
EndIf
Else
MessageRequester("OOPS!", "Can't find the Calculator!", #MB_ICONERROR)
End
EndIf
oldproc = SetWindowLong_(button, #GWL_WNDPROC, @ButtonProc())
result = GetMessage_(@msg.MSG, #Null, #Null, #Null)
While result <> 0
If result = -1 ; GetMessage failed
MessageRequester("OOPS!", "Failure in GetMessage Loop", #MB_ICONERROR)
End
EndIf
TranslateMessage_(msg)
DispatchMessage_(msg)
result = GetMessage_(@msg.MSG, #Null, #Null, #Null)
Wend
Code : Tout sélectionner
Global oldproc, quit=0, cebutton, clearbutton, one, two, three
Global four, five, six, seven, eight, nine, zero, point
Procedure ButtonProc(hwnd, msg, wParam, lParam)
Select msg
Case #WM_NCDESTROY
End
Case #WM_LBUTTONUP
SendMessage_(cebutton, #BM_CLICK, 0,0)
SendMessage_(three, #BM_CLICK, 0,0)
SendMessage_(point, #BM_CLICK, 0,0)
SendMessage_(one, #BM_CLICK, 0,0)
SendMessage_(four, #BM_CLICK, 0,0)
SendMessage_(one, #BM_CLICK, 0,0)
SendMessage_(five, #BM_CLICK, 0,0)
EndSelect
ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wParam, lParam)
EndProcedure
Procedure GetClearButtons(hwnd, param)
CtrlID = GetDlgCtrlID_(hwnd)
If CtrlID = 81
clearbutton = hwnd
ElseIf CtrlID = 82
cebutton = hwnd
EndIf
ProcedureReturn 1
EndProcedure
Procedure GetNumbers(hwnd, param)
Select GetDlgCtrlID_(hwnd)
Case 124 : zero = hwnd
Case 125 : one = hwnd
Case 126 : two = hwnd
Case 127 : three = hwnd
Case 128 : four = hwnd
Case 129 : five = hwnd
Case 130 : six = hwnd
Case 131 : seven = hwnd
Case 132 : eight = hwnd
Case 133 : nine = hwnd
Case 85 : point = hwnd
EndSelect
ProcedureReturn 1
EndProcedure
CalcProgramID = RunProgram("Calc.Exe", "", "", #PB_Program_Open)
If CalcProgramID
CalcProcessID = ProgramID(CalcProgramID)
Count = 0
Repeat
Delay(100) ; Avoid hanging of windows during start of application while searching for the window
Count = Count + 1 ; Security counter to avoid hanging
WinHandle = FindWindow_(0,0)
While WinHandle <> 0
GetWindowThreadProcessId_(WinHandle, @ProcessID)
If ProcessID = CalcProcessID
c = WinHandle
Break
EndIf
WinHandle = GetWindow_(WinHandle, #GW_HWNDNEXT)
Wend
Until c Or (Count=50) ; Wait up to 5 seconds for window to occur
EndIf
If c
EnumChildWindows_(c, @GetClearButtons(), 0)
EnumChildWindows_(c, @GetNumbers(), 0)
SetWindowPos_(clearbutton, 0,0,0,28,29,#SWP_NOZORDER|#SWP_NOMOVE|#SWP_FRAMECHANGED)
InitCommonControls_()
GetWindowRect_(c, @cr.RECT)
w = cr\right-cr\left
If w < 270 ; Standard
If OSVersion() = #PB_OS_Windows_NT_4
yPosPIButton = 46
Else
yPosPIButton = 37
EndIf
button = CreateWindowEx_(0,"Button", "PI", #WS_CHILD|#WS_VISIBLE,216,yPosPIButton,28,29,c,0,GetModuleHandle_(0),0)
EndIf
RedrawWindow_(button, 0, 0, #RDW_UPDATENOW)
Else
MessageRequester("OOPS!", "Can't find the Calculator!", #MB_ICONERROR)
End
EndIf
oldproc = SetWindowLong_(button, #GWL_WNDPROC, @ButtonProc())
result = GetMessage_(@msg.MSG, #Null, #Null, #Null)
While result <> 0
If result = -1 ; GetMessage failed
MessageRequester("OOPS!", "Failure in GetMessage Loop", #MB_ICONERROR)
End
EndIf
TranslateMessage_(msg)
DispatchMessage_(msg)
result = GetMessage_(@msg.MSG, #Null, #Null, #Null)
Wend
Code : Tout sélectionner
SendMessage_(cebutton, #BM_CLICK, 0,0)
SendMessage_(three, #BM_CLICK, 0,0)
SendMessage_(point, #BM_CLICK, 0,0)
SendMessage_(one, #BM_CLICK, 0,0)
SendMessage_(four, #BM_CLICK, 0,0)
SendMessage_(one, #BM_CLICK, 0,0)
SendMessage_(five, #BM_CLICK, 0,0)
ha bah oui !! quel âne fais-jegildev a écrit :En fait il simule l'appuie des boutons de la calculatrice, du moins je pense...
En tout cas c'est puissant, très puissant.Code : Tout sélectionner
SendMessage_(cebutton, #BM_CLICK, 0,0) SendMessage_(three, #BM_CLICK, 0,0) SendMessage_(point, #BM_CLICK, 0,0) SendMessage_(one, #BM_CLICK, 0,0) SendMessage_(four, #BM_CLICK, 0,0) SendMessage_(one, #BM_CLICK, 0,0) SendMessage_(five, #BM_CLICK, 0,0)