Jump to content

Text editor bounding rectangle is out of place


mrbig1479
 Share

Recommended Posts

hi here is the script

#include <GuiConstants.au3>
#include <GuiEdit.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>

Opt("GuiCloseOnESC", 0)
$I=0
$SETS_CTRL_DATA=""
$NUMBEROFSETS=46
Global $hEdit, $hDC, $hBrush, $Item = -1, $SubItem = 0
Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT)
$hGUI =GUICreate("Price Editor", 689, 469, 201, 115)
GUISetBkColor(0x00E0FFFF)
$hListView = _GUICtrlListView_Create($hGUI, "", 10, 100, 496, 355, BitOR($LVS_EDITLABELS, $LVS_REPORT))
_GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_GRIDLINES)
_GUICtrlListView_InsertColumn($hListView, 0, "Card name", 180)
_GUICtrlListView_InsertColumn($hListView, 1, "Sell price", 80)
_GUICtrlListView_InsertColumn($hListView, 2, "foil sell price", 80)
_GUICtrlListView_InsertColumn($hListView, 1, "Buy price", 80)
_GUICtrlListView_InsertColumn($hListView, 2, "foil buy price", 80)
$Button_Load = GUICtrlCreateButton("Load", 24, 24, 75, 25, 0)
$Button_save = GUICtrlCreateButton("Save", 104, 24, 75, 25, 0)
$Button_Delete = GUICtrlCreateButton("Delete", 184, 24, 75, 25, 0)
$Combo_type = GUICtrlCreateCombo("Rares", 280, 24, 145, 25)
GUICtrlSetData(-1, "Commons|Uncommons|Mystic", "Rares")
$Combo_Sets = GUICtrlCreateCombo("ALA", 432, 24, 145, 25)


While $I <= $NUMBEROFSETS - 1
    $SETS_CTRL_DATA=$SETS_CTRL_DATA&Conert_set_to_number($I)&"|"
    $I=$I+1
WEnd

$SETS_CTRL_DATA=StringTrimRight ($SETS_CTRL_DATA,1)
GUICtrlSetData(-1, $SETS_CTRL_DATA, "ALA") 
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlSetOnEvent($Button_Load, "LOAD_EDITOR")
GUICtrlSetOnEvent($Button_save, "SAVE_EDITOR")


For $i = 1 To 43
    _GUICtrlListView_AddItem($hListView, "Item" & $i)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 1)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 2)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 2)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 3)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 4)
Next


GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

GUISetState(@SW_SHOW)

Do
    $msg = GUIGetMsg()

Until $msg = $GUI_EVENT_CLOSE
    
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $tNMHDR, $hWndFrom, $iCode
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hListView
            Switch $iCode
                Case $NM_DBLCLK
                    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView)
                    If ($aHit[0] <> -1) And ($aHit[1] = 0) Then
                        $Item = $aHit[0]
                        $SubItem = 0
                        Local $aRect = _GUICtrlListView_GetItemRect($hListView, $Item)
                    ElseIf ($aHit[0] <> -1) And ($aHit[1] > 0) Then
                        $Item = $aHit[0]
                        $SubItem = $aHit[1]
                        Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $Item, $SubItem)
                    Else
                        Return $GUI_RUNDEFMSG
                    EndIf
                    Local $iItemText = _GUICtrlListView_GetItemText($hListView, $Item, $SubItem)
                    Local $iLen = _GUICtrlListView_GetStringWidth($hListView, $iItemText)
                    $hEdit = _GUICtrlEdit_Create($hGUI, $iItemText, $aRect[0] + 3, $aRect[1], $iLen + 10, 17, $Style)
                    _GUICtrlEdit_SetSel($hEdit, 0, -1)
                    _WinAPI_SetFocus($hEdit)
                    $hDC = _WinAPI_GetWindowDC($hEdit)
                    $hBrush = _WinAPI_CreateSolidBrush(0x0000FF)
                    FrameRect($hDC, 0, 0, $iLen + 10 , 17, $hBrush)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Func FrameRect($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBrush)
    Local $stRect = DllStructCreate("int;int;int;int")
    DllStructSetData($stRect, 1, $nLeft)
    DllStructSetData($stRect, 2, $nTop)
    DllStructSetData($stRect, 3, $nRight)
    DllStructSetData($stRect, 4, $nBottom)
    DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush)
