Jump to content

Recommended Posts

Posted (edited)

Edit: Sorry - beaten to the punch! disregard..

Spoiler

 Best I can make of the conversation, there's no official release.. It looks like some updated code was in the svn at the time and AdmiralAlkex compiled that and posted it to the thread.

 

 

Edited by MattyD
Posted

Thanks for sharing, and good to see you getting back into it again. :) 

Added this to the AutoIt GUI Creators (Designers) sticky.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Posted

Here is yesterday's effort - single select button for now.. Double click sets the text, delete removes the control.

;~ #AutoIt3Wrapper_UseX64=N

#include <WindowsSysColorConstants.au3>
#include <guiConstants.au3>
#include <winapi.au3>
#include <guibutton.au3>
#include <WinAPIvkeysConstants.au3>


Global Const $tagMINMAXINFO = "long Reserved[2]; long MaxSize[2]; long MaxPosition[2]; long MinTrackSize[2]; long MaxTrackSize[2]"

Global Const $MK_LBUTTON = 1

Global Const $iSnap = 15

Global $hCursor_Cross = _WinAPI_LoadCursor(0, $IDC_CROSS)
Global $hGui = GUICreate("", 300, 200, 100, 100, BitOR($WS_SIZEBOX, $WS_MINIMIZEBOX))
GUISetState()

Global $hBtnProc = DllCallbackRegister("btnProc", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr")
Global $pBtnProc = DllCallbackGetPtr($hBtnProc)
Global $hWndProc = DllCallbackRegister("WndProc", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr")
Global $pWndProc = DllCallbackGetPtr($hWndProc)

_WinAPI_SetWindowSubclass($hGui, $pWndProc, 1000)

GUISetState()

Local $iMsg
While WinExists($hGui)
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop

    EndSwitch
WEnd

_WinAPI_RemoveWindowSubclass($hGui, $pWndProc, 1000)

Func WndProc($hWnd, $iMsg, $wParam, $lParam, $iIdSubclass, $dwRefData)
    Local $iRet
    Local Static $bDrawRect, $tPaintRect = DllStructCreate($tagRect)

    Switch $iMsg

        Case $WM_SETCURSOR
            Local $iSrc = _WinAPI_LoWord($lParam), $iEvent =  _WinAPI_HiWord($lParam)
            If $iSrc = $HTCLIENT Then
                _WinAPI_SetCursor($hCursor_Cross)
                $iRet = 1
            Else
                $iRet = _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
            EndIf

        Case $WM_LBUTTONDOWN
            Local $tPoint = _WinAPI_MakePoints($lParam)

            $tPaintRect.Left = $tPoint.X
            $tPaintRect.Top = $tPoint.Y

            $tPaintRect.Left -= Mod($tPaintRect.Left, $iSnap)
            $tPaintRect.Top -= Mod($tPaintRect.Top, $iSnap)

            $bDrawRect = True
;~          _WinAPI_TrackMouseEvent($hWnd, $TME_LEAVE)
            $iRet = _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)

        Case $WM_MOUSEMOVE
            Local $tPoint = _WinAPI_MakePoints($lParam)

            If BitAND($wParam, $MK_LBUTTON) = $MK_LBUTTON Then
                _WinAPI_InvalidateRect($hWnd, $tPaintRect, True)
                $tPaintRect.Right = $tPoint.X
                $tPaintRect.Bottom = $tPoint.Y
                $tPaintRect.Right -= Mod($tPaintRect.Right, $iSnap)
                $tPaintRect.Bottom -= Mod($tPaintRect.Bottom, $iSnap)

                _WinAPI_InvalidateRect($hWnd, $tPaintRect, True)
                $iRet = 0
            Else
                If $bDrawRect Then _WinAPI_InvalidateRect($hWnd, $tPaintRect, True)
                $bDrawRect = False
                $iRet = _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
            EndIf


        Case $WM_PAINT
            If $bDrawRect Then
                Local $tPaintStruct = $tagPAINTSTRUCT
                Local $hDC = _WinAPI_BeginPaint($hWnd, $tPaintStruct)
                Local $hPen = _WinAPI_CreatePen($PS_DOT, 1, _WinAPI_RGB(0, 0, 0))
                Local $hBrush = _WinAPI_GetStockObject($WHITE_BRUSH)
                _WinAPI_SelectObject($hDC, $hPen)
                _WinAPI_SelectObject($hDC, $hBrush)
                _WinAPI_Rectangle($hDC, $tPaintRect)
                _WinAPI_DeleteObject($hPen)
                _WinAPI_DeleteObject($hBrush)
                _WinAPI_EndPaint($hWnd, $tPaintStruct)
                $iRet = 0
            Else
                $iRet = _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
            EndIf

        Case $WM_LBUTTONUP
            Local $tPoint = _WinAPI_MakePoints($lParam)

            If $bDrawRect Then
                $bDrawRect = False

                $tPaintRect.Right = $tPoint.X
                $tPaintRect.Bottom = $tPoint.Y
                $tPaintRect.Right -= Mod($tPaintRect.Right, $iSnap)
                $tPaintRect.Bottom -= Mod($tPaintRect.Bottom, $iSnap)

                _WinAPI_InvalidateRect($hWnd, $tPaintRect, True)

                If Abs($tPaintRect.Left - $tPaintRect.Right) >= $iSnap _  ;MinWidth & Height.
                    And Abs($tPaintRect.Top - $tPaintRect.Bottom) >= $iSnap Then

                    ;Need border & clipsiblings to paint custom frame. using UDF for button to avoid any surprises in autoit's default btn proc
                    Local $hBtn = _GUICtrlButton_Create($hWnd, "", _
                            ($tPaintRect.Left < $tPaintRect.Right) ? $tPaintRect.Left : $tPaintRect.Right, _
                            ($tPaintRect.Top < $tPaintRect.Bottom) ? $tPaintRect.Top : $tPaintRect.Bottom, _
                            Abs($tPaintRect.Left - $tPaintRect.Right), _
                            Abs($tPaintRect.Top - $tPaintRect.Bottom), _
                            BitOR($BS_PUSHLIKE, $WS_BORDER, $WS_CLIPSIBLINGS))
                    _WinAPI_SetWindowSubclass($hBtn, $pBtnProc, _WinAPI_GetDlgCtrlID($hBtn))

                EndIf

            EndIf

            $iRet = _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)


        Case $WM_SIZE
            ;This prevents autoit's docking logic from moving controls around on window restore.
            $iRet = _WinAPI_DefWindowProcW($hWnd, $iMsg, $wParam, $lParam)

