Jump to content

Please correct my code


Recommended Posts

Please Run this code :

#include <GuiConstants.au3>
Dim $M1 = "Title 123", $M2 = "First Label Goes Here" & @CRLF & @CRLF & "2nd Label Here..." & @CRLF & @CRLF & "3rd Label here..." & @CRLF & @CRLF & "Press OK To Continue..."
Func CMB($title,$text,$color)
    Local $L_TEXT = StringLen($text)
    Local $ROW = Int(Number($L_TEXT) / 45) + 1
    Local $GUI = GUICreate($title,316,83*Number($ROW) + 30,-1,-1)
    GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
    GUISetBkColor(0x000000)
    Global $GLOBAL_WINPOS = WinGetPos($GUI) ; Save Variable for 2)
    AdlibEnable("_SaveWinPos",100) ; 2.1) Disable Move by WinMove Or taskbar-> Move Window
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $GUI, "int", 1000, "long", 0x00040010)
    Local $icon = GUICtrlCreateIcon("shell32.dll", "240", 10, 35, 48, 48)
    Local $FIELD = GUICtrlCreateLabel($text,50,10,250,30*Number($ROW),0x01)
    GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel("Access", 15, 25, 45, 17)
    GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0x0000FF)
    $Label2 = GUICtrlCreateLabel("Denied", 15, 80, 40, 17)
    GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0x0000FF)
    $Label3 = GUICtrlCreateLabel("Info:"&@CRLF&"Some Text here..."&@CRLF&"Some Text here..."&"Some Text here..."&@CRLF&@CRLF&"Some Text here...", 8, 144, 230, 92)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFFFFFF)
    Local $OK = GUICtrlCreateButton("OK", 232, 112, 75, 25, 0)
    Local $About = GUICtrlCreateButton("About", 232, 245, 75, 25)
    GUICtrlSetColor ($FIELD,$color)
    GUISetState(@SW_SHOW,$GUI)
    GuiSetIcon(@SystemDir & "\ahui.exe", 0)
    While 1 
        $MSG = GUIGetMsg()
        $Timer=TimerInit()
        $pos = WinGetPos($M1)
        If $pos[0]<>Int((@DesktopWidth-$pos[2])/2) or $pos[1]<> Int((@DesktopHeight-$pos[3])/2) Then
            WinMove($M1,"",Int((@DesktopWidth-$pos[2])/2),Int((@DesktopHeight-$pos[3])/2))
        Endif
        If $MSG = $OK Then
            DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $GUI, "int", 1000, "long", 0x00050008);slide-out to top
            GUIDelete($GUI)
            ExitLoop
        EndIf
        If $MSG = $About Then
            DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $GUI, "int", 1000, "long", 0x00090000)
            ToolTip(@CRLF&"Name:"&@CRLF&"Company:"&@CRLF&@CRLF&"Contact:"&@CRLF&@CRLF&"This info will automatically close in 3sec.", 400, 300, " Information ", 2, 2)
            Sleep(3000)
            ToolTip("", 0, 0, "", 0)
            DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $GUI, "int", 1000, "long", 0x00080000);fade-in
        EndIf
        If TimerDiff($Timer) >= 10000 then 
            GUIDelete($GUI)
            ExitLoop
        EndIf   ;after 20 seconds exit or you could exitloop and proceed to the next part of the script
    WEnd
EndFunc
; 2.2) Disable Move by WinMove Or taskbar-> Move Window
Func _SaveWinPos()
Local $x = WinGetPos($M1)
If $x[0] <> $GLOBAL_WINPOS[0] Or _
$x[1] <> $GLOBAL_WINPOS[1] Or _
$x[2] <> $GLOBAL_WINPOS[2] Or _
$x[3] <> $GLOBAL_WINPOS[3] Then
WinMove($M1,"",$GLOBAL_WINPOS[0],$GLOBAL_WINPOS[1],$GLOBAL_WINPOS[2],$GLOBAL_WINPOS[3])
EndIf
EndFunc
; 1.2) Disable Move by titlebar
Func WM_NCHITTEST($hWnd, $Msg, $wParam, $lParam)
Local $iProc

$iProc = DllCall("user32.dll", "int", "DefWindowProc", "hwnd", $hWnd, "int", $Msg, "wparam", $wParam, "lparam", $lParam)
$iProc = $iProc[0]

If $iProc = $HTCAPTION Then Return 0

Return $GUI_RUNDEFMSG
EndFunc
;Function is called from the code given Below
CMB($M1, $M2,0x00FF00)
;Function is called from the code given Above

Problems:

1- Gui is going to be crazy

2- its not timing out

thanks in advance for help!

