Jump to content

Dissappearing Graphic n Label on Move Tried Everything...........


Recommended Posts

Hey Every1...................

I made a Virtual Scroll Bar like Thing Using Buttons and Graphic(also with Labels ,Pictures, and Buttons)...........

The Problem is when i Drag the Graphic, Label ,Picture, or Button it Dissapers..........

I have Already Tried to set the BK_COLOR of label to Transparent .............

But No luck ,..............

Please Help Me Out................

Code..........::

#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.6.1
Author:      Phoenix XL
Script Function:
Template AutoIt script.
#ce ----------------------------------------------------------------------------
; Script Start - Add your code below here
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $sgui=GUICreate('Testing........',500,400,100,100)
Local $sBtn[2]=[GUICtrlCreateButton('UP',225,20,50,30),GUICtrlCreateButton('DOWN',225,350,50,30)]
Local $sLabel=GUICtrlCreateGraphic(225,70,50,35)
GuiCtrlSetState(-1,$GUI_ONTOP)
GUICtrlSetBkColor(-1, 0x000000)
GUIRegisterMsg($WM_COMMAND,'WM_COMMAND')
GUISetState()
Local $nMsg,$sPos
While $nMsg<>-3
$nMsg=GUIGetMsg()
$sPos=ControlGetPos($sgui,'',$sLabel)
ConsoleWrite($sPos[1]+$sPos[3]&@CRLF)
Switch $nMsg
  Case $sBtn[0]
   If $sPos[1]+$sPos[3]<=70+25 Then ContinueLoop
   ControlMove($sgui,'',$sLabel,$sPos[0],$sPos[1]-1)
  Case $sBtn[1]
   If $sPos[1]+$sPos[3]>=345 Then ContinueLoop
   ControlMove($sgui,'',$sLabel,$sPos[0],$sPos[1]+1)
EndSwitch
WEnd
Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local $nID = BitAND($wParam, 0xFFFF),$sMousePos
    Switch BitShift($wParam, 16) ; message code
  Case 0,1 ; $STN_CLICKED or Double
   While 1
    $sMousePos=GUIGetCursorInfo($sgui)
    If Not $sMousePos[2] Then ExitLoop
    If $sMousePos[1]<=345-35 And $sMousePos[1]>=70-10 Then
     ControlMove($sgui,'',$sLabel,225,$sMousePos[1])
    EndIf
   WEnd
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
Func _MakeLong($LoWord,$HiWord)
  Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

You do long lasting blocking code in WM_COMMAND.

This is main source of odd behaviour.

Here is fixed version, blocking code moved from WM_COMMAND to main message loop.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $sgui = GUICreate('Testing........', 500, 400, 100, 100)
Local $sBtn[2] = [GUICtrlCreateButton('UP', 225, 20, 50, 30), GUICtrlCreateButton('DOWN', 225, 350, 50, 30)]
;~ Local $sLabel = GUICtrlCreateGraphic(225, 70, 50, 35)
Local $sLabel = GUICtrlCreateLabel('', 225, 70, 50, 35)
GUICtrlSetState(-1, $GUI_ONTOP)
GUICtrlSetBkColor(-1, 0x000000)
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
GUISetState()

Global $drag = False
Local $nMsg, $sPos

While $nMsg <> -3
    $nMsg = GUIGetMsg()
    $sPos = ControlGetPos($sgui, '', $sLabel)
;~   ConsoleWrite($sPos[1] + $sPos[3] & @CRLF)
    Switch $nMsg
        Case $sBtn[0]
            If $sPos[1] + $sPos[3] <= 70 + 25 Then ContinueLoop
            ControlMove($sgui, '', $sLabel, $sPos[0], $sPos[1] - 1)
        Case $sBtn[1]
            If $sPos[1] + $sPos[3] >= 345 Then ContinueLoop
            ControlMove($sgui, '', $sLabel, $sPos[0], $sPos[1] + 1)
    EndSwitch
    
    If $drag Then
        While 1
            $sMousePos = GUIGetCursorInfo($sgui)
            If Not $sMousePos[2] Then ExitLoop
            If $sMousePos[1] <= 345 - 35 And $sMousePos[1] >= 70 - 10 Then
                ControlMove($sgui, '', $sLabel, 225, $sMousePos[1])
            EndIf
        WEnd
        $drag = False
    EndIf
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local $nID = BitAND($wParam, 0xFFFF), $sMousePos
    Switch BitShift($wParam, 16) ; message code
        Case 0, 1 ; $STN_CLICKED or Double
            $drag = True
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func _MakeLong($LoWord, $HiWord)
    Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc   ;==>_MakeLong

But as you can see some problems remains.

I think it's because Graphic control is very nonstandard AutoIt's control so its usage is limited.

I recommend to use Picture control instead. You can use GDI or GDI+ API functions to paint whatever you want on that pictur control if needed.

EDIT: using label instead of graphic fixed it

Edited by Zedna
Link to comment
Share on other sites

And why not use that way?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $sgui = GUICreate('Testing........', 500, 400, 100, 100)
Local $sBtn[2] = [GUICtrlCreateButton('UP', 225, 20, 50, 30), GUICtrlCreateButton('DOWN', 225, 350, 50, 30)]
Local $sLabel = GUICtrlCreateGraphic(225, 70, 50, 35)
GUICtrlSetState(-1, $GUI_ONTOP)
GUICtrlSetBkColor(-1, 0x000000)
GUISetState()

Global $drag = True
Local $nMsg, $sPos

While $nMsg <> -3
    $nMsg = GUIGetMsg()

    Switch $nMsg
        Case $sBtn[0]
            $sPos = ControlGetPos($sgui, '', $sLabel)
            If $sPos[1] + $sPos[3] <= 70 + 25 Then ContinueLoop
            ControlMove($sgui, '', $sLabel, $sPos[0], $sPos[1] - 10)
        Case $sBtn[1]
            $sPos = ControlGetPos($sgui, '', $sLabel)
            If $sPos[1] + $sPos[3] >= 345 Then ContinueLoop
            ControlMove($sgui, '', $sLabel, $sPos[0], $sPos[1] + 10)
        Case $sLabel
            $sPos = ControlGetPos($sgui, '', $sLabel)
            While 1
                $sMousePos = GUIGetCursorInfo($sgui)
                If Not $sMousePos[2] Then ExitLoop
                If $sMousePos[1] <= 345 - 35 And $sMousePos[1] >= 70 - 10 Then
                    ControlMove($sgui, '', $sLabel, 225, $sMousePos[1])
                EndIf
            WEnd
    EndSwitch
WEnd

Regards,

João Carlos.

Edited by JScript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

Thanx JScript and Zedna.................

Both The Methods Work Flawlessly ;)

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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...