c.haslam Posted October 5, 2017 Share Posted October 5, 2017 Here is my code: expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL") Local $Form1 = GUICreate("Form1", 623, 449, 192, 114) GUISetState(@SW_SHOW) Global $n = 39,$nMsg,$oldn=-1,$Graphic1=0 While 1 If $n<>$oldn Then If $Graphic1<>0 Then GUICtrlDelete($Graphic1) EndIf $Graphic1 = GUICtrlCreateGraphic(0, 0, 605, 441) GUICtrlSetGraphic($Graphic1, $GUI_GR_MOVE, 9, 39) GUICtrlSetGraphic($Graphic1, $GUI_GR_LINE, 300, $n) $oldn = $n Else $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch EndIf WEnd Func WM_MOUSEWHEEL($hWnd,$iMsg, $iwParam, $ilParam) #forceref $hwnd, $iMsg, $ilParam Local $a = GUIGetCursorInfo($Form1) If $a[4] = $Graphic1 Then Local $iDelta = BitShift($iwParam, 16) If $iDelta > 0 Then $n += 5 If $iDelta < 0 Then $n -= 5 EndIf Return $GUI_RUNDEFMSG EndFunc When the wheel is "wheeled", the right end of the line should move up or down. It doesn't. In fact, the line does not appear at all. With the cursor inside the control, inserting MsgBox(0,'','here') after $oldn = $n shows me that the If .. Else code is executed. Suggestions? Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
c.haslam Posted October 8, 2017 Author Share Posted October 8, 2017 (edited) I am answering my own question. It seems that the native functions are unable to handle the problem. I turned to GDI+, so here is a simple example of GDI+ graphics, thanks to Mat (Post 6) I also thank all those others whose posts led me in a direction that works. expandcollapse popup#include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars',1) Global Const $MK_SHIFT = 0x4 Global Const $MK_CONTROL = 0x8 GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL") Global $gY0,$gY1,$ghGui,$gLabel Example() Func Example() Local $ghGui, $hGraphic, $hPen Local $oldY0,$oldY1 ; Create GUI $ghGui = GUICreate("GDI+", 400, 330) $gLabel = GUICtrlCreateLabel('',0,0,400,250) GUICtrlCreateLabel('Scroll mouse to move whole line',10,251,300,17) GUICtrlCreateLabel('Control scroll to move left end',10,271,300,17) GUICtrlCreateLabel('Shift scroll to move right end',10,291,300,17) Local $btn = GUICtrlCreateButton('Exit',351,291,30,20) GUISetState(@SW_SHOW) _GDIPlus_Startup() Local $h = GUICtrlGetHandle($gLabel) ; limit graphics to area of $label $hGraphic = _GDIPlus_GraphicsCreateFromHWND($h) $hPen = _GDIPlus_PenCreate() _GDIPlus_GraphicsDrawLine($hGraphic, 10, $gY0, 350, $gY1, $hPen) $gY0 = 150 $gY1 = 150 ; Loop until the user exits. While True If $gY0<>$oldY0 Or $gY1<>$oldY1 Then _GDIPlus_GraphicsClear($hGraphic,0xFFD4D0C8) _GDIPlus_GraphicsDrawLine($hGraphic, 10, $gY0, 390, $gY1, $hPen) $oldY0 = $gY0 $oldY1 = $gY1 Else Switch GUIGetMsg() Case $GUI_EVENT_CLOSE,$btn Exit EndSwitch EndIf WEnd ; Clean up resources _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() EndFunc Func WM_MOUSEWHEEL($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam Local $vec = GUIGetCursorInfo($ghGui) If $vec[4] = $gLabel Then Local $iDelta = BitShift($wParam, 16) ; positive = up Local $iKeys = _WinAPI_LoWord($wParam) If BitAND($iKeys,$MK_CONTROL)=$MK_CONTROL Then If BitAND($iKeys,$MK_SHIFT)=$MK_SHIFT Then ; do nothing Else If $iDelta > 0 And $gY0>3 Then $gY0 -= 1 If $iDelta < 0 And $gY0<247 Then $gY0 += 1 EndIf Else If BitAND($iKeys,$MK_SHIFT)=$MK_SHIFT Then If $iDelta > 0 And $gY1>3 Then $gY1 -= 1 If $iDelta < 0 And $gY1<247 Then $gY1 += 1 Else If $iDelta > 0 And $gY0>3 Then $gY0 -= 1 If $iDelta < 0 And $gY0<247 Then $gY0 += 1 If $iDelta > 0 And $gY1>3 Then $gY1 -= 1 If $iDelta < 0 And $gY1<247 Then $gY1 += 1 EndIf EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_MOUSEWHEEL The script provides the user with the ability to move the whole line, and its left end, as well as the right end. My application does not require the line to be moved horizontally. It appears that GDI+ can empty a graphic of all lines, etc. but not just one. Comments and suggestions are most welcome. Edited October 8, 2017 by c.haslam Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard 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