82 $this->countCtrls = 1000;
83 $this->callback = array();
97 public function createAppWindow($caption, $width, $height, $style =
null, $params =
null): mixed
99 return $this->
createWindow(
null, AppWindow, $caption, WBC_CENTER, WBC_CENTER, $width, $height, $style, $params);
117 public function createWindow($parent, $wclass, $caption, $xPos, $yPos, $width, $height, $style =
null, $params =
null): mixed
122 $parent = $parent ===
null ? 0 : $parent;
125 $style = $style ===
null ? 0 : $style;
126 $params = $params ===
null ? 0 : $params;
129 $this->
writeLog(
'Creating window: class=' . $wclass .
', caption=' . $caption .
', pos=(' . $xPos .
',' . $yPos .
'), size=(' . $width .
'x' . $height .
'), style=' . $style .
', params=' . $params);
131 $caption = empty($caption) ? $this->defaultTitle : $this->defaultTitle .
' - ' . $caption;
132 $window = $this->
callWinBinder(
'wb_create_window', array($parent, $wclass, $caption, $xPos, $yPos, $width, $height, $style, $params));
134 if ($window ===
false || $window ===
null) {
135 $this->
writeLog(
'ERROR: Failed to create window - wb_create_window returned: ' . var_export($window,
true));
137 if (!extension_loaded(
'winbinder')) {
138 $this->
writeLog(
'ERROR: WinBinder extension is not loaded!');
141 if (!function_exists(
'wb_create_window')) {
142 $this->
writeLog(
'ERROR: wb_create_window function does not exist!');
145 $this->
writeLog(
'Window created successfully: handle=' . $window);
162 private function callWinBinder($function, $params = array(), $removeErrorHandler =
false): mixed
165 if (function_exists($function)) {
166 if ($removeErrorHandler) {
168 $oldErrorLevel = error_reporting(0);
169 $result = @call_user_func_array($function, $params);
170 error_reporting($oldErrorLevel);
172 $result = call_user_func_array($function, $params);
189 if ($wbobject ===
null) {
190 error_log(
'Error: $wbobject is null.');
195 if (!file_exists($path)) {
196 error_log(
'Error: Image file does not exist at path: ' . $path);
201 return $this->
callWinBinder(
'wb_set_image', array($wbobject, $path));
215 public function createNakedWindow($caption, $width, $height, $style =
null, $params =
null): mixed
217 $window = $this->
createWindow(
null, NakedWindow, $caption, WBC_CENTER, WBC_CENTER, $width, $height, $style, $params);
218 $this->
setArea($window, $width, $height);
232 public function setArea($wbobject, $width, $height): mixed
234 return $this->
callWinBinder(
'wb_set_area', array($wbobject, WBC_TITLE, 0, 0, $width, $height));
251 $windowTitle = $this->
getText($window);
262 while ($attempt < $maxAttempts && !$destroyed) {
272 $this->
exec(
'taskkill',
'/FI "WINDOWTITLE eq ' . $windowTitle .
'" /F',
true);
276 if (!empty($currentPid)) {
277 $this->
exec(
'taskkill',
'/PID ' . $currentPid .
' /T /F',
true);
278 $this->
writeLog(
'Force-killed PID: ' . $currentPid .
' for window: ' . $window);
283 $this->
callWinBinder(
'wb_destroy_window', array($window),
true);
303 return $this->
callWinBinder(
'wb_get_text', array($wbobject));
319 $text = $this->
callWinBinder(
'wb_get_text', array($window),
true);
320 return ($text !==
false);
342 public function exec($cmd, $params =
null, $silent =
false): mixed
348 $cmd =
'wscript.exe';
349 $params = !empty($params) ? $silent .
' "' . $params .
'"' : $silent;
352 $this->
writeLog(
'exec: ' . $cmd .
' ' . $params);
354 return $this->
callWinBinder(
'wb_exec', array($cmd, $params));
387 return $this->
callWinBinder(
'wb_refresh', array($wbobject,
true));
399 return $this->
callWinBinder(
'wb_get_system_info', array($info));
414 public function drawImage($wbobject, $path, $xPos = 0, $yPos = 0, $width = 0, $height = 0): mixed
416 $image = $this->
callWinBinder(
'wb_load_image', array($path));
418 return $this->
callWinBinder(
'wb_draw_image', array($wbobject, $image, $xPos, $yPos, $width, $height));
434 public function drawText($parent, $caption, $xPos, $yPos, $width =
null, $height =
null, $font =
null)
437 $caption = $caption ===
null ?
'' : $caption;
438 $caption = str_replace(self::NEW_LINE, PHP_EOL, $caption);
439 $width = $width ==
null ? 120 : $width;
440 $height = $height ==
null ? 25 : $height;
442 return $this->
callWinBinder(
'wb_draw_text', array($parent, $caption, $xPos, $yPos, $width, $height, $font));
458 public function drawRect($parent, $xPos, $yPos, $width, $height, $color = 15790320, $filled =
true)
460 return $this->
callWinBinder(
'wb_draw_rect', array($parent, $xPos, $yPos, $width, $height, $color, $filled));
476 public function drawLine($wbobject, $xStartPos, $yStartPos, $xEndPos, $yEndPos, $color, $height = 1)
478 return $this->
callWinBinder(
'wb_draw_line', array($wbobject, $xStartPos, $yStartPos, $xEndPos, $yEndPos, $color, $height));
491 public function createFont($fontName, $size =
null, $color =
null, $style =
null)
493 return $this->
callWinBinder(
'wb_create_font', array($fontName, $size, $color, $style));
503 public function wait($wbobject =
null)
505 return $this->
callWinBinder(
'wb_wait', array($wbobject),
true);
518 return $this->
callWinBinder(
'wb_destroy_timer', array($wbobject, $timerobject));
546 public function setHandler($wbobject, $classCallback, $methodCallback, $launchTimer =
null)
548 if ($launchTimer !=
null) {
549 $launchTimer = $this->
createTimer($wbobject, $launchTimer);
552 $this->callback[$wbobject] = array($classCallback, $methodCallback, $launchTimer);
554 return $this->
callWinBinder(
'wb_set_handler', array($wbobject,
'__winbinderEventHandler'));
570 self::CTRL_ID => $this->countCtrls,
571 self::CTRL_OBJ => $this->
callWinBinder(
'wb_create_timer', array($wbobject, $this->countCtrls, $wait))
586 $content = $content ===
null ?
'' : $content;
587 $content = str_replace(self::NEW_LINE, PHP_EOL, $content);
589 return $this->
callWinBinder(
'wb_set_text', array($wbobject, $content));
611 return $this->
callWinBinder(
'wb_set_focus', array($wbobject));
623 return $this->
callWinBinder(
'wb_get_enabled', array($wbobject));
648 return $this->
callWinBinder(
'wb_set_enabled', array($wbobject, $enabled));
661 return $this->
callWinBinder(
'wb_set_style', array($wbobject, $style));
675 return $this->
callWinBinder(
'wb_sys_dlg_path', array($parent, $title, $path));
688 public function sysDlgOpen($parent, $title, $filter =
null, $path =
null)
690 return $this->
callWinBinder(
'wb_sys_dlg_open', array($parent, $title, $filter, $path));
707 public function createLabel($parent, $caption, $xPos, $yPos, $width =
null, $height =
null, $style =
null, $params =
null)
709 $caption = str_replace(self::NEW_LINE, PHP_EOL, $caption);
710 $width = $width ==
null ? 120 : $width;
711 $height = $height ==
null ? 25 : $height;
713 return $this->
createControl($parent, Label, $caption, $xPos, $yPos, $width, $height, $style, $params);
731 public function createControl($parent, $ctlClass, $caption, $xPos, $yPos, $width, $height, $style =
null, $params =
null)
736 $style = $style ===
null ? 0 : $style;
737 $params = $params ===
null ? 0 : $params;
740 self::CTRL_ID => $this->countCtrls,
741 self::CTRL_OBJ => $this->
callWinBinder(
'wb_create_control', array(
771 public function createInputText($parent, $value, $xPos, $yPos, $width =
null, $height =
null, $maxLength =
null, $style =
null, $params =
null)
774 $value = $value ===
null ?
'' : $value;
775 $value = str_replace(self::NEW_LINE, PHP_EOL, $value);
776 $width = $width ==
null ? 120 : $width;
777 $height = $height ==
null ? 25 : $height;
778 $inputText = $this->
createControl($parent, EditBox, (
string)$value, $xPos, $yPos, $width, $height, $style, $params);
779 if (is_numeric($maxLength) && $maxLength > 0) {
780 $this->
setMaxLength($inputText[self::CTRL_OBJ], $maxLength);
798 return $this->
callWinBinder(
'wb_send_message', array($wbobject, 0x00c5, $length, 0),
true);
815 public function createEditBox($parent, $value, $xPos, $yPos, $width =
null, $height =
null, $style =
null, $params =
null)
817 $value = str_replace(self::NEW_LINE, PHP_EOL, $value);
818 $width = $width ==
null ? 540 : $width;
819 $height = $height ==
null ? 340 : $height;
820 $editBox = $this->
createControl($parent, RTFEditBox, (
string)$value, $xPos, $yPos, $width, $height, $style, $params);
839 public function createHyperLink($parent, $caption, $xPos, $yPos, $width =
null, $height =
null, $style =
null, $params =
null)
841 $caption = str_replace(self::NEW_LINE, PHP_EOL, $caption);
842 $width = $width ==
null ? 120 : $width;
843 $height = $height ==
null ? 15 : $height;
844 $hyperLink = $this->
createControl($parent, HyperLink, (
string)$caption, $xPos, $yPos, $width, $height, $style, $params);
845 $this->
setCursor($hyperLink[self::CTRL_OBJ], self::CURSOR_FINGER);
858 public function setCursor($wbobject, $type = self::CURSOR_ARROW)
860 return $this->
callWinBinder(
'wb_set_cursor', array($wbobject, $type));
877 public function createRadioButton($parent, $caption, $checked, $xPos, $yPos, $width =
null, $height =
null, $startGroup =
false)
879 $caption = str_replace(self::NEW_LINE, PHP_EOL, $caption);
880 $width = $width ==
null ? 120 : $width;
881 $height = $height ==
null ? 25 : $height;
883 return $this->
createControl($parent, RadioButton, (
string)$caption, $xPos, $yPos, $width, $height, $startGroup ? WBC_GROUP :
null, $checked ? 1 : 0);
900 public function createButton($parent, $caption, $xPos, $yPos, $width =
null, $height =
null, $style =
null, $params =
null)
902 $width = $width ==
null ? 80 : $width;
903 $height = $height ==
null ? 25 : $height;
905 return $this->
createControl($parent, PushButton, $caption, $xPos, $yPos, $width, $height, $style, $params);
922 public function createProgressBar($parent, $max, $xPos, $yPos, $width =
null, $height =
null, $style =
null, $params =
null)
926 $width = $width ==
null ? 200 : $width;
927 $height = $height ==
null ? 15 : $height;
930 $this->
setRange($progressBar[self::CTRL_OBJ], 0, $max);
931 $this->gauge[$progressBar[self::CTRL_OBJ]] = 0;
945 return $this->
callWinBinder(
'wb_get_value', array($wbobject));
959 return $this->
callWinBinder(
'wb_set_range', array($wbobject, $min, $max));
980 if ($progressBar !=
null && isset($progressBar[self::CTRL_OBJ]) && isset($this->gauge[$progressBar[self::CTRL_OBJ]])) {
981 if (strval($value) == self::INCR_PROGRESS_BAR) {
982 $value = $this->gauge[$progressBar[self::CTRL_OBJ]] + 1;
984 if (is_numeric($value)) {
985 $this->gauge[$progressBar[self::CTRL_OBJ]] = $value;
989 $this->
callWinBinder(
'wb_set_value', array($progressBar[self::CTRL_OBJ], $value),
true);
1004 return $this->
callWinBinder(
'wb_set_value', array($wbobject, $content));
1025 $this->
setRange($progressBar[self::CTRL_OBJ], 0, $max);
1038 return $this->
messageBox($message, self::BOX_INFO, $title);
1054 $message = str_replace(self::NEW_LINE, PHP_EOL, $message);
1057 strlen($message) < 64 ? str_pad($message, 64) : $message,
1058 $title ==
null ? $this->defaultTitle : $this->defaultTitle .
' - ' . $title,
1075 return $this->
messageBox($message, self::BOX_OK, $title);
1088 return $this->
messageBox($message, self::BOX_OKCANCEL, $title);
1101 return $this->
messageBox($message, self::BOX_QUESTION, $title);
1114 return $this->
messageBox($message, self::BOX_ERROR, $title);
1127 return $this->
messageBox($message, self::BOX_WARNING, $title);
1140 return $this->
messageBox($message, self::BOX_YESNO, $title);
1153 return $this->
messageBox($message, self::BOX_YESNOCANCEL, $title);
1173 global $bearsamppWinbinder;
1175 if ($bearsamppWinbinder->callback[$window][2] !=
null) {
1176 $bearsamppWinbinder->destroyTimer($window, $bearsamppWinbinder->callback[$window][2][0]);
1179 call_user_func_array(
1180 array($bearsamppWinbinder->callback[$window][0], $bearsamppWinbinder->callback[$window][1]),
1181 array($window, $id, $ctrl, $param1, $param2)
__winbinderEventHandler($window, $id, $ctrl, $param1, $param2)
static logInitClass($classInstance)
static logDebug($data, $file=null)
setCursor($wbobject, $type=self::CURSOR_ARROW)
messageBoxYesNoCancel($message, $title=null)
setHandler($wbobject, $classCallback, $methodCallback, $launchTimer=null)
createFont($fontName, $size=null, $color=null, $style=null)
drawLine($wbobject, $xStartPos, $yStartPos, $xEndPos, $yEndPos, $color, $height=1)
messageBox($message, $type, $title=null)
createProgressBar($parent, $max, $xPos, $yPos, $width=null, $height=null, $style=null, $params=null)
createButton($parent, $caption, $xPos, $yPos, $width=null, $height=null, $style=null, $params=null)
messageBoxError($message, $title=null)
destroyTimer($wbobject, $timerobject)
callWinBinder($function, $params=array(), $removeErrorHandler=false)
incrProgressBar($progressBar)
setImage($wbobject, $path)
setValue($wbobject, $content)
createAppWindow($caption, $width, $height, $style=null, $params=null)
createInputText($parent, $value, $xPos, $yPos, $width=null, $height=null, $maxLength=null, $style=null, $params=null)
setArea($wbobject, $width, $height)
setStyle($wbobject, $style)
setProgressBarValue($progressBar, $value)
createControl($parent, $ctlClass, $caption, $xPos, $yPos, $width, $height, $style=null, $params=null)
setRange($wbobject, $min, $max)
drawText($parent, $caption, $xPos, $yPos, $width=null, $height=null, $font=null)
createNakedWindow($caption, $width, $height, $style=null, $params=null)
messageBoxWarning($message, $title=null)
messageBoxOk($message, $title=null)
createHyperLink($parent, $caption, $xPos, $yPos, $width=null, $height=null, $style=null, $params=null)
drawRect($parent, $xPos, $yPos, $width, $height, $color=15790320, $filled=true)
resetProgressBar($progressBar)
messageBoxInfo($message, $title=null)
setText($wbobject, $content)
createRadioButton($parent, $caption, $checked, $xPos, $yPos, $width=null, $height=null, $startGroup=false)
exec($cmd, $params=null, $silent=false)
createEditBox($parent, $value, $xPos, $yPos, $width=null, $height=null, $style=null, $params=null)
sysDlgPath($parent, $title, $path=null)
messageBoxOkCancel($message, $title=null)
messageBoxQuestion($message, $title=null)
sysDlgOpen($parent, $title, $filter=null, $path=null)
setProgressBarMax($progressBar, $max)
createLabel($parent, $caption, $xPos, $yPos, $width=null, $height=null, $style=null, $params=null)
setMaxLength($wbobject, $length)
createTimer($wbobject, $wait=1000)
createWindow($parent, $wclass, $caption, $xPos, $yPos, $width, $height, $style=null, $params=null)
drawImage($wbobject, $path, $xPos=0, $yPos=0, $width=0, $height=0)
setEnabled($wbobject, $enabled=true)
messageBoxYesNo($message, $title=null)