;~      Case $WM_MOUSELEAVE
;~          Local $tPoint = _WinAPI_GetMousePos(True, $hWnd)
;~          If ($tPoint.X < 0) Or ($tPoint.X > _WinAPI_GetWindowWidth($hWnd)) Then
;~          ElseIf ($tPoint.Y < 0) Or ($tPoint.Y > _WinAPI_GetWindowHeight($hWnd)) Then
;~          EndIf

        Case Else
            $iRet = _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)

    EndSwitch

    Return $iRet
EndFunc   ;==>WndProc


Func btnProc($hWnd, $iMsg, $wParam, $lParam, $iIdSubclass, $dwRefData)
    Local $iRet
    Local Static $iXOffset, $iYOffset, $hHasFocus, $hLastFocus;, $tStartPos
    Local Static $hDrag

    Switch $iMsg

        Case $WM_NCHITTEST
            Local $tPoint = _WinAPI_MakePoints($lParam)
            Local $tRect = _WinAPI_GetWindowRect($hWnd)
            Local $iMar = 10

            $iRet = $HTCLIENT
            ;only in caption bar if left button is down. (no kb input availabe in caption!)
            Local $iTestKey = _WinAPI_GetSystemMetrics($SM_SWAPBUTTON) ? $VK_RBUTTON : $VK_LBUTTON
            If BitAnd(0x8000, _WinAPI_GetAsyncKeyState($iTestKey)) Then $iRet = $HTCAPTION

            If $tPoint.X - $tRect.Left < $iMar Then $iRet = $HTLEFT
            If $tPoint.X > ($tRect.Right - $iMar) Then $iRet = $HTRIGHT

            If $tPoint.Y - $tRect.Top < $iMar Then
                Switch $iRet
                    Case $HTLEFT
                        $iRet = $HTTOPLEFT
                    Case $HTRIGHT
                        $iRet = $HTTOPRIGHT
                    Case Else
                        $iRet = $HTTOP
                EndSwitch

            ElseIf $tPoint.Y > ($tRect.Bottom - $iMar) Then
                Switch $iRet
                    Case $HTLEFT
                        $iRet = $HTBOTTOMLEFT
                    Case $HTRIGHT
                        $iRet = $HTBOTTOMRIGHT
                    Case Else
                        $iRet = $HTBOTTOM
                EndSwitch
            EndIf

            If $tPoint.X < 0 Then $iRet = _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
            If $tPoint.Y < 0 Then $iRet = _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
            _WinAPI_RedrawWindow($hWnd)

        Case $WM_NCLBUTTONDOWN
            $iRet = _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
            _WinaPI_SetFocus($hWnd)

        Case $WM_SETFOCUS
            $hHasFocus = $hWnd
            _SendMessage($wParam, $WM_KILLFOCUS, $hWnd)
            $hLastFocus = $hWnd
            _WinAPI_RedrawWindow($hWnd, 0, 0, BitOR($RDW_FRAME, $RDW_INVALIDATE))
            $iRet = _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)

        Case $WM_KILLFOCUS
            _WinAPI_RedrawWindow($hWnd, 0, 0, BitOR($RDW_FRAME, $RDW_INVALIDATE))
            $iRet = _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)

        Case $WM_NCLBUTTONDBLCLK ;Prevent double-click maximizing in "caption" - also now set caption.
            If $wParam = $HTCAPTION Then
                Local $iCaptionLen = _SendMessage($hWnd, $WM_GETTEXTLENGTH)
                Local $tCaption = DllStructCreate(StringFormat("wchar text[%d]", $iCaptionLen + 1))
                _SendMessage($hWnd, $WM_GETTEXT, DllStructGetSize($tCaption), $tCaption, 0, "wparam", "struct*")
                Local $sCaption = InputBox("Edit Caption", " ", $tCaption.Text, "", 150, 60, BitAND($lParam, 0xFFFF), BitShift($lParam, 16))
                If Not @error Then _SendMessage($hWnd, $WM_SETTEXT, 0, $sCaption, 0, "wparam", "wstr")
            Else
                $iRet = _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
            EndIf

        Case $WM_GETMINMAXINFO
            ;Min width jumps to ~150 with WS_BORDER - I guess it gets min window size: SM_CYMINTRACK
            Local $tMinMaxInfo = DllStructCreate($tagMINMAXINFO, $lParam)
            $tMinMaxInfo.MinTrackSize(1) = $iSnap + 1
            $tMinMaxInfo.MinTrackSize(2) = $iSnap + 1
            $iRet = 0

        Case $WM_SIZING
            Local $tRect = DllStructCreate($tagRect, $lParam)
            Local $tRect2 = _WinAPI_GetWindowRect($hWnd)

            $tRect.Left += Mod($tRect2.Left - $tRect.Left, $iSnap)
            $tRect.Top += Mod($tRect2.Top - $tRect.Top, $iSnap)
            $tRect.Right += Mod($tRect2.Right - $tRect.Right, $iSnap)
            $tRect.Bottom += Mod($tRect2.Bottom - $tRect.Bottom, $iSnap)

            $iRet = True

        Case $WM_NCPAINT
            Local $hDC = _WinAPI_GetWindowDC($hWnd)
            Local $tRect = _WinAPI_GetClientRect($hWnd)
            $tRect.Right = _WinAPI_GetWindowWidth($hWnd)
            $tRect.Bottom = _WinAPI_GetWindowHeight($hWnd)
            Local $hPenCol = ($hHasFocus = $hWnd) ?  _WinAPI_RGB(0, 0xAA, 0) : _WinAPI_GetSysColor($COLOR_3DFACE)
            Local $hPen = _WinAPI_CreatePen($PS_SOLID, 1, $hPenCol)

            _WinAPI_SelectObject($hDC, $hPen)
            _WinAPI_Rectangle($hDC, $tRect)
            _WinAPI_DeleteObject($hPen)
            _WinAPI_ReleaseDC($hWnd, $hDC)
            $iRet = 0

        Case $WM_MOVING
            Local $tRect = DllStructCreate($tagRect, $lParam)
            Local $tRect2 = _WinAPI_GetWindowRect($hWnd)

            $iXOffset += $tRect.Left - $tRect2.Left
            $iYOffset += $tRect.Top - $tRect2.Top
            Local $iSnapH = Floor($iXOffset / $iSnap) * $iSnap
            Local $iSnapV = Floor($iYOffset / $iSnap) * $iSnap
            $iXOffset -= $iSnapH
            $iYOffset -= $iSnapV

            $tRect.Left = $tRect2.Left + $iSnapH
            $tRect.Right = $tRect2.Right + $iSnapH
            $tRect.Top = $tRect2.Top + $iSnapV
            $tRect.Bottom = $tRect2.Bottom + $iSnapV

            $iRet = 0

        Case $WM_EXITSIZEMOVE
            $iXOffset = 0
            $iYOffset = 0
            $iRet = _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)

        Case $WM_KEYDOWN
            If $wParam = $VK_DELETE Then
