Sign in to follow this  
Followers 0
MeisterMan

cant drag 2 gui with guionevent on ?

4 posts in this topic

#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Dim $_GuiDelete

$_PngPath = @ScriptDir & "\test.png"
_GDIPlus_Startup ( )
$_Image = _GDIPlus_ImageLoadFromFile ($_PngPath)
$_Width = _GDIPlus_ImageGetWidth ($_Image)
$_Height = _GDIPlus_ImageGetHeight ( $_Image )
$_Ratio = $_Width / $_Height
;~ $_Width = 600
$_Gui = GUICreate ( "gui", $_Width , $_Width / $_Ratio, -1, -1, -1, BitOR ( $WS_EX_LAYERED, $WS_EX_TOPMOST ) )
$_Image = _ImageResize ( $_PngPath, $_Width, $_Width / $_Ratio )
_SetBitMap ( $_Gui, $_Image, 255, $_Width, $_Width / $_Ratio )
$hGUI_Child = GUICreate("", 150, 17, 8, 8, $WS_POPUP, $WS_EX_TOPMOST + $WS_EX_MDICHILD, $_Gui)
$Progress1 = GUICtrlCreateProgress(0, 0, 150, 17,  $PBS_SMOOTH)
GUISetState (@SW_SHOW, $_Gui)
GUISetState (@SW_SHOW, $hGUI_Child)

GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Drag_Window")
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_PRIMARYDOWN
            _SendMessage($_Gui, $WM_SYSCOMMAND, 0xF012, 0)
    EndSwitch
WEnd

_GDIPlus_GraphicsDispose ($_Image)
_GDIPlus_Shutdown()
Exit

Func Drag_Window()    ; <<<<<<<<<<<<<<<<<<<<<<<<<

EndFunc
Func _SetBitmap ( $hGUI, $hImage, $iOpacity, $n_width, $n_height )
Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
$hScrDC = _WinAPI_GetDC ( 0 )
$hMemDC = _WinAPI_CreateCompatibleDC ( $hScrDC )
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap ( $hImage )
$hOld = _WinAPI_SelectObject ( $hMemDC, $hBitmap )
$tSize = DllStructCreate ( $tagSIZE )
$pSize = DllStructGetPtr ( $tSize )
DllStructSetData ( $tSize, "X", $n_width )
DllStructSetData ( $tSize, "Y", $n_height )
$tSource = DllStructCreate ( $tagPOINT )
$pSource = DllStructGetPtr ( $tSource )
$tBlend = DllStructCreate ( $tagBLENDFUNCTION )
$pBlend = DllStructGetPtr ( $tBlend )
DllStructSetData ( $tBlend, "Alpha", $iOpacity )
DllStructSetData ( $tBlend, "Format", 1 )
_WinAPI_UpdateLayeredWindow ( $hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA )
_WinAPI_ReleaseDC ( 0, $hScrDC )
_WinAPI_SelectObject ( $hMemDC, $hOld )
_WinAPI_DeleteObject ( $hBitmap )
_WinAPI_DeleteDC ( $hMemDC )
EndFunc ;==> _SetBitmap ( )

Func _ImageResize ( $sInImage, $newW, $newH, $sOutImage = "" )
Local $oldImage, $GC, $newBmp, $newGC
If $sOutImage = "" Then _GDIPlus_Startup ( )
$oldImage = _GDIPlus_ImageLoadFromFile ( $sInImage )
$GC = _GDIPlus_ImageGetGraphicsContext ( $oldImage )
$newBmp = _GDIPlus_BitmapCreateFromGraphics ( $newW, $newH, $GC )
$newGC = _GDIPlus_ImageGetGraphicsContext ( $newBmp )
_GDIPlus_GraphicsDrawImageRect ( $newGC, $oldImage, 0, 0, $newW, $newH )
_GDIPlus_GraphicsDispose ( $GC )
_GDIPlus_GraphicsDispose ( $newGC )
_GDIPlus_ImageDispose ( $oldImage )
If $sOutImage = "" Then
Return $newBmp
Else
_GDIPlus_ImageSaveToFile ( $newBmp, $sOutImage )
_GDIPlus_BitmapDispose ( $newBmp )
_GDIPlus_Shutdown ( )
Return 1
EndIf
EndFunc ;==> _ImageResize ( )

why i cant drag the gui with OnEvent(1)  but when not on event if i put  _SendMessage($_Gui, $WM_SYSCOMMAND, 0xF012, 0)  in while loop it work?

post-82725-0-95979800-1391434658_thumb.p

Share this post


Link to post
Share on other sites



You aren't using OnEvent mode, you're using MessageLoop mode, so the GUISetOnEvent won't be fired. You have to use one mode or the other, you can't mix them.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

