Что нового

Обновление GUI при перетаскивании

gloss

Ленивое кодило
Сообщения
155
Репутация
5
2 способа и что один, что другой не обновляет Label при перетаскивании.
Код:
Global Const $GUI_EVENT_CLOSE = -3
Global Const $GUI_WS_EX_PARENTDRAG = 0x00100000
Global Const $SS_CENTER = 0x1
Global Const $SS_CENTERIMAGE = 0x0200
Global Const $WS_EX_TOOLWINDOW = 0x00000080
Global Const $WS_EX_TOPMOST = 0x00000008
Global Const $WS_POPUP = 0x80000000
Global $time[3]
$Form1 = GUICreate('', 249, 81, Default, Default, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
$sTime = GUICtrlCreateLabel('', 0, 0, 249, 81, BitOR($SS_CENTER,$SS_CENTERIMAGE), $GUI_WS_EX_PARENTDRAG)
GUICtrlSetFont(-1, 48, 400, 0, 'Arial')
GUISetState(@SW_SHOW)
time()
$t = TimerInit()
While 1
	If TimerDiff($t) > 1000 Then
		tleft()
		$t = TimerInit()
	EndIf

	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit

	EndSwitch
WEnd

Func time()
	$time1 = StringSplit('00:01:10', ':', 2)
	$time[0] = $time1[0]
	$time[1] = $time1[1]
	$time[2] = $time1[2]
EndFunc

Func tleft()
	If $time[0] = 0 And $time[1] = 0 And $time[2] = 0 Then
		Exit
	EndIf
	If $time[1] = 0 And $time[2] = 0 Then
		$time[0] -= 1
		$time[1] = 59
		$time[2] = 60
	EndIf
	If $time[2] = 0 Then
		$time[2] = 60
		$time[1] -= 1
	EndIf
	$time[2] -= 1
	GUICtrlSetData($sTime, StringFormat('%02d:%02d:%02d', $time[0], $time[1], $time[2]))
EndFunc
Код:
#include <SendMessage.au3>
#include <WinAPI.au3>
Global Const $GUI_EVENT_CLOSE = -3
Global Const $GUI_RUNDEFMSG = 'GUI_RUNDEFMSG'
Global Const $SC_DRAGMOVE = 0xF012
Global Const $SS_CENTER = 0x1
Global Const $SS_CENTERIMAGE = 0x0200
Global Const $WM_NCHITTEST = 0x0084
Global Const $WM_WINDOWPOSCHANGING = 0x0046
Global Const $WS_EX_TOOLWINDOW = 0x00000080
Global Const $WS_EX_TOPMOST = 0x00000008
Global Const $WS_POPUP = 0x80000000
Global $time[3]
$Form1 = GUICreate('', 249, 81, Default, Default, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
$sTime = GUICtrlCreateLabel('', 0, 0, 249, 81, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlSetFont(-1, 48, 400, 0, 'Arial')
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NCHITTEST, 'WM_NCHITTEST')
GUIRegisterMsg($WM_WINDOWPOSCHANGING, 'WM_WINDOWPOSCHANGING')
time()
$t = TimerInit()
While 1
	If TimerDiff($t) > 1000 Then
		tleft()
		$t = TimerInit()
	EndIf

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

Func time()
	$time1 = StringSplit('00:01:10', ':', 2)
	$time[0] = $time1[0]
	$time[1] = $time1[1]
	$time[2] = $time1[2]
EndFunc

Func tleft()
	If $time[0] = 0 And $time[1] = 0 And $time[2] = 0 Then
		Exit
	EndIf
	If $time[1] = 0 And $time[2] = 0 Then
		$time[0] -= 1
		$time[1] = 59
		$time[2] = 60
	EndIf
	If $time[2] = 0 Then
		$time[2] = 60
		$time[1] -= 1
	EndIf
	$time[2] -= 1
	GUICtrlSetData($sTime, StringFormat('%02d:%02d:%02d', $time[0], $time[1], $time[2]))
EndFunc

Func WM_WINDOWPOSCHANGING($hWnd, $Msg, $wParam, $lParam)
    Local $stWinPos = DllStructCreate("uint;uint;int;int;int;int;uint", $lParam)

    Local $iLeft = DllStructGetData($stWinPos, 3)
    Local $iTop = DllStructGetData($stWinPos, 4)
    Local $iWidth = DllStructGetData($stWinPos, 5)
    Local $iHeight = DllStructGetData($stWinPos, 6)

    Local $aGUI_Pos = WinGetPos($hWnd)

    If $iHeight < $aGUI_Pos[3] Then
        $iNew_Top = -($aGUI_Pos[3]-$iHeight)-18 ;I am not sure that 18 will fit for all
        DllStructSetData($stWinPos, 4, $iNew_Top)
    EndIf
EndFunc

Func WM_NCHITTEST($hWnd, $iMsg, $wParam, $lParam)
    If $hWnd <> $Form1 Or $iMsg <> $WM_NCHITTEST Then Return $GUI_RUNDEFMSG

    Local $iRet = _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam)
    If $iRet = 1 Then Return 2

    Return $iRet
EndFunc
 
A

Alofa

Гость
OffTopic:
Стал разбирать и возник вот такой же вопрос? Т.е. где взять инфу по "SC_DRAGMOVE"?
Интуитивно конечно понятно, но хотелось бы документального подтверждения. А его чей-то не нашел в MSDN :shok:
 
Автор
G

gloss

Ленивое кодило
Сообщения
155
Репутация
5
InnI сказал(а):
Хмм, скрипт делает обратное, но не останавливается при перетаскивании, надо копать :ok:


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

Как-то так :smile:
Код:
#include <SendMessage.au3>
#include <Timers.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $time[3], $iTimer
$Form1 = GUICreate('', 249, 81, Default, Default, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
$sTime = GUICtrlCreateLabel('00:01:10', 0, 0, 249, 81, BitOR($SS_CENTER,$SS_CENTERIMAGE), $GUI_WS_EX_PARENTDRAG)
GUICtrlSetFont(-1, 48, 400, 0, 'Arial')
GUISetState(@SW_SHOW)
time()
$iTimer = TimerInit()
_Timer_SetTimer($Form1, 1000, 'tleft')

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
	EndSwitch
WEnd
_Timer_KillAllTimers($Form1)
Func time()
	$time1 = StringSplit('00:01:10', ':', 2)
	$time[0] = $time1[0]
	$time[1] = $time1[1]
	$time[2] = $time1[2]
EndFunc

Func tleft($hWnd, $Msg, $iIDTimer, $dwTim)
	If $time[0] = 0 And $time[1] = 0 And $time[2] = 0 Then
		Exit
	EndIf
	If $time[1] = 0 And $time[2] = 0 Then
		$time[0] -= 1
		$time[1] = 59
		$time[2] = 60
	EndIf
	If $time[2] = 0 Then
		$time[2] = 60
		$time[1] -= 1
	EndIf
	$time[2] -= 1
	GUICtrlSetData($sTime, StringFormat('%02d:%02d:%02d', $time[0], $time[1], $time[2]))
EndFunc
 
Верх