[font="Georgia"]GSM Expert[/font] but not AutoIt :DProud to be Admin Of : http://www.gsmhosting.net/visit my Forum... http://www.gsmhosting.net/vbb/index.php
$Life = "Happy"
If @Error Then
$Life = "Risk"
Link to comment
Share on other sites

TimerInit was in wrong place. Basically every time the loop went through, the timer was reset. You did not need some lines regarding win pos, and I change the If statements to Switch...Case...EndSwitch which makes it cleaner IMO.

EDIT: Code lol.

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
Dim $M1 = "Title 123", $M2 = "First Label Goes Here" & @CRLF & @CRLF & "2nd Label Here..." & @CRLF & @CRLF & "3rd Label here..." & @CRLF & @CRLF & "Press OK To Continue..."
$Timer=TimerInit()

Func CMB($title,$text,$color)
    Local $L_TEXT = StringLen($text)
    Local $ROW = Int(Number($L_TEXT) / 45) + 1
    Local $GUI = GUICreate($title,316,83*Number($ROW) + 30,-1,-1)
    GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
    GUISetBkColor(0x000000)
    Global $GLOBAL_WINPOS = WinGetPos($GUI); Save Variable for 2)
    AdlibEnable("_SaveWinPos",100); 2.1) Disable Move by WinMove Or taskbar-> Move Window
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $GUI, "int", 1000, "long", 0x00040010)
    Local $icon = GUICtrlCreateIcon("shell32.dll", "240", 10, 35, 48, 48)
    Local $FIELD = GUICtrlCreateLabel($text,50,10,250,30*Number($ROW),0x01)
    GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel("Access", 15, 25, 45, 17)
    GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0x0000FF)
    $Label2 = GUICtrlCreateLabel("Denied", 15, 80, 40, 17)
    GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0x0000FF)
    $Label3 = GUICtrlCreateLabel("Info:"&@CRLF&"Some Text here..."&@CRLF&"Some Text here..."&"Some Text here..."&@CRLF&@CRLF&"Some Text here...", 8, 144, 230, 92)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFFFFFF)
    Local $OK = GUICtrlCreateButton("OK", 232, 112, 75, 25, 0)
    Local $About = GUICtrlCreateButton("About", 232, 245, 75, 25)
    GUICtrlSetColor ($FIELD,$color)
    GUISetState(@SW_SHOW,$GUI)
    GuiSetIcon(@SystemDir & "\ahui.exe", 0)
    While 1 
        $MSG = GUIGetMsg()
        Switch $MSG
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $OK
            DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $GUI, "int", 1000, "long", 0x00050008);slide-out to top
            ExitLoop
        Case $About
            DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $GUI, "int", 1000, "long", 0x00090000)
            ToolTip(@CRLF&"Name:"&@CRLF&"Company:"&@CRLF&@CRLF&"Contact:"&@CRLF&@CRLF&"This info will automatically close in 3sec.", 400, 300, " Information ", 2, 2)
            Sleep(3000)
            ToolTip("", 0, 0, "", 0)
            DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $GUI, "int", 1000, "long", 0x00080000);fade-in
        EndSwitch
        If TimerDiff($Timer) >= 10000 then
            ExitLoop
        EndIf  ;after 20 seconds exit or you could exitloop and proceed to the next part of the script
    WEnd
    GUIDelete($GUI)
EndFunc
; 2.2) Disable Move by WinMove Or taskbar-> Move Window
Func _SaveWinPos()
Local $x = WinGetPos($M1)
If $x[0] <> $GLOBAL_WINPOS[0] Or _
$x[1] <> $GLOBAL_WINPOS[1] Or _
$x[2] <> $GLOBAL_WINPOS[2] Or _
$x[3] <> $GLOBAL_WINPOS[3] Then
WinMove($M1,"",$GLOBAL_WINPOS[0],$GLOBAL_WINPOS[1],$GLOBAL_WINPOS[2],$GLOBAL_WINPOS[3])
EndIf
EndFunc
; 1.2) Disable Move by titlebar
Func WM_NCHITTEST($hWnd, $Msg, $wParam, $lParam)
Local $iProc

$iProc = DllCall("user32.dll", "int", "DefWindowProc", "hwnd", $hWnd, "int", $Msg, "wparam", $wParam, "lparam", $lParam)
$iProc = $iProc[0]

If $iProc = $HTCAPTION Then Return 0

Return $GUI_RUNDEFMSG
EndFunc
;Function is called from the code given Below
CMB($M1, $M2,0x00FF00)
;Function is called from the code given Above
Edited by BrettF
Link to comment
Share on other sites

You have initialized your timer inside the main while loop so it keeps getting updated. You have not set the global variables used for the window positions to the actual positions.

Try this