EndFunc

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $iCode = BitShift($wParam, 16)
    Switch $lParam
        Case $hEdit
            Switch $iCode
                Case $EN_KILLFOCUS
                    Local $iText = _GUICtrlEdit_GetText($hEdit)
                    _GUICtrlListView_SetItemText($hListView, $Item, $iText, $SubItem)
                    _WinAPI_DeleteObject($hBrush)
                    _WinAPI_ReleaseDC($hEdit, $hDC)
                    _WinAPI_DestroyWindow($hEdit)
                    $Item = -1
                    $SubItem = 0
            EndSwitch
    EndSwitch
   
    Return $GUI_RUNDEFMSG
EndFunc 
    
Func Conert_set_to_number($ED)
EndFunc
FUNC LOAD_EDITOR ()
EndFunc

FUNC SET_PRICE_ON_CONTROL($CARDNAME,$SELLING_PRICE,$SELLING_FOIL_PRICE ,$BUYING_PRICE,$BUYING_FOIL_PRICE)
EndFunc

FUNC SAVE_EDITOR ()
EndFunc

when i double click on data to change it the bounding rectangle is in a higher position,

also i need to click anywhere else for the data to change , can i use also "enter" to enter the data ?

thanks

Link to comment
Share on other sites

Try this:

#include <GuiConstants.au3>
#include <GuiEdit.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>

Opt("GuiCloseOnESC", 0)

$I=0
$SETS_CTRL_DATA=""
$NUMBEROFSETS=46
Global $hEdit, $hDC, $hBrush, $Item = -1, $SubItem = 0
Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT)
$hGUI =GUICreate("Price Editor", 689, 469, 201, 115)
GUISetBkColor(0x00E0FFFF)
$hListView = _GUICtrlListView_Create($hGUI, "", 10, 100, 496, 355, BitOR($LVS_EDITLABELS, $LVS_REPORT))
_GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_GRIDLINES)
_GUICtrlListView_InsertColumn($hListView, 0, "Card name", 180)
_GUICtrlListView_InsertColumn($hListView, 1, "Sell price", 80)
_GUICtrlListView_InsertColumn($hListView, 2, "foil sell price", 80)
_GUICtrlListView_InsertColumn($hListView, 1, "Buy price", 80)
_GUICtrlListView_InsertColumn($hListView, 2, "foil buy price", 80)
$Button_Load = GUICtrlCreateButton("Load", 24, 24, 75, 25, 0)
$Button_save = GUICtrlCreateButton("Save", 104, 24, 75, 25, 0)
$Button_Delete = GUICtrlCreateButton("Delete", 184, 24, 75, 25, 0)
$Combo_type = GUICtrlCreateCombo("Rares", 280, 24, 145, 25)
GUICtrlSetData(-1, "Commons|Uncommons|Mystic", "Rares")
$Combo_Sets = GUICtrlCreateCombo("ALA", 432, 24, 145, 25)


While $I <= $NUMBEROFSETS - 1
    $SETS_CTRL_DATA=$SETS_CTRL_DATA&Conert_set_to_number($I)&"|"
    $I=$I+1
WEnd

$SETS_CTRL_DATA=StringTrimRight ($SETS_CTRL_DATA,1)
GUICtrlSetData(-1, $SETS_CTRL_DATA, "ALA")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlSetOnEvent($Button_Load, "LOAD_EDITOR")
GUICtrlSetOnEvent($Button_save, "SAVE_EDITOR")


For $i = 1 To 43
    _GUICtrlListView_AddItem($hListView, "Item" & $i)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 1)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 2)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 2)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 3)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 4)
Next


GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

GUISetState(@SW_SHOW)

Do
    $msg = GUIGetMsg()

