#IfWinActive,메뉴공부
F12::
Options:
Gui,2:Add, Button,x200 y350 w60 +Center, 설정저장
Gui,2:+alwaysontop +toolwindow
Gui,2:margin,0,0
Gui,2:Add, Tab2, x0 y0 w400 h400 vOption,기능|오차수정|키설정|기타
Gui,2:Tab, 기능
Gui,2:add,GroupBox,x6 y20 w385 h90 ,설정
Gui,2:add,Text,x16 y40,모드
Gui,2:add,DropDownList,x46 y35 vSetting_A w60,모험|기타|
Gui,2:Tab,기타
Gui,2:Add,Text,x6 y30,설치위치
Gui,2:Add,Edit,x60 y25 w200 vSetPos,
Gui,2:Show,w400 h400,환경설정
Gui,2:Tab,오차수정
----------------------------------------------
;이미지 오차율 수정
----------------------------------------------
LV = SysListView321 ;set the controls to use
ED = Edit1
ST = Static1
FontSize = 10
EnableSingleClick = 1 ;whether or not to do cell highlighting on singleclick
SysGet,SM_CXVSCROLL,2 ;get width of vertical scrollbar
LVIR_LABEL = 0x0002 ;LVM_GETSUBITEMRECT constant - get label info
LVM_GETITEMCOUNT = 4100 ;gets total number of rows
LVM_SCROLL = 4116 ;scrolls the listview
LVM_GETTOPINDEX = 4135 ;gets the first displayed row
LVM_GETCOUNTPERPAGE = 4136 ;gets number of displayed rows
LVM_GETSUBITEMRECT = 4152 ;gets cell width,height,x,y
LVS_SINGLESEL = 0x4 ;allow one item to be selected
LVS_SHOWSELALWAYS = 0x8 ;shows selection highlighting even if no focus
LVS_EX_FULLROWSELECT = LV0x20 ;whole row selection
listOptions =
(Join`s LTrim
+AltSubmit
-Checked
+NoSortHdr
+NoSort
+Grid
-%LVS_EX_FULLROWSELECT%
-%LVS_SHOWSELALWAYS%
+%LVS_SINGLESEL%
+LV0x2
)
;AutoTrim,Off
DetectHiddenWindows,On
Gui,2:+LastFound
guiID := WinExist() ;get id for gui
GroupAdd,editKeypress,ahk_id %guiID% ;for ENTER and ESC handling
Gui,2:Add, ListView, x5 yp+45 h200 w350 %listOptions% vlview glistclick, ID|이미지파일명|이미지|인식율 ;make listview
Gui,2:Add, Edit, x0 y-50 vCellEdit ;make edit control
Gui,2:Add, Text, x0 y-50 vCellHighlight +Border cBlue -Wrap ;make static1 control
ControlGetPos,lx,ly,lw,lh,%LV%,ahk_id %guiID% ;get info on listview
GuiControl,2:-Redraw,lview
;********just to fill the listview********
; Gather a list of file names from a folder and put them into the ListView:
Loop, %A_ScriptDir%\Data\Img\*.*,0,0
{
StringTrimRight, FileName, A_LoopFileName,4
Iniread, I_%FileName%, %A_ScriptDir%\Config.ini,Mistake, %FileName%,%A_Space%
%FileName% := I_%FileName%
img:=ILA_AddImageFile(A_LoopFileFullPath,0,40,1)
Row := lv_add("Icon999999",A_Index,FileName,,%FileName%)
LVA_SetSubItemImage("lview", Row, 3, img)
}
LV_ModifyCol()
LV_ModifyCol(1,0)
LV_ModifyCol(2,150)
;LV_ModifyCol(3,50)
LV_ModifyCol(4,50)
GuiControl,2:+Redraw,lview
Return
button설정저장:
gui,2:submit, nohide
Loop, %A_ScriptDir%\data\img\*.*,0,0
{
SaveCount := A_Index
}
Loop, %SaveCount%
{
Lv_GetText(CurrVariation,A_Index,4)
Lv_GetText(CurrFileName,A_Index,2)
iniwrite, %CurrVariation%, %A_ScriptDir%\Config.ini,Mistake, %CurrFileName%
}
return
;TODO:
;singleclick in listview not reliable - find another way other than "Normal" maybe "C" with other condition
;can't highlight text in edit1 with mouse, just calls listClick
;maybe use arrow keys with a static control cell overlay to emulate cell highlighting? - partially done
listClick:
CoordMode,MOUSE,RELATIVE
MouseGetPos,mx,my,oID,oCNN
If(A_GuiEvent = "DoubleClick")
{ Gosub doubleclick
}
Else If(A_GuiEvent = "Normal" and EnableSingleClick)
{ Gosub singleclick
}
Else If A_GuiEvent In S,s,RightClick,ColClick,D,d,e ;hide edit on these events
{ GuiControl,Hide,%ST% ;hide static control
GuiControl,Hide,%ED% ;hide edit control
}
Return
doubleclick:
GuiControl,Hide,%ED% ;hide edit control
GuiControl,Hide,%ST% ;hide static control
DispControl := ED ;make edit1 the default control
spacer =
Gosub CellInfo
if (currCol =4)
{
Gosub CellReSize
Gosub CellPosition
GuiControl,Focus,%DispControl% ;set focus
SetTimer,isEditFocused,75 ;start edit focus monitor
currCol =
}
else
{}
Return
singleclick:
GuiControl,Hide,%ED% ;hide edit control
GuiControl,Hide,%ST% ;hide edit control
DispControl := ST ;make static1 the default control
spacer = %A_Space%
Gosub CellInfo
if (currCol =4)
{
Gosub CellReSize
Gosub CellPosition
GuiControl,Focus,%LV% ;set focus
currCol =
}
else
{}
Return
;*************************cell size and position stuff******************************
CellInfo:
SendMessage,LVM_GETITEMCOUNT,0,0,%LV%,ahk_id %guiID%
TotalNumOfRows := ErrorLevel ;get total number of rows
SendMessage,LVM_GETCOUNTPERPAGE,0,0,%LV%,ahk_id %guiID%
NumOfRows := ErrorLevel ;get number of displayed rows
SendMessage,LVM_GETTOPINDEX,0,0,%LV%,ahk_id %guiID%
topIndex := ErrorLevel ;get first displayed row
VarSetCapacity(XYstruct, 16, 0) ;create struct
Loop,%NumOfRows% ;gets the current row, and cell Y,H
{ which := topIndex + A_Index -1 ;loop through each displayed row
InsertInteger(LVIR_LABEL ,XYstruct,0) ;get label info constant
InsertInteger(A_Index-1 ,XYstruct,4) ;subitem index
SendMessage,LVM_GETSUBITEMRECT,%which%,&XYstruct,%LV%,ahk_id %guiID% ;get cell coords
RowY := ExtractInteger(XYstruct,4,4) + ly ;row upperleft y = itempos y + listview y
RowY2 := ExtractInteger(XYstruct,12,4) + ly ;row bottomright y2 = itempos y2 + listview y
currColHeight := RowY2 - RowY ;get cell height
If(my <= RowY + currColHeight) ;if mouse Y pos less than row pos + height
{ currRow := which +1 ;1-based current row
currRow0 := which ;0-based current row
Break
}
}
VarSetCapacity(XYstruct, 16, 0) ;create struct
Loop % LV_GetCount("Col") ;gets the current column, and cell X,W
{ InsertInteger(LVIR_LABEL ,XYstruct,0) ;get label info constant
InsertInteger(A_Index-1 ,XYstruct,4) ;subitem index
SendMessage,LVM_GETSUBITEMRECT,%currRow0%,&XYstruct,%LV%,ahk_id %guiID% ;get cell coords
RowX := ExtractInteger(XYstruct,0,4) + lx ;row upperleft x = itempos x + listview x
RowX2 := ExtractInteger(XYstruct,8,4) + lx ;row bottomright x2 = itempos x2 + listview x
currColWidth := RowX2 - RowX ;get cell width
If(mx <= RowX + currColWidth) ;if mouse X pos less than column pos+width
{ currCol := A_Index ;get current column number
Break
}
}
Return
CellReSize:
If(RowX < lx) ;make sure the cell is in view, then get the cell x coord again if it wasn't
{ hscrollVal := RowX - lx - 4 ;get the difference
SendMessage,LVM_SCROLL,%hscrollVal%,0,%LV%,ahk_id %guiID% ;scroll the column into view
VarSetCapacity(XYstruct, 16, 0) ;recreate struct
InsertInteger(LVIR_LABEL ,XYstruct,0) ;get just label coords
InsertInteger(currCol-1 ,XYstruct,4) ;1-based subitem index
SendMessage,LVM_GETSUBITEMRECT,%currRow0%,&XYstruct,%LV%,ahk_id %guiID% ;get cell coords
RowX := ExtractInteger(XYstruct,0,4) + lx ;row upperleft x = itempos x + listview x
}
scrollWidth := TotalNumOfRows > NumOfRows ? SM_CXVSCROLL : 0 ;0 if no vscroll, else = SM_CXVSCROLL
If(RowX+currColWidth > lx+lw-scrollWidth) ;if edit will be too wide, shrink it
{ currColWidth -= ((RowX+currColWidth) - (lx+lw-scrollWidth)) + 3
}
Return
CellPosition:
CellX_LV := currCol ;get cell column
CellY_LV := currRow ;get cell row
LV_GetText(coltxt,CellY_LV,CellX_LV) ;get the text
edW := currColWidth ;get control width
edH := currColHeight + 1 ;get control height
edX := RowX + 2 ;get control x pos
edY := RowY + 1 ;get control y pos
ControlMove,%DispControl%,edX,edY,edW,edH ;move and size control
GuiControl,,%DispControl%,%spacer%%colTxt% ;set the text
GuiControl,Show,%DispControl% ;show control
Return
CellHide:
GuiControl,Hide,%DispControl%
;GuiControl,Focus,%ED% ;set focus
Return
;*************************end cell size and position stuff******************************
isEditFocused:
GuiControlGet,cFoc,Focus
If(cFoc != DispControl)
{ SetTimer,isEditFocused,Off
Gosub CellHide
}
Return
#IfWinActive ahk_group editKeypress
Enter::
GuiControlGet,fControl,Focus ;get control with focus
If(fControl = DispControl) ;if Edit, save any changes
{ Gui,Submit,NoHide
CellX_save = Col%CellX_LV%
LV_Modify(CellY_LV,CellX_save,CellEdit)
Gosub CellHide
}
Return
Esc::
Gosub CellHide ;cancel
Return
Up:: ;if arrow keys pressed while cell highlighted
Down::
Left::
Right::
If(DispControl = ST) ;TODO
{ If(A_ThisHotkey = "Left")
{
}
Else If(A_ThisHotkey = "Right")
{
}
Else If(A_ThisHotkey = "Up")
{
}
Else If(A_ThisHotkey = "Down")
{
}
}
Return
#IfWinActive
InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
; The caller must ensure that pDest has sufficient capacity. To preserve any existing contents in pDest,
; only pSize number of bytes starting at pOffset are altered in it.
{
Loop %pSize% ; Copy each byte in the integer into the structure as raw binary data.
DllCall("RtlFillMemory", "UInt", &pDest + pOffset + A_Index-1, "UInt", 1, "UChar", pInteger >> 8*(A_Index-1) & 0xFF)
}
ExtractInteger(ByRef pSource, pOffset = 0, pIsSigned = false, pSize = 4)
; pSource is a string (buffer) whose memory area contains a raw/binary integer at pOffset.
; The caller should pass true for pSigned to interpret the result as signed vs. unsigned.
; pSize is the size of PSource's integer in bytes (e.g. 4 bytes for a DWORD or Int).
; pSource must be ByRef to avoid corruption during the formal-to-actual copying process
; (since pSource might contain valid data beyond its first binary zero).
{
Loop %pSize% ; Build the integer by adding up its bytes.
result += *(&pSource + pOffset + A_Index-1) << 8*(A_Index-1)
if (!pIsSigned OR pSize > 4 OR result < 0x80000000)
return result ; Signed vs. unsigned doesn't matter in these cases.
; Otherwise, convert the value (now known to be 32-bit) to its signed counterpart:
return -(0xFFFFFFFF - result + 1)
}
;taken from LVA.ahk by Dadepp with minor bug fix
;http://www.autohotkey.com/forum/viewtopic.php?t=43242
LVA_SetSubItemImage(LVvar, Row, Col, iNum){
Static LVM_SETITEM := A_IsUnicode ? 0x104C : 0x1006 ; LVM_SETITEMW : LVM_SETITEMA
Static LVITEMSize := 48 + (A_PtrSize * 3)
Static OffImage := 20 + (A_PtrSize * 2)
GuiControlGet, hLV, Hwnd, %LVvar%
VarSetCapacity(LVItem, LVITEMSize, 0)
Row := (Row < 1) ? 1 : Row
Col := (Col < 1) ? 1 : Col
NumPut(2, LVItem, 0, "UInt")
NumPut(Row-1, LVItem, 4, "Int")
NumPut(Col-1, LVItem, 8, "Int")
NumPut(iNum-1, LVItem, OffImage, "Int")
SendMessage, % LVM_SETITEM, 0, &LVItem,, ahk_id %hLV%
}
; ILA requires GDI
; Thanks to tic (Tariq Porter) for his GDI+ Library
; http://www.autohotkey.com/forum/viewtopic.php?t=32238
#Include Gdip.ahk
; idea for this function taken from post by Looq
; http://www.autohotkey.com/board/topic/62448-large-jpgpnggif-images-inside-a-listview/?hl=%2Blarge+%2Bicon
ILA_AddImageFile(ImageFile, wsize=0, hsize=0, IconType=1){
static hIL, w, h
If FileExist(ImageFile){
pToken := Gdip_Startup()
pBitmap := Gdip_CreateBitmapFromFile(ImageFile)
Gdip_GetDimensions(pBitmap, Width, Height)
If (!w And !h) ;on first call
If (!wsize And !hsize) ;first image defines icon size
w := Width , h := Height
Else if (!wsize) ;scale to hsize
h := hsize , w := (Width * h) // Height
Else if (!hsize) ;scale to wsize
w := wsize , h := (Height * w) // Width
If !hIL{ ;on first call
hIL := ImageList_Create(w, h, 0x20, 255, 10) ; all bitmaps need to be "wxh"
LV_SetImageList(hIL,IconType)
}
If (w = Width and h = Height) ;no resize is needed
hBitmap:=Gdip_CreateHBITMAPFromBitmap(pBitmap)
Else{ ;image needs to be resized
pBitmapResized := Gdip_CreateBitmap(w, h)
G := Gdip_GraphicsFromImage(pBitmapResized)
rw := w / Width , rh := h / Height
r := (rw < rh) ? rw : rh
Gdip_DrawImage(G, pBitmap, (w - Width * r)//2, (h - Height * r)//2, Floor(Width * r), Floor(Height * r))
hBitmap:=Gdip_CreateHBITMAPFromBitmap(pBitmapResized)
Gdip_DeleteGraphics(G)
Gdip_DisposeImage(pBitmapResized)
}
img := ImageList_Add(hIL, hBitmap) + 1 ; "+1" to have a 1 based list
Gdip_DisposeImage(pBitmap)
DeleteObject(hBitmap)
Gdip_Shutdown(pToken)
return img
}
}
return
ImageList_Create(cx,cy,flags,cInitial,cGrow){
return DllCall("comctl32.dll\ImageList_Create", "int", cx, "int", cy, "uint", flags, "int", cInitial, "int", cGrow)
}
ImageList_Add(hIml, hbmImage, hbmMask=""){
return DllCall("comctl32.dll\ImageList_Add", "Ptr", hIml, "Ptr",hbmImage, "Ptr", hbmMask)
}
베스트 글에 있는 이미지 오차율 설정을 저한테 맞게 바꾸고 있습니다.
근데 여기서 한가지 문제가...2번째 gui창에 집어 넣을려고 하는데 이게 2번째 창에 gui는 제대로 출력이 되는데
변수 등이 제대로 2번째 gui에서 작동을 하않아서 출력이 아무것도 안 됩니다.
무엇을 손대야 하는 건가요?
좋은정보 감사합니다.