#include <GuiConstants.au3>
Global $GLOBAL_WINPOS
Dim $M1 = "Title 123", $M2 = "First Label Goes Here" & @CRLF & @CRLF & "2nd Label Here..." & @CRLF & @CRLF & "3rd Label here..." & @CRLF & @CRLF & "Press OK To Continue..."
Func CMB($title,$text,$color)
    Local $L_TEXT = StringLen($text)
    Local $ROW = Int(Number($L_TEXT) / 45) + 1
    Local $GUI = GUICreate($title,316,83*Number($ROW) + 30,-1,-1)
    GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
    GUISetBkColor(0x000000)
    $GLOBAL_WINPOS = WinGetPos($GUI); Save Variable for 2)
    AdlibEnable("_SaveWinPos",100); 2.1) Disable Move by WinMove Or taskbar-> Move Window
    DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $GUI, "int", 1000, "long", 0x00040010)
    Local $icon = GUICtrlCreateIcon("shell32.dll", "240", 10, 35, 48, 48)
    Local $FIELD = GUICtrlCreateLabel($text,50,10,250,30*Number($ROW),0x01)
    GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
    $Label1 = GUICtrlCreateLabel("Access", 15, 25, 45, 17)
    GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0x0000FF)
    $Label2 = GUICtrlCreateLabel("Denied", 15, 80, 40, 17)
    GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0x0000FF)
    $Label3 = GUICtrlCreateLabel("Info:"&@CRLF&"Some Text here..."&@CRLF&"Some Text here..."&"Some Text here..."&@CRLF&@CRLF&"Some Text here...", 8, 144, 230, 92)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFFFFFF)
    Local $OK = GUICtrlCreateButton("OK", 232, 112, 75, 25, 0)
    Local $About = GUICtrlCreateButton("About", 232, 245, 75, 25)
    GUICtrlSetColor ($FIELD,$color)
    GUISetState(@SW_SHOW,$GUI)
    GuiSetIcon(@SystemDir & "\ahui.exe", 0)
    $Timer=TimerInit()
    While 1 
        $MSG = GUIGetMsg()
        
        $pos = WinGetPos($M1)
        If $pos[0]<>Int((@DesktopWidth-$pos[2])/2) or $pos[1]<> Int((@DesktopHeight-$pos[3])/2) Then
            WinMove($M1,"",Int((@DesktopWidth-$pos[2])/2),Int((@DesktopHeight-$pos[3])/2))
        Endif
        If $MSG = $OK Then
            ConsoleWrite($MSG & @CRLF)
            DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $GUI, "int", 1000, "long", 0x00050008);slide-out to top
            GUIDelete($GUI)
            ExitLoop
        EndIf
        If $MSG = $About Then
            ConsoleWrite($MSG & @CRLF)
            DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $GUI, "int", 1000, "long", 0x00090000)
            ToolTip(@CRLF&"Name:"&@CRLF&"Company:"&@CRLF&@CRLF&"Contact:"&@CRLF&@CRLF&"This info will automatically close in 3sec.", 400, 300, " Information ", 2, 2)
            Sleep(3000)
            ToolTip("", 0, 0, "", 0)
            DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $GUI, "int", 1000, "long", 0x00080000);fade-in
        EndIf
        If TimerDiff($Timer) >= 10000 then
            GUIDelete($GUI)
            ExitLoop
        EndIf  ;after 20 seconds exit or you could exitloop and proceed to the next part of the script
    WEnd
EndFunc
; 2.2) Disable Move by WinMove Or taskbar-> Move Window
Func _SaveWinPos()
Local $x = WinGetPos($M1)
if not IsArray($x) then return
If $x[0] <> $GLOBAL_WINPOS[0] Or _
$x[1] <> $GLOBAL_WINPOS[1] Or _
$x[2] <> $GLOBAL_WINPOS[2] Or _
$x[3] <> $GLOBAL_WINPOS[3] Then
WinMove($M1,"",$GLOBAL_WINPOS[0],$GLOBAL_WINPOS[1],$GLOBAL_WINPOS[2],$GLOBAL_WINPOS[3])
For $n = 0 to 3
    $GLOBAL_WINPOS[$n] = $x[$n]
Next

EndIf
EndFunc
; 1.2) Disable Move by titlebar
Func WM_NCHITTEST($hWnd, $Msg, $wParam, $lParam)
Local $iProc
$iProc = DllCall("user32.dll", "int", "DefWindowProc", "hwnd", $hWnd, "int", $Msg, "wparam", $wParam, "lparam", $lParam)
$iProc = $iProc[0]

If $iProc = $HTCAPTION Then Return 0

Return $GUI_RUNDEFMSG
EndFunc
;Function is called from the code given Below
CMB($M1, $M2,0x00FF00)
;Function is called from the code given Above
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...