Until $msg = $GUI_EVENT_CLOSE
    
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $tNMHDR, $hWndFrom, $iCode
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hListView
            Switch $iCode
                Case $NM_DBLCLK
                    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView)
                    If ($aHit[0] <> -1) And ($aHit[1] = 0) Then
                        $Item = $aHit[0]
                        $SubItem = 0
                        Local $aRect = _GUICtrlListView_GetItemRect($hListView, $Item)
                    ElseIf ($aHit[0] <> -1) And ($aHit[1] > 0) Then
                        $Item = $aHit[0]
                        $SubItem = $aHit[1]
                        Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $Item, $SubItem)
                    Else
                        Return $GUI_RUNDEFMSG
                    EndIf
                    
                    Local $iItemText = _GUICtrlListView_GetItemText($hListView, $Item, $SubItem)
                    Local $iLen = _GUICtrlListView_GetStringWidth($hListView, $iItemText)
                    
                    Local $aCtlPos = ControlGetPos($hWnd, "", $hWndFrom)
                    Local $iX = $aCtlPos[0] + $aRect[0] + 2
                    Local $iY = $aCtlPos[1] + $aRect[1] - 2
                    
                    $hEdit = _GUICtrlEdit_Create($hGUI, $iItemText, $iX, $iY, $iLen + 10, 17, $Style)
                    
                    _GUICtrlEdit_SetSel($hEdit, 0, -1)
                    _WinAPI_SetFocus($hEdit)
                    
                    $hDC = _WinAPI_GetWindowDC($hEdit)
                    $hBrush = _WinAPI_CreateSolidBrush(0x0000FF)
                    FrameRect($hDC, 0, 0, $iLen + 10 , 17, $hBrush)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Func FrameRect($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBrush)
    Local $stRect = DllStructCreate("int;int;int;int")
    DllStructSetData($stRect, 1, $nLeft)
    DllStructSetData($stRect, 2, $nTop)
    DllStructSetData($stRect, 3, $nRight)
    DllStructSetData($stRect, 4, $nBottom)
    DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush)
EndFunc

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $iCode = BitShift($wParam, 16)
    Switch $lParam
        Case $hEdit
            Switch $iCode
                Case $EN_KILLFOCUS
                    Local $iText = _GUICtrlEdit_GetText($hEdit)
                    _GUICtrlListView_SetItemText($hListView, $Item, $iText, $SubItem)
                    _WinAPI_DeleteObject($hBrush)
                    _WinAPI_ReleaseDC($hEdit, $hDC)
                    _WinAPI_DestroyWindow($hEdit)
                    $Item = -1
                    $SubItem = 0
            EndSwitch
    EndSwitch
  
    Return $GUI_RUNDEFMSG
EndFunc    
    
Func Conert_set_to_number($ED)
EndFunc
FUNC LOAD_EDITOR ()
EndFunc

FUNC SET_PRICE_ON_CONTROL($CARDNAME,$SELLING_PRICE,$SELLING_FOIL_PRICE ,$BUYING_PRICE,$BUYING_FOIL_PRICE)
EndFunc

FUNC SAVE_EDITOR ()
EndFunc
Link to comment
Share on other sites

Try this:

#include <GuiConstants.au3>
#include <GuiEdit.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>

Opt("GuiCloseOnESC", 0)

$I=0
$SETS_CTRL_DATA=""
$NUMBEROFSETS=46
Global $hEdit, $hDC, $hBrush, $Item = -1, $SubItem = 0
Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT)
$hGUI =GUICreate("Price Editor", 689, 469, 201, 115)
GUISetBkColor(0x00E0FFFF)
$hListView = _GUICtrlListView_Create($hGUI, "", 10, 100, 496, 355, BitOR($LVS_EDITLABELS, $LVS_REPORT))
_GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_GRIDLINES)
_GUICtrlListView_InsertColumn($hListView, 0, "Card name", 180)
_GUICtrlListView_InsertColumn($hListView, 1, "Sell price", 80)
_GUICtrlListView_InsertColumn($hListView, 2, "foil sell price", 80)
_GUICtrlListView_InsertColumn($hListView, 1, "Buy price", 80)
_GUICtrlListView_InsertColumn($hListView, 2, "foil buy price", 80)
$Button_Load = GUICtrlCreateButton("Load", 24, 24, 75, 25, 0)
$Button_save = GUICtrlCreateButton("Save", 104, 24, 75, 25, 0)
$Button_Delete = GUICtrlCreateButton("Delete", 184, 24, 75, 25, 0)
$Combo_type = GUICtrlCreateCombo("Rares", 280, 24, 145, 25)
GUICtrlSetData(-1, "Commons|Uncommons|Mystic", "Rares")
$Combo_Sets = GUICtrlCreateCombo("ALA", 432, 24, 145, 25)


