오토핫키 커뮤니티

질문
2015.10.04 20:15

이미지서치 오차율 질문

조회 수 797 추천 0 댓글 3
#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에서 작동을 하않아서 출력이 아무것도 안 됩니다.
무엇을 손대야 하는 건가요?

  • 꼴초123 2015.10.04 20:55

    좋은정보 감사합니다.

  • profile
    외치기 2015.10.05 16:58

    GuiControl등을 사용할때 Gui이름을 지정해주셔야할거같은데요.

    GuiControl,2: 이런식으로 이름지정해주시는거

    몇개는 되있는데 몇개는 안되있고 그러네요.

  • fnwj 2015.10.05 19:28

    GuiControl 있는거 다 2:로 해줬는데도 안 되더라구요...

    차라리 제가 직접 한번 스크립트 내용 일일이 검색해서 제 스타일대로 만들어야 하나 생가궁입니다.

    혹시 조언해주실 것이 있다면 조언좀 해 주실 수 있나요?


List of Articles
분류 제목 글쓴이 최근변경 추천
정보 MS오피스 스타일 GUI 프로토타입 6 예지력1 2016.04.16 4/0
자유 함수 파라메터 질문좀 드리겠습니다. 7 횬히 2015.10.08 0/0
질문 숫자 "배수"를 나타내려면? (반복작업 중 시간간격으로... 6 서시 2015.10.12 0/0
자유 gdip_imagesearch 사용하시는분 팁좀주세요! 8 횬히 2015.10.10 0/0
질문 gdip_imagesearch 관련 클릭 질문드립니다 2 영웅거북 2016.07.19 0/0
질문 변수대입 줄문입니다 고수님들 좀봐주세요 11 제발등업좀2 2015.10.08 0/0
질문 마우스드래그 1 가자야 2015.10.06 0/0
질문 오토핫키 문의합니다. 답변부탁드려요. 6 운매력임 2015.10.07 0/0
질문 항상위 4 가자야 2015.10.05 0/0
질문 카트라이더 매크로는 없나요? 2 성혀니요 2015.10.05 0/0
질문 이미지서치 오차율 질문 3 fnwj 2015.10.05 0/0
질문 혹시 뮤오리진 질문이여, 2 사잉다유 2015.10.05 0/0
질문 RAW 파일 열수있는 방법이나 .. 읽는 방법이 뭘가요 ㅠㅠ 12 제발등업좀2 2015.10.07 0/0
질문 GuiControl롤 Tab2이동. 3 fnwj 2015.10.05 0/0
정보 맥주소 얻기 12 와이로 2015.10.05 1/0
자유 아..언패킹당해네요 ㅋㅋ 기분..참 29 제발등업좀2 2016.01.14 1/0
정보 Menu bar 근접하게 만들어봄 4 fnwj 2017.11.26 0/0
질문 menu bar fnwj 2015.09.29 0/0
질문 레이븐매크로만드는거도움좀주실분부탁드려요 3 개부리 2015.10.02 0/0
질문 mousegetpos로 딴 좌표에다가 3 이아이온 2015.09.28 0/0
Board Pagination Prev 1 ... 142143144145146147148149150 ... 209 Next
/ 209

전체 최신 인기글

전체 주간 인기글