yes i  know... i used onevent... doesnt work thats why i put it in the loop/. u try put onevent and move the command from While to function drag_window() .. ull see what im on about

Share this post


Link to post
Share on other sites

nvm fixed ! :) 

#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Opt("GuiOnEventMode", 1)

Dim $_GuiDelete

$_PngPath = @ScriptDir & "\test.png"
_GDIPlus_Startup ( )
$_Image = _GDIPlus_ImageLoadFromFile ($_PngPath)
$_Width = _GDIPlus_ImageGetWidth ($_Image)
$_Height = _GDIPlus_ImageGetHeight ( $_Image )
$_Ratio = $_Width / $_Height
;~ $_Width = 600
$_Gui = GUICreate ( "gui", $_Width , $_Width / $_Ratio, -1, -1, -1, BitOR ( $WS_EX_LAYERED, $WS_EX_TOPMOST ) )
$_Image = _ImageResize ( $_PngPath, $_Width, $_Width / $_Ratio )
_SetBitMap ( $_Gui, $_Image, 255, $_Width, $_Width / $_Ratio )

$hGUI_Child = GUICreate("", 150, 17, 8, 8, $WS_POPUP, $WS_EX_TOPMOST + $WS_EX_MDICHILD, $_Gui)
$Progress1 = GUICtrlCreateProgress(0, 0, 150, 17,  $PBS_SMOOTH)
GUISetState (@SW_SHOW, $_Gui)
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Drag_Window")
GUISetState (@SW_SHOW, $hGUI_Child)


While 1

WEnd

_GDIPlus_GraphicsDispose ($_Image)
_GDIPlus_Shutdown()
Exit

Func Drag_Window()    ; <<<<<<<<<<<<<<<<<<<<<<<
    _SendMessage($_Gui, $WM_SYSCOMMAND, 0xF012, 0)
EndFunc
Func _SetBitmap ( $hGUI, $hImage, $iOpacity, $n_width, $n_height )
Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
$hScrDC = _WinAPI_GetDC ( 0 )
$hMemDC = _WinAPI_CreateCompatibleDC ( $hScrDC )
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap ( $hImage )
$hOld = _WinAPI_SelectObject ( $hMemDC, $hBitmap )
$tSize = DllStructCreate ( $tagSIZE )
$pSize = DllStructGetPtr ( $tSize )
DllStructSetData ( $tSize, "X", $n_width )
DllStructSetData ( $tSize, "Y", $n_height )
$tSource = DllStructCreate ( $tagPOINT )
$pSource = DllStructGetPtr ( $tSource )
$tBlend = DllStructCreate ( $tagBLENDFUNCTION )
$pBlend = DllStructGetPtr ( $tBlend )
DllStructSetData ( $tBlend, "Alpha", $iOpacity )
DllStructSetData ( $tBlend, "Format", 1 )
_WinAPI_UpdateLayeredWindow ( $hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA )
_WinAPI_ReleaseDC ( 0, $hScrDC )
_WinAPI_SelectObject ( $hMemDC, $hOld )
_WinAPI_DeleteObject ( $hBitmap )
_WinAPI_DeleteDC ( $hMemDC )
EndFunc ;==> _SetBitmap ( )

Func _ImageResize ( $sInImage, $newW, $newH, $sOutImage = "" )
Local $oldImage, $GC, $newBmp, $newGC
If $sOutImage = "" Then _GDIPlus_Startup ( )
$oldImage = _GDIPlus_ImageLoadFromFile ( $sInImage )
$GC = _GDIPlus_ImageGetGraphicsContext ( $oldImage )
$newBmp = _GDIPlus_BitmapCreateFromGraphics ( $newW, $newH, $GC )
$newGC = _GDIPlus_ImageGetGraphicsContext ( $newBmp )
_GDIPlus_GraphicsDrawImageRect ( $newGC, $oldImage, 0, 0, $newW, $newH )
_GDIPlus_GraphicsDispose ( $GC )
_GDIPlus_GraphicsDispose ( $newGC )
_GDIPlus_ImageDispose ( $oldImage )
If $sOutImage = "" Then
Return $newBmp
Else
_GDIPlus_ImageSaveToFile ( $newBmp, $sOutImage )
_GDIPlus_BitmapDispose ( $newBmp )
_GDIPlus_Shutdown ( )
Return 1
EndIf
EndFunc ;==> _ImageResize ( )

had to move the GuiSetOnEvent() like that .. :D 

GUISetState (@SW_SHOW, $_Gui)
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Drag_Window")
GUISetState (@SW_SHOW, $hGUI_Child)

Share this post


Link to post
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
Sign in to follow this  
Followers 0