While $I <= $NUMBEROFSETS - 1
    $SETS_CTRL_DATA=$SETS_CTRL_DATA&Conert_set_to_number($I)&"|"
    $I=$I+1
WEnd

$SETS_CTRL_DATA=StringTrimRight ($SETS_CTRL_DATA,1)
GUICtrlSetData(-1, $SETS_CTRL_DATA, "ALA")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlSetOnEvent($Button_Load, "LOAD_EDITOR")
GUICtrlSetOnEvent($Button_save, "SAVE_EDITOR")


For $i = 1 To 43
    _GUICtrlListView_AddItem($hListView, "Item" & $i)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 1)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 2)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 2)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 3)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 4)
Next


GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

GUISetState(@SW_SHOW)

Do
    $msg = GUIGetMsg()

Until $msg = $GUI_EVENT_CLOSE
    
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $tNMHDR, $hWndFrom, $iCode
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hListView
            Switch $iCode
                Case $NM_DBLCLK
                    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView)
                    If ($aHit[0] <> -1) And ($aHit[1] = 0) Then
                        $Item = $aHit[0]
                        $SubItem = 0
                        Local $aRect = _GUICtrlListView_GetItemRect($hListView, $Item)
                    ElseIf ($aHit[0] <> -1) And ($aHit[1] > 0) Then
                        $Item = $aHit[0]
                        $SubItem = $aHit[1]
                        Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $Item, $SubItem)
                    Else
                        Return $GUI_RUNDEFMSG
                    EndIf
                    
                    Local $iItemText = _GUICtrlListView_GetItemText($hListView, $Item, $SubItem)
                    Local $iLen = _GUICtrlListView_GetStringWidth($hListView, $iItemText)
                    
                    Local $aCtlPos = ControlGetPos($hWnd, "", $hWndFrom)
                    Local $iX = $aCtlPos[0] + $aRect[0] + 2
                    Local $iY = $aCtlPos[1] + $aRect[1] - 2
                    
                    $hEdit = _GUICtrlEdit_Create($hGUI, $iItemText, $iX, $iY, $iLen + 10, 17, $Style)
                    
                    _GUICtrlEdit_SetSel($hEdit, 0, -1)
                    _WinAPI_SetFocus($hEdit)
                    
                    $hDC = _WinAPI_GetWindowDC($hEdit)
                    $hBrush = _WinAPI_CreateSolidBrush(0x0000FF)
                    FrameRect($hDC, 0, 0, $iLen + 10 , 17, $hBrush)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Func FrameRect($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBrush)
    Local $stRect = DllStructCreate("int;int;int;int")
    DllStructSetData($stRect, 1, $nLeft)
    DllStructSetData($stRect, 2, $nTop)
    DllStructSetData($stRect, 3, $nRight)
    DllStructSetData($stRect, 4, $nBottom)
    DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush)
EndFunc

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $iCode = BitShift($wParam, 16)
    Switch $lParam
        Case $hEdit
            Switch $iCode
                Case $EN_KILLFOCUS
                    Local $iText = _GUICtrlEdit_GetText($hEdit)
                    _GUICtrlListView_SetItemText($hListView, $Item, $iText, $SubItem)
                    _WinAPI_DeleteObject($hBrush)
                    _WinAPI_ReleaseDC($hEdit, $hDC)
                    _WinAPI_DestroyWindow($hEdit)
                    $Item = -1
                    $SubItem = 0
            EndSwitch
    EndSwitch
  
    Return $GUI_RUNDEFMSG
EndFunc    
    
Func Conert_set_to_number($ED)
EndFunc
FUNC LOAD_EDITOR ()
EndFunc

FUNC SET_PRICE_ON_CONTROL($CARDNAME,$SELLING_PRICE,$SELLING_FOIL_PRICE ,$BUYING_PRICE,$BUYING_FOIL_PRICE)
EndFunc

FUNC SAVE_EDITOR ()
EndFunc
Thanks a lot , i couldn't do it without your help. Edited by mrbig1479
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...