;~              _WinAPI_DestroyWindow($hWnd)
                _WinAPI_PostMessage($hWnd, $WM_DESTROY, 0, 0)
            Else
                $iRet = _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
            EndIf

        Case $WM_DESTROY
            _WinAPI_RemoveWindowSubclass($hWnd, $pBtnProc, $iIdSubclass)
            $iRet = _WinAPI_DefWindowProcW($hWnd, $iMsg, $wParam, $lParam)
            _GUICtrlButton_Destroy($hWnd)

        Case $WM_SETCURSOR
            Local $iSrc = BitAND($lParam, 0xFFFF), $iEvent = BitShift($lParam, 16)
            If $iSrc = $HTCAPTION And $iEvent = $WM_LBUTTONDOWN Then
                _WinAPI_SetCursor($hCursor_Cross)
                $iRet = 1
            Else
                $iRet = _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
            EndIf

        Case Else
            $iRet = _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)

    EndSwitch

    Return $iRet
EndFunc   ;==>btnProc

Func _WinAPI_MakePoints($iValue)
    Local $tPoint = DllStructCreate($tagPoint)
    DllStructSetData($tPoint, 1, _WinAPI_WordToShort(_WinAPI_LoWord($iValue)))
    DllStructSetData($tPoint, 2, _WinAPI_WordToShort(_WinAPI_HiWord($iValue)))
    Return $tPoint
EndFunc
Posted
4 hours ago, jaberwacky said:

I'm wondering if I should put this on github?

Sounds good

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted

I wonder why the uploaded file use Unix convention for EOL(End of file) instead of Windows  @CRLF

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
×
×
  • Create New...