zwierzak Posted December 11, 2010 Share Posted December 11, 2010 (edited) Hello! Recently, I've been working on a small thing. I met a problem, and dunno what's wrong. I want to make my window "Stats" move, as the original window moves. Here is my code and what happens to the "Stats" window after dragging the bigger window on it.expandcollapse popup#include <GDIPlus.au3> #include <WinAPI.au3> #include <GuiConstants.au3> #include <WindowsConstants.au3> #include <Timers.au3> #Include <Misc.au3> Opt("GUIOnEventMode", 1) Opt("MouseCoordMode", 2) ;MouseGetPos will work for window, not the whole screen Global $GuiSizeX = 1050, $GuiSizeY = 300, $coordX = 0, $coordY = 0 $hGui = GUICreate("GDIPlus Example", $GuiSizeX, $GuiSizeY, $coordX, $coordY) $stats = GUICreate("Stats", 200, $GuiSizeY, $coordX + $GuiSizeX, $coordY) GUISetState(@SW_SHOW, $hGui) GUISetState(@SW_SHOW, $stats) _GDIPlus_Startup() ; Create Double Buffer $hGraphicGUI = _GDIPlus_GraphicsCreateFromHWND($hGui) $hBMPBuff = _GDIPlus_BitmapCreateFromGraphics($GuiSizeX, $GuiSizeY, $hGraphicGUI) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBMPBuff) ;End Double Buffer ;Graphics here $hPen = _GDIPlus_PenCreate(0xFFFF0000, 2) ;End of graphics GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit", $hGui) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit", $stats) GUIRegisterMsg($WM_ERASEBKGND, "WM_ERASEBKGND") $windowpos = WinGetPos($hGui) _MouseTrap($windowpos[0], $windowpos[1], $windowpos[0] + $windowpos[2], $windowpos[1] + $windowpos[3]) While Sleep(100) draw1() MouseTrap() WEnd Func draw1() _GDIPlus_GraphicsClear($hGraphic, 0xFFE8FFE8) $pos = MouseGetPos() _GDIPlus_GraphicsDrawEllipse ($hGraphic, 100, 70, 50, 50, $hPen) ;head _GDIPlus_GraphicsDrawLine ($hGraphic, 125, 120, 125, 200, $hPen) ;body _GDIPlus_GraphicsDrawLine ($hGraphic, 125, 135, 100, 160, $hPen) ;left arm _GDIPlus_GraphicsDrawLine ($hGraphic, 100, 160, 170, $pos[1], $hPen);left forearm _GDIPlus_GraphicsDrawLine ($hGraphic, 125, 120, 125, 200, $hPen) ;right arm _GDIPlus_GraphicsDrawLine ($hGraphic, 125, 120, 125, 200, $hPen);right forearm _GDIPlus_GraphicsDrawLine ($hGraphic, 125, 200, 90, 280, $hPen) ;left leg _GDIPlus_GraphicsDrawLine ($hGraphic, 125, 200, 160, 280, $hPen) ;right leg _GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0) EndFunc Func WM_ERASEBKGND($hWnd, $msg, $wParam, $lParam) _GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0) Return 1 EndFunc ;==>MY_PAINT Func _Exit() GUIRegisterMsg($WM_ERASEBKGND, "") ;_GDIPlus_BrushDispose($hBrush) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_GraphicsDispose($hGraphicGUI) _WinAPI_DeleteObject($hBMPBuff) _GDIPlus_Shutdown() Exit EndFunc Func MouseTrap() $windowpos2 = WinGetPos($hGui) If $windowpos[0] <> $windowpos2[0] Or $windowpos[1] <> $windowpos2[1] Or $windowpos[2] <> $windowpos2[2] Or $windowpos[3] <> $windowpos2[3] Then ;tylko jesli zmienilo sie polozenie _MouseTrap($windowpos2[0], $windowpos2[1], $windowpos2[0] + $windowpos2[2], $windowpos2[1] + $windowpos2[3]) WinMove(WinGetTitle($stats), "", $windowpos2[0] + $windowpos2[2], $windowpos2[1]) EndIf EndFunc ;When u test the script, try to move the big window and notice what happens. Why? Edited December 11, 2010 by zwierzak Link to comment Share on other sites More sharing options...
Realm Posted December 11, 2010 Share Posted December 11, 2010 (edited) Hello zwierzak, After looking at the image you included, all I could think was LAG! Looking at your script I think I found the problem. While Loops work only if a condition is met.. such as 'While 1'. which is the same as 'While True'. In your script your loop is While Sleep(100) which is not a standard condition for a loop. Don't quote me, but I don't think the Sleep function is going to work the way you intended. That small loop without sleep will cause your cpu to overload, giving lots of lag like seen in your image. I would also add a HotKeySet() to exit the application or include a condition in your loop to check for an exit call such as GUIGetMsg() for $GUI_Event_Close. Try changing this: While Sleep(100) draw1() MouseTrap() WEnd To This: While 1 Sleep(100) draw1() MouseTrap() ;add a condition so you can exit the loop as well WEnd Realm Edit: typos Edited December 11, 2010 by Realm My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted December 12, 2010 Share Posted December 12, 2010 @Realm I don't see the problem. While Sleep(100) ConsoleWrite(1 & @CRLF) WEnd .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now