Что нового

Работа с всплывающими окнами и вывод динамического текста в GUI

G

GenoTIP

Гость
В общем начал я разбирать библиотеку Yashied`а из вот этой темы http://autoit-script.ru/index.php/topic,2263.0.html

Решил написать простецкую програмку и вот с чем столкнулся. (выложил только саму функцию код программы в примере по ссылке выше)

Код:
Func _Popup1()
	Local $hGraphic, $hArea, $hBitmap, $hFamily, $hFont, $hFormat, $hBrush, $tLayout, $aData
	Local $sHtml,$string,$repString,$iMass,$i
	$sHtml = BinaryToString(InetRead('http://tf2.tomsk.ru/',1))
	$online = StringRegExp($sHtml , 'nbsp;
<b>(\d+)',3)
	$maxslot = StringRegExp($sHtml , 'nbsp;
<b>\d+</b>/(\d+)</td>',3)

	$iMass = UBound($maxslot)

	;_ArrayDisplay($maxslot)
	For $i=0 To $iMass-1
		$players[$i] = $online[$i] & "/" & $maxslot[$i]
		$Text = $players[$i]
		;MsgBox(0,"",$Text)
	Next

	$hArea = _GDIPlus_BitmapCloneArea($hImage1, 0, 0, 133, 133, $GDIP_PXF32ARGB)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hArea)
    $hFamily = _GDIPlus_FontFamilyCreate('Tahoma')
    $hFont = _GDIPlus_FontCreate($hFamily, 12, 0, 2)
    $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hBrush = _GDIPlus_BrushCreateSolid(0xC0FFFFFF)
    _GDIPlus_GraphicsSetTextRenderingHint($hGraphic, 3)
    $aData = _GDIPlus_GraphicsMeasureString($hGraphic, $Text, $hFont, $tLayout, $hFormat)
    $tLayout = $aData[0]
    DllStructSetData($tLayout, 1, (133 - DllStructGetData($tLayout, 3)) /2 )
    DllStructSetData($tLayout, 2, (133 - DllStructGetData($tLayout, 4)) /2)
    _GDIPlus_GraphicsDrawStringEx($hGraphic, $Text, $hFont, $aData[0], $hFormat, $hBrush)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hArea)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_ImageDispose($hArea)
    If Not _Popup_IsActive($hPopup1) Then
		_Popup_Show($hPopup1,$hBitmap, 1, @DesktopWidth - 90, @DesktopHeight - 110, -1)
    Else
        _Popup_Hide($hPopup1)
    EndIf
EndFunc   ;==>_Popup1


Не могу понять, как вот в этом месте..
Код:
For $i=0 To $iMass-1
		$players[$i] = $online[$i] & "/" & $maxslot[$i]
		$Text = $players[$i]
		;MsgBox(0,"",$Text)
	Next

правильнее написать процесс занесения в $text информации типа 3/24 при том, что строка может быть не одна(!)

ну и заодно хочу узнать, можно как-то вот это сократить? трудоемкость снизить
Код:
$online = StringRegExp($sHtml , 'nbsp;
<b>(\d+)',3)
$maxslot = StringRegExp($sHtml , 'nbsp;
<b>\d+</b>/(\d+)</td>',3)
 

Viktor1703

AutoIT Гуру
Сообщения
1,535
Репутация
413
Что - то Вы напутали с массивами, не пойму что должен отобразить скрипт на POPUP окне? у меня отображает (0/12), разъясните подробнее, пока что только такой вариант:

Код:
#Include <GDIPlus.au3>
#Include <Pop-ups.au3>

Opt('TrayAutoPause', 0)

_GDIPlus_Startup()

Global $hImage1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\Image1.png'), $hImage2 = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\Image2.png')
Global $hPopup1 = _Popup_Register()

HotKeySet('{F10}', '_Popup1') ; F10

While 1
    Sleep(1000)
WEnd

_GDIPlus_Shutdown()

Func _Popup1()
   Local $hGraphic, $hArea, $hBitmap, $hFamily, $hFont, $hFormat, $hBrush, $tLayout, $aData
  
   $sHtml = BinaryToString(InetRead('http://tf2.tomsk.ru/',1))
   $online = StringRegExp($sHtml , 'nbsp;
<b>(\d+)',3)
   $maxslot = StringRegExp($sHtml , 'nbsp;
<b>\d+</b>/(\d+)</td>',3)

   For $i = 0 To UBound($maxslot) -1
	  $Text = $online[$i] & "/" & $maxslot[$i]

	  $hArea = _GDIPlus_BitmapCloneArea($hImage1, 0, 0, 133, 133, $GDIP_PXF32ARGB)
      $hGraphic = _GDIPlus_ImageGetGraphicsContext($hArea)
      $hFamily = _GDIPlus_FontFamilyCreate('Tahoma')
      $hFont = _GDIPlus_FontCreate($hFamily, 12, 0, 2)
      $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
      $hFormat = _GDIPlus_StringFormatCreate()
      $hBrush = _GDIPlus_BrushCreateSolid(0xC0FFFFFF)
      _GDIPlus_GraphicsSetTextRenderingHint($hGraphic, 3)
      $aData = _GDIPlus_GraphicsMeasureString($hGraphic, $Text, $hFont, $tLayout, $hFormat)
      $tLayout = $aData[0]
      DllStructSetData($tLayout, 1, (133 - DllStructGetData($tLayout, 3)) /2 )
      DllStructSetData($tLayout, 2, (133 - DllStructGetData($tLayout, 4)) /2)
	  _GDIPlus_GraphicsDrawStringEx($hGraphic, $Text, $hFont, $aData[0], $hFormat, $hBrush)
      $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hArea)
      _GDIPlus_GraphicsDispose($hGraphic)
      _GDIPlus_StringFormatDispose($hFormat)
      _GDIPlus_FontFamilyDispose($hFamily)
      _GDIPlus_FontDispose($hFont)
      _GDIPlus_BrushDispose($hBrush)
      _GDIPlus_ImageDispose($hArea)
	  _Popup_Show($hPopup1,$hBitmap, 1, @DesktopWidth - 90, @DesktopHeight - 110, -1)
   Next 
EndFunc   ;==>_Popup1
  
Func _GDIPlus_GraphicsSetTextRenderingHint($hGraphics, $iTextRenderingHint)

	Local $aResult = DllCall($ghGDIPDll, 'uint', 'GdipSetTextRenderingHint', 'ptr', $hGraphics, 'int', $iTextRenderingHint)

	If @error Then
		Return SetError(1, 0, 0)
	Else
		If $aResult[0] Then
			Return SetError($aResult[0], 0, 0)
		EndIf
	EndIf
	Return 1
EndFunc   ;==>_GDIPlus_GraphicsSetTextRenderingHint


Всё понял, он показывает игровые сервера?!

Код:
Steam+Vac noCrits TF2.Tomsk.ru:27018 
Mix server
mge_training_v7 	 
0/12

Тогда работает.
 

Zaramot

I ♥ AutoIt
Сообщения
1,160
Репутация
660
Так ?:
Код:
Global $Text

For $i=0 To $iMass-1
    $players[$i] = $online[$i] & "/" & $maxslot[$i]
    $Text = $Text & $players[$i] & @CRLF
Next

MsgBox(0,"",$Text)
 
Автор
G

GenoTIP

Гость
Viktor1703
ваш пример работает примерно правильно, но вот он отображает только последнюю строчку массива (0/12) А там их 3
получается так: в переменную текст заносится сначала 1, 2, 3 строчка и он их должен поочередно вывести в попапе
 

Viktor1703

AutoIT Гуру
Сообщения
1,535
Репутация
413
Честно говоря не пойму почему текст не пишется, попробуйте запустить этот скрипт и в консоле Вы увидите все 3 значения серверов, но на POPUP окне он не пишется.

Код:
#Include <GDIPlus.au3>
#Include <Pop-ups.au3>

Opt('TrayAutoPause', 0)

_GDIPlus_Startup()

Global $hImage1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\Image1.png'), $hImage2 = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\Image2.png')
Global $hPopup1 = _Popup_Register()

HotKeySet('{F10}', '_Popup1') ; F10

While 1
    Sleep(1000)
WEnd

_GDIPlus_Shutdown()

Func _Popup1()
   Local $hGraphic, $hArea, $hBitmap, $hFamily, $hFont, $hFormat, $hBrush, $tLayout, $aData
  
   $sHtml = BinaryToString(InetRead('http://tf2.tomsk.ru/',1))
   $online = StringRegExp($sHtml , 'nbsp;
<b>(\d+)',3)
   $maxslot = StringRegExp($sHtml , 'nbsp;
<b>\d+</b>/(\d+)</td>',3)
   
   Local $Text = ""
   
   For $i = 0 To UBound($maxslot) -1
	  $Text &= $online[$i] & "/" & $maxslot[$i] & @CRLF
   Next 
   
   ConsoleWrite($Text & @CRLF)
   
   $hArea = _GDIPlus_BitmapCloneArea($hImage1, 0, 0, 133, 133, $GDIP_PXF32ARGB)
   $hGraphic = _GDIPlus_ImageGetGraphicsContext($hArea)
   $hFamily = _GDIPlus_FontFamilyCreate('Tahoma')
   $hFont = _GDIPlus_FontCreate($hFamily, 8, 0, 2)
   $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
   $hFormat = _GDIPlus_StringFormatCreate()
   $hBrush = _GDIPlus_BrushCreateSolid(0xC0FFFFFF)
   _GDIPlus_GraphicsSetTextRenderingHint($hGraphic, 3)
   $aData = _GDIPlus_GraphicsMeasureString($hGraphic, $Text, $hFont, $tLayout, $hFormat)
   $tLayout = $aData[0]
   DllStructSetData($tLayout, 1, (133 - DllStructGetData($tLayout, 3)) /2 )
   DllStructSetData($tLayout, 2, (133 - DllStructGetData($tLayout, 4)) /2)
   _GDIPlus_GraphicsDrawStringEx($hGraphic, $Text, $hFont, $aData[0], $hFormat, $hBrush)
   $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hArea)
   _GDIPlus_GraphicsDispose($hGraphic)
   _GDIPlus_StringFormatDispose($hFormat)
   _GDIPlus_FontFamilyDispose($hFamily)
   _GDIPlus_FontDispose($hFont)
   _GDIPlus_BrushDispose($hBrush)
   _GDIPlus_ImageDispose($hArea)
   _Popup_Show($hPopup1,$hBitmap, 1, @DesktopWidth - 90, @DesktopHeight - 110, -1)
   
EndFunc   ;==>_Popup1
  
Func _GDIPlus_GraphicsSetTextRenderingHint($hGraphics, $iTextRenderingHint)

	Local $aResult = DllCall($ghGDIPDll, 'uint', 'GdipSetTextRenderingHint', 'ptr', $hGraphics, 'int', $iTextRenderingHint)

	If @error Then
		Return SetError(1, 0, 0)
	Else
		If $aResult[0] Then
			Return SetError($aResult[0], 0, 0)
		EndIf
	EndIf
	Return 1
EndFunc   ;==>_GDIPlus_GraphicsSetTextRenderingHint
 
Верх