Что нового

Поставить кнопку в окно с помощью StdinWrite

Sergey2210

Осваивающий
Сообщения
263
Репутация
31
Версия AutoIt:3.

Не получается поставить кнопку в окно.

Главный скрипт:
Код:
#include <GUIConstants.au3>
#include <WindowsConstants.au3>

$hForm = GUICreate("22",400,300)
$But = PluginCall(@ScriptDir & "\1.exe",'_Button('&'"'& $hForm &'"'&', 10, 10,100,20)')
GUISetState()

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
	EndSwitch
WEnd


Func PluginCall($hFile,$hFunc)
	Local $sRead = ""
    $iPid = Run($hFile, "", @SW_HIDE, 1)
    StdinWrite($iPid, '/Func:'& $hFunc)
EndFunc


Консольный:
Код:
#include <GUIConstantsEx.au3>
#include <GuiButton.au3>

$sRead = ""

Dim $Button

While 1
    Sleep(10)
    
    $sRead &= ConsoleRead()
    ;If @error Then exit
    
    If $sRead Then
        If StringLeft($sRead, 6) = "/Func:" Then
            Execute(StringTrimLeft($sRead, 6))
        ElseIf $sRead = "/Exit" Then
            Exit
        EndIf
        
        $sRead = ""
    EndIf
WEnd

Func _Button($hWnd,$left,$top,$width,$height)
	
$Button = _GUICtrlButton_Create($hWnd,"",$left,$top,$width,$height)
Return $Button

EndFunc
 

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8,671
Репутация
2,481
Главный скрипт:
Код:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hForm = GUICreate("Test", 400, 300)
$iPid = PluginCall(@ScriptDir & "\1.exe", '/Func:_Button("' & $hForm & '", 10, 10,100,20)')
GUISetState()

While 1
    $nMsg = GUIGetMsg()
	
    Switch $nMsg
		Case $GUI_EVENT_CLOSE
			PluginCall($iPid, "/Exit")
			Exit
    EndSwitch
WEnd

Func PluginCall($sFile, $sCmd)
	Local $iPid
	
	If FileExists($sFile) Then
		$iPid = Run($sFile, "", @SW_HIDE, 1)
	Else
		$iPid = $sFile
	EndIf
	
    StdinWrite($iPid, $sCmd)
	Return $iPid
EndFunc


Консольный:
Код:
#include <GUIConstantsEx.au3>
#include <GUIButton.au3>

$sRead = ""

Dim $Button

While 1
    Sleep(10)
    
    $sRead &= ConsoleRead()
    ;If @error Then exit
    
    If $sRead Then
        If StringLeft($sRead, 6) = "/Func:" Then
            Execute(StringTrimLeft($sRead, 6))
        ElseIf $sRead = "/Exit" Then
            Exit
        EndIf
        
        $sRead = ""
    EndIf
WEnd

Func _Button($hWnd,$left,$top,$width,$height)
	_GUICtrlButton_Create(HWnd($hWnd), "Button", $left, $top, $width, $height)
EndFunc
 
Автор
S

Sergey2210

Осваивающий
Сообщения
263
Репутация
31
Ошибки с вызовом функций через StdinWrite

Версия AutoIt:3.

Не получается вызвать ещё одну функцию из консольного приложения,
при закрытии главного окна консольное не закрывается и выводит ошибку,
при попытки нажать на псевдо кнопку,в данном случае Child окно ничего не
получается,получается для каждой функции нужно делать отдельное
консольное приложение....

Главный скрипт:
Код:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hForm = GUICreate("Test", 400, 300)
$iButton = PluginCall(@ScriptDir & "\Console.exe", '/Func:__Button("' & $hForm & '", 20, 20,100,20)')
GUISetState()


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
		Case $iButton
			MsgBox(0,'','')
        Case $GUI_EVENT_CLOSE
            PluginCall(@ScriptDir & "\Console.exe", "/Func:__Exit")
            Exit
    EndSwitch
WEnd

Func PluginCall($sFile, $sCmd)
    Local $iPid
    
    If FileExists($sFile) Then
        $iPid = Run($sFile, "", @SW_HIDE, 1)
    Else
        $iPid = $sFile
    EndIf
    
    StdinWrite($iPid, $sCmd)
    Return $iPid
EndFunc

Консоль:
Код:
#include <GUIConstantsEx.au3>
#include <GUIButton.au3>
 
$sRead = ""
 
While 1
    Sleep(0)
   
    $sRead &= ConsoleRead()
    If @error Then 
	    MsgBox(16,"Информация","Здесь вылазиет ошибка")
        Exit
	EndIf
	
    If $sRead Then
        If StringLeft($sRead, 6) = "/Func:" Then
            Execute(StringTrimLeft($sRead, 6))
		EndIf
       
        $sRead = ""
    EndIf
WEnd
 
Dim $cGuiButton
 
Func __Button($hWnd,$left,$top,$width,$height)
	$cGuiButton = GUICreate('',$width,$height,-1,-1,0x80000000,0x00000040,HWnd($hWnd))
	GUISetBkColor(0x000000)
	GUISetState()
	While 1
		$hPos = WinGetPos(HWnd($hWnd))
		WinMove($cGuiButton,'',$hPos[0]+$left+3,$hPos[1]+$top+29,$width,$height)
	Wend
    Return $cGuiButton
EndFunc	

Func __Exit()
	Exit
EndFunc
 

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8,671
Репутация
2,481
Re: Ошибки с вызовом функций через StdinWrite

Sergey2210 [?]
при закрытии главного окна консольное не закрывается и выводит ошибку
А зачем ты поменял $iPid на путь?
Я же специально изменил твой пример, добавив в него закрытие, зачем ты искажешь скрипт?

при попытки нажать на псевдо кнопку,в данном случае Child окно ничего не
получается
Кнопка должна обрабатываться из консольного приложения, а ты пытаешься её проверять из главного скрипта (причём не кнопку, а возвращаемый PID :D).

P.S
И почему это в новой теме, когда оно касается всё той же темы с кнопкой...



Добавлено:
Сообщение автоматически объединено:

Мне кажется, ты выбрал не тот метод интеракций для своей задачи.
 
Автор
S

Sergey2210

Осваивающий
Сообщения
263
Репутация
31
Ну так а как тогда сделать,чтоб обрабатывать сообщения
можно было в главном скрипте,я просто хочу скины для
окон делать и компилировать их в консоль,чтоб потом
можно было добавлять уже готовые скиновые кнопки,
инпуты,эдиты и т.д....
 

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8,671
Репутация
2,481
Sergey2210 [?]
чтоб обрабатывать сообщения
можно было в главном скрипте

Главный скрипт:
Код:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hAu3Title = WinGetHandle(AutoItWinGetTitle())
$hPlugin = _PluginInit(@ScriptDir & "\Console.exe")

$hForm = GUICreate("Test", 400, 300)

_PluginCall($hPlugin, '/Func:__Button(' & $hForm & ', "Button", 20, 20, 100, 20)')
GUISetState()
_PluginCall($hPlugin, '/Hwnd:' & $hAu3Title)

AdlibRegister("_CheckButtonProc", 100)

While 1
    $nMsg = GUIGetMsg()
	
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _PluginCall($hPlugin, "/Func:__Exit()")
            Exit
    EndSwitch
WEnd

Func _CheckButtonProc()
	$nButton = ControlGetText($hAu3Title, "", "Edit1")
	
	If $nButton <> "" Then
		ControlSetText($hAu3Title, "", "Edit1", "")
		MsgBox(64, 'Title', 'Button pressed: ' & $nButton, 0, $hForm)
	EndIf
EndFunc

Func _PluginInit($sFile)
	Return Run($sFile, "", @SW_HIDE, 1)
EndFunc

Func _PluginCall($iPid, $sCmd)
	StdinWrite($iPid, $sCmd)
	Sleep(200)
EndFunc


Консоль:
Код:
#include <GUIConstantsEx.au3>
#include <GUIButton.au3>

Global $sRead = ""
Global $hMoveButton = 0
Global $hGUI = 0
Global $nGuiButton = 0
Global $hMain = 0
Global $iLeft, $iTop, $iWidth, $iHeight

Opt("GUIOnEventMode", 1)

While 1
    Sleep(10)
   
    $sRead = ConsoleRead()
    
    If $sRead Then
        Switch StringLeft($sRead, 6)
			Case "/Func:"
				Execute(StringTrimLeft($sRead, 6))
			Case "/Hwnd:"
				$hMain = HWnd(StringTrimLeft($sRead, 6))
        EndSwitch
		
        $sRead = ""
    EndIf
	
	If $hMoveButton Then
		$hPos = WinGetPos($hMoveButton)
        WinMove($hGUI, '', $hPos[0]+$iLeft+3, $hPos[1]+$iTop+29, $iWidth, $iHeight)
	EndIf
WEnd
 
Func __Button($hWnd, $text, $left, $top, $width, $height)
	Dim $iLeft = $left, $iTop = $top, $iWidth = $width, $iHeight = $height
	
    $hGUI = GUICreate('', $width, $height, -1, -1, 0x80000000, 0x00000040, HWnd($hWnd))
	$nGuiButton = GUICtrlCreateButton($text, 0, 0, $width, $height)
	GUICtrlSetOnEvent(-1, "__Events")
    GUISetBkColor(0x000000)
    GUISetState()
	
	$hMoveButton = HWnd($hWnd)
EndFunc 

Func __Events()
	ControlSetText($hMain, "", "Edit1", $nGuiButton)
EndFunc

Func __Exit()
	Exit
EndFunc


Это всего лишь набросок, я бы этим не пользовался.
 
Верх