레이블이 GUI인 게시물을 표시합니다. 모든 게시물 표시
레이블이 GUI인 게시물을 표시합니다. 모든 게시물 표시

2016. 3. 12.

현재 열려있는 IE의 윈도우 정보 가져오기

[출처:http://autohotkey.co.kr/b/6-833]


프레임 제어관련 http://www.autohotkey.com/forum/topic70428.html

[AHK_L] 현재 열려진 인터넷 창 값 가져오기

 
AHK_L 은 이렇게...

#include d:\COM.ahk
IEGet( name="" )
{
   IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame ; Get active window if no parameter
   Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs" : RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" )
   For pwb in ComObjCreate( "Shell.Application" ).Windows
      If ( pwb.LocationName = Name ) && InStr( pwb.FullName, "iexplore.exe" )
         Return pwb
}
F3::
pwb := IEGet("Access an existing IE object - Microsoft Internet Explorer")
pwb.Visible := True ; Make the IE object visible
Sleep, 2000
test := pwb.document.documentElement.innerText
MsgBox, %test%
return

^r::
reload
return

Basic Ahk_L COM Tutorial for Webpages


This guide is not intended to replace the great work that other (more advanced) members have put into other guides. It is designed to help non-coders (n00bz) grasp the basic concepts of AutoHotkey_L COM.

This guide will focus on giving the reader a baseline understanding of the use of the Component Object Model(COM) which can be used to manipulate an application with designed with Document Object Model or DOM such as Internet Explorer.

Q: What is COM? (도대체 컴이 뭐유?)
The Component Object Model is a collection of automation objects that allows a user to interface with various methods and properties of an application.

Q: How do I use it in my script?
There is no easy answer to this question. Why? Because there are different commands to every type of COM object. For instance the methods for Internet Explorer are completely different from MS Office.

In this tutorial I will focus on using COM to script simple commands that will be used to automate IE. Before you can do anything with the IE DOM you have to create a handle to the application.
Code (Copy):
Pwb := ComObjCreate("InternetExplorer.Application")

"Pwb" or Pointer to a Web Browser is the common name for your handle to IE. Your script doesn't care what you name your Pointer you could name it "WhatAboutBob" if you really wanted to.
Now that you have a handle you need to do something with it. Think of it like the steering wheel of a car. Just because you have the wheel in your hands doesn't mean your driving the car.

Code (Copy):
Pwb.Visible := True   

This is the next line of code you will HAVE to have. Your code can work without it but you won't be able to see anything going on. By default IE starts off in invisible mode. I'll go ahead and point out that ".Visible" is NOT AHK code. It is a built in method in the DOM. You can access it through any COM compatible language (Ruby,C++,ect).

Code (Copy):
Pwb.Navigate("Google.com")

At this point we have actually done something. That is open up an instance of IE and navigated to google.com. You could also store an address in a variable.

Code (Copy):
URL = Google.com
Pwb.Navigate(URL)

What about accessing an already open web browser? Good Q! There is no simple command for this. Instead you will have to rely on a function (I did not write) to do this for you.

Code (Copy):
IEGet(Name="")      ;Retrieve pointer to existing IE window/tab
{
   IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame
      Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs"
      : RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" )
   For Pwb in ComObjCreate( "Shell.Application" ).Windows
      If ( Pwb.LocationName = Name ) && InStr( Pwb.FullName, "iexplore.exe" )
         Return Pwb
} ;written by Jethrow

If your thinking "Holy Heart Attack Batman!" fear not you don't need to understand how this function works to implement it into your script. What this function does is looks through the windows on your computer for IE and then for the tab name of the page you sent it OR default to the last activated tab.

Code (Copy):

Pwb := IEGet()   ;Last active window/tab
;OR
Pwb := IEGet("Google")   ;Tab name you define can also be a variable

Now that we can open IE and navigate to pages we can manipulate things now right? Wrong!

notice the loading bar at the bottom of the page or wherever your browser has it? That is your first adversary. You are going to have to tell your script to wait till your page is done loading.

Code (Copy):

IELoad(Pwb)   ;You must send the function your Handle for it to work

This is a function that is based of the iWeb function Tank built. If you don't care to understand how it works then just know that you must have this (or another similer) function on any script that deals with IE.

Code (Expand - Copy):

IELoad(Pwb)   ;You need to send the IE handle to the function unless you define it as global.
{
   If !Pwb   ;If Pwb is not a valid pointer then quit
      Return False
   Loop   ;Otherwise sleep for .1 seconds untill the page starts loading
      Sleep,100
   Until (Pwb.busy)
   Loop   ;Once it starts loading wait until completes
      Sleep,100
   Until (!Pwb.busy)
   Loop   ;optional check to wait for the page to completely load
      Sleep,100
   Until (Pwb.Document.Readystate = "Complete")
Return True
}

Now that you can access an existing page or launch a new one we can actually do something useful. Let's fill the search field. We are going to use the "Name" element to do this.

Code (Copy):

Pwb.Document.All.q.Value := "site:autohotkey.com tutorial"

You can also set a form to a variable:

Code (Copy):

Website = site:autohotkey.com tutorial
Pwb.Document.All.q.Value := Website

You've just manipulated your first DOM object! Let's go over what we did just now.
This line of code probably doesn't mean anything to you at the moment so let's break it down to something that we all can understand.

Think of "Pwb" in our code as the top floor or roof of the building you happen to be on. You however want to do something in the basement since it's too wet and rainy to do anything on the roof. However to get to the basement you must travel through all the other floors between.

"Document" refers the the room directly below you in this example. The Document object holds EVERYTHING on any web page you see. But you must specify where your looking on the Document.

"All" specifies all the items including forms, tables, buttons, ect that you can control.

What is "q"??? Q happens to be the name of the search form. To figure out what the name of anything on a web page you should use a tool such as "Ahk Web Recorder." It's a handy tool that shows the information of any IE window you hover the mouse cursor over.

Now that we have the address of the element we want to work with "Value" is a method that alows you to change the content within.

Everything to the right side of the ":=" is what you want placed within the value you have selected. In this case we are going to search through the website "autohotkey.com" using the "site:" tool that is built into the Google search engine. That way Google will only search through a single website instead of browsing the entire WWW.

Now let's click the "Search" button.

Code (Copy):

Pwb.Document.All.btnG.Click()

Here we use the "Click()" method. "Value" gives us access to data held within a form whereas "Click" activates a button.

So far we have covered: how to get a(n) existing or created IE handle, sleep till a page has loaded, set a form, and click a button. Here's what your code SHOULD look like. Minus the functions:

Code (Copy):

Pwb := IEGet("Google") ;IE instance already open and tab named google exists
Pwb.Document.All.q.Value := "site:autohotkey.com tutorial"
Pwb.Document.All.btnG.Click()
IELoad(Pwb)
;or
Pwb := ComObjCreate("InternetExplorer.Application") ;create a IE instance
Pwb.Visible := True
Pwb.Navigate("Google.com")
IELoad(Pwb)
Pwb.Document.All.q.Value := "site:autohotkey.com tutorial"
Pwb.Document.All.btnG.Click()
IELoad(Pwb)

This guide is a work in progress I will continue to add more material as soon as I get more time and after editing the work I have done so far.
Please keep posts on this page to either requests for explanations or pointing out errors I have made here.
Thanks for reading.

Other Resources:

For a more advanced tutorial on this subject please see jethrow's tutorial at: http://www.autohotkey.com/forum/viewtopic.php?t=51020&start=0&postdays=0&postorder=asc&highlight= This is what I first started out with.


Last edited by Mickers on Thu May 12, 2011 4:26 pm; edited 6 times in total



While PWB.readystate <> 4
   sleep 50

I don't see any reason why using all three available detection methods shouldn't be encouraged:

Code (Copy):
Loop
   Sleep, 50
Until   (pwb.readyState=4 && pwb.document.readyState="complete" && !pwb.busy)





웹페이지 로딩 완료 체크

[출처:http://autohotkey.co.kr/b/6-586]


WebWait(A,Search)
{
WinAct(A)
; 새창의 윈도ID 얻기 
WinGet, wid, ID 
; 새창을 제어할 수 있는 COM 오브젝트 얻기 
ie := IE_ComObjGet(wid) 
 
; 이제 ie를 통해 새창을 제어한다. 
 
; 특정 윈도ID를 가지는 IE창의 COM 오브젝트를 얻는다. 존재하지 않는다면 빈문자열을 반환한다. 
@param wid 윈도ID 
@return COM 오브젝트 
 
;ie 오브젝트에서 한번 썻기때문에 안씀.
IE_ComObjGet(wid) { 
    For obj in ComObjCreate("Shell.Application").Windows 
        If (ComObjType(obj, "Name") == "IWebBrowser2" && obj.HWND == wid) 
            Return obj 
}
 
 loop
 {; ie 객체의 테스트를 취득하여 dnserror 오류가 없으면 result에 저장을 하며, result에 페이지 특유의 텍스트가 있는지를 비교하여 완료.
 If (!RegExMatch(ie.StatusText, "dnserror")) { 
 ErrorLevel := 0
 result := ie.Document.documentElement.innerHTML 
 
     } Else { 
 ErrorLevel := 1 
     } 
FileAppend, %result%, test.html
IfInString, result, %Search%
 {
 break
 }
 }
 }
 

2016. 3. 11.

GroupBox 컨트롤 데모

[출처:https://autohotkey.com/board/topic/71065-groupbox-addwrap-around-existing-controls]


GBTHeight:=10
Gui, +LastFound
Gui, Add, Text, vLabel1, A Label
Gui, Add, Text, x162 yMargin vLabel2, Nother Label
Gui, Add, Edit, Section vMyEdit1 xMargin, This is a Control
Gui, Add, Edit, vMyEdit2 ys x162, This is a Control
Gui, Add, CheckBox, Section vCheck1 xMargin, CheckBox 1
Gui, Add, CheckBox, vCheck2 ys x160, CheckBox 2
GroupBox("GB1", "Testing", GBTHeight, 10, "Label1|Label2|MyEdit1|MyEdit2|Check1|Check2")
Gui, Add, Text, Section xMargin, This is un-named
Gui, Add, DropDownList, xMargin vDDL, LIne 1|Line 2| Line 3
GroupBox("GB2", "Another Test", GBTHeight, 10, "This is un-named|DDL")
Gui, Add, Text, yS, This is a control
Gui, Add, DateTime, vMyDateTime w127
GroupBox("GB3", "Test", GBTHeight, 10, "Static4|MyDateTime")
Gui, Add, Text, vMyText xMargin, Some text to read.
Gui, Add, Button, Section x60, Button 1
Gui, Add, Button, ys x+10, Button 2
GroupBox("GB4", "Buttons Too", GBTHeight, 10, "Button 1|Button 2")
GroupBox("GB5", "Around Another GroupBox", GBTHeight, 10, "MyText|Button 1|Button 2|GB4", 298)
Gui, Show, , GroupBox Test

return
GuiClose:
ExitApp



GroupBox(GBvName,Title,TitleHeight,Margin,Piped_CtrlvNames,FixedWidth="",FixedHeight="") {
 Local maxX, maxY, minX, minY, xPos, yPos
 minX:=99999, minY:=99999, maxX:=0, maxY:=0
 Loop, Parse, Piped_CtrlvNames, |, %A_Space%
 {
  GuiControlGet, GB, Pos, %A_LoopField%
  minX:= GBX<minX ? GBX : minX
  minY:= GBY<minY ? GBY : minY
  maxX:= GBX+GBW>maxX ? GBX+GBW : maxX
  maxY:= GBY+GBH>maxY ? GBY+GBH : maxY
  xPos:= GBX+Margin
  yPos:= GBY+TitleHeight
  GuiControl, Move, %A_LoopField%, x%xPos% y%yPos%
 }
 GBW:= FixedWidth ? FixedWidth : maxX-minX+2*Margin
 GBH:= FixedHeight ? FixedHeight : maxY-MinY+TitleHeight+Margin
 Gui, Add, GroupBox, v%GBvName% x%minX% y%minY% w%GBW% h%GBH%, %Title%
}

2개 이상의 다른 스크립트 제어하기

[출처:http://autohotkey.co.kr/b/6-200]


;다음 내용을 main.ahk라는 이름으로 저장해 주세요.

DetectHiddenWindows On
SetTitleMatchMode 2
OnExit,exit
return

;Start
^s::
run,a.ahk
run,b.ahk
return

;Pause
^p::
PostMessage,0x111,65306,,,a.ahk - AutoHotkey
PostMessage,0x111,65306,,,b.ahk - AutoHotkey
return

;Reload
^r::
PostMessage,0x111,65303,,,a.ahk - AutoHotkey
PostMessage,0x111,65303,,,b.ahk - AutoHotkey
return

;Close
^x::
PostMessage,0x111,65307,,,a.ahk - AutoHotkey
PostMessage,0x111,65307,,,b.ahk - AutoHotkey
return

exit:
PostMessage,0x111,65307,,,a.ahk - AutoHotkey
PostMessage,0x111,65307,,,b.ahk - AutoHotkey
exitapp


;다음 내용을 a.ahk라는 이름으로 저장해 주세요.

#SingleInstance force
#NoTrayIcon
CoordMode,ToolTip,Screen
Loop
{
Tooltip,%A_Index%,100,100
sleep,100
}
return

;다음 내용을 b.ahk라는 이름으로 저장해 주세요.

#SingleInstance force
#NoTrayIcon
CoordMode,ToolTip,Screen
Loop
{
Tooltip,%A_Index%,200,100
sleep,100
}
return

;-----------------------------------------------------------------

이제 main.ahk만 실행시켜 주세요.
main.ahk에서 a.ahk와 b.ahk를 제어할 수 있습니다.

Ctrl-S 로 a.ahk와 b.ahk를 시작할 수 있습니다.
Ctrl-P 는 Pause.
Ctrl-R 는 Reload.
Ctrl-X 는 a와 b를 종료시킵니다.

2016. 3. 4.

스크립트 리스트

gui, add, listView, w200 h200 vsList, 값
gui, show

iCount := 0

i := 1

while(i<=5) {
    iCount++

random, sGet, 1, 10

    lv_add("", sGet)

    sleep, 200
i++
}

iCount := LV_getCount()

loop, %iCount% {
LV_getText(sVal, a_index, 1)
sList := sList . sVal . "`n"
}

msgbox % sList

2016. 2. 29.

바탕화면을 그림판처럼 쓸수있는 스크립트

컨트롤을 누른채로 마우스 드래그하면 낙서가 됩니다. ESC로 끕니다.





CoordMode, Mouse, Screen

Black    = 000000
Green    = 008000
Silver    = C0C0C0
Lime       = 00FF00
Gray       = 808080
Olive       = 808000
White    = FFFFFF
Yellow    = FFFF00
Maroon    = 800000
Navy    = 000080
Red       = FF0000
Blue       = 0000FF
Purple    = 800080
Teal       = 008080
Fuchsia    = FF00FF
Aqua    = 00FFFF
hh := A_ScreenHeight - 51
ww := A_ScreenWidth / 3
ColorChoice = Black
LineWidth = 11
xpos=0
ypos=0
word=
Gui 2: Color, black
Gui 2: Add, Button, Default x-100 y1 gokbt,
Gui 2: +LastFound +AlwaysOnTop +ToolWindow -Caption
Gui 2: Add, Edit, vword x20 y1 w%ww%,
 Gui 2: Add, DropDownList, w80 x+20 y1 choose2 vColorChoice gchange, Aqua|Black|Blue|Fuchsia|Gray|Green|Lime|Maroon|Navy|Olive|Purple|Red|Silver|Teal|White|Yellow|
Gui 2: Add, DropDownList, w40 x+20 y1 choose4 vLineWidth gchange2, 8|9|10|11|12|14|16|18|20|22|24|26|28|36|48|72|
Gui 2: Show, x-1 y%hh% w%A_ScreenWidth% h22
Gui, 1:+LastFound +AlwaysOnTop
Gui, 1:-Caption
Gui, 1:Color, FF0000
WinSet, TransColor, FF0000
GuiHwnd := WinExist()
Gui, 1:Show
Gui, 1:Maximize
SetTimer, DrawLine, 100
return

okbt:
Gui 2: Submit, NoHide
StringLen, length, ww
Send {Ctrl down}
Send {a}
Send {Ctrl up}
Send {del}
fontsize := LineWidth * 3
MouseGetPos, xpos, ypos
Gui 3: Color, EEAA99
Gui 3: +LastFound +AlwaysOnTop +ToolWindow -Caption
WinSet, TransColor, EEAA99
gui 3: font, s%fontsize% C%ColorChoice%, Verdana
Gui 3: Add, Text, x1 y1, %word%
Gui 3: Show, x%xpos% y%ypos% w%A_ScreenWidth%
length=
return

DrawLine:
GetKeyState, state, LButton
GetKeyState, state2, Ctrl
MouseGetPos, M_x, M_y
if state = D
if state2 = D
{
sleep 25
MouseGetPos, M_x2, M_y2
Canvas_DrawLine(GuihWnd, M_x, M_y, M_x2, M_y2, LineWidth, %ColorChoice%)
loop 30
{
GetKeyState, state, LButton
GetKeyState, state2, Ctrl
if state = U
{
break
}
else if state2 = U
{
break
}
sleep 25
MouseGetPos, M_x3, M_y3
Canvas_DrawLine(GuihWnd, M_x3, M_y3, M_x2, M_y2, LineWidth, %ColorChoice%)
sleep 25
MouseGetPos, M_x2, M_y2
Canvas_DrawLine(GuihWnd, M_x3, M_y3, M_x2, M_y2, LineWidth, %ColorChoice%)
}
}
return
Canvas_DrawLine(hWnd, p_x1, p_y1, p_x2, p_y2, p_w, p_color) ; r,angle,width,color)
   {
   p_x1 -= 1, p_y1 -= 1, p_x2 -= 1, p_y2 -= 1
   hDC := DllCall("GetDC", UInt, hWnd)
   hCurrPen := DllCall("CreatePen", UInt, 0, UInt, p_w, UInt, Convert_BGR(p_color))
   DllCall("SelectObject", UInt,hdc, UInt,hCurrPen)
   DllCall("gdi32.dll\MoveToEx", UInt, hdc, Uint,p_x1, Uint, p_y1, Uint, 0 )
   DllCall("gdi32.dll\LineTo", UInt, hdc, Uint, p_x2, Uint, p_y2 )
   DllCall("ReleaseDC", UInt, 0, UInt, hDC)  ; Clean-up.
   DllCall("DeleteObject", UInt,hCurrPen)
   }
Convert_BGR(RGB)
   {
   StringLeft, r, RGB, 2
   StringMid, g, RGB, 3, 2
   StringRight, b, RGB, 2
   Return, "0x" . b . g . r
   }

return

change:
Gui 2: submit
Gui 2: Color, %ColorChoice%
Gui 2: Show, x-1 y%hh% w2000 h22
return
change2:
Gui 2: submit
Gui 2: Show, x-1 y%hh% w2000 h22
return

esc::exitapp

^r::
{
WinSet, Redraw,, ahk_id %GuiHwnd%
Gui 3: Cancel
return
}




[출처:http://www.autohotkey.com/board/topic/28662-drawing-on-screen/]

2016. 2. 17.

Listbox Gui 만들때 유용한 예제

[출처: http://autohotkey.co.kr/b/1-1839  꼼꼼님 예제입니다. ]


ahk파일 다운로드
(txt파일인데 확장자 ahk로 바꿔주시면 됩니다.)


스크립트에 대한 설명:

ListBox Gui 만들때 유용할겁니다.
아마 예제만 이용해도 웬만한 기능은 써먹을수 있을겁니다.




------------ AHK 스크립트 내용 ------------

#singleinstance force
#notrayicon
 
title = ListBox 예제


gui,add,listbox,xm ym w100 r20 vLB choose1 gLBevent,목소리|음성|공감|솔직|편지|지폐|선물
gui,add,edit  ,xm    yp+250 w200 vEDT -background
gui,add,button,xm+110 ym    w130 h20 gBTN1,총 리스트수
gui,add,button,xp     yp+20 wp hp gBTN2,추가
gui,add,button,xp     yp+20 wp hp gBTN3,선택한 다음줄에 삽입
gui,add,button,xp     yp+20 wp hp gBTN4,랜덤 선택
gui,add,button,xp     yp+20 wp hp gBTN5,선택줄 삭제
gui,add,button,xp     yp+20 wp hp gBTN6,전체 삭제
gui,add,button,xp     yp+20 wp hp gBTN7,선택줄 번호/이름
gui,add,button,xp     yp+20 wp hp gBTN8,Height 간격조절
gui,add,button,xp     yp+20 wp hp gBTN20,재실행
gui,add,button,xp     yp+20 w65 hp glistboxUPDOWN vitemUP,위로
gui,add,button,xp+65  yp    wp hp glistboxUPDOWN vitemDN,아래로
gui,show,,% title
return
LBevent:
    ifEqual, a_guievent, doubleclick, msgbox,64,info, % a_eventinfo,1  ;리스트를 더블클릭했을때 리스트번호 얻기
    return
BTN1:
    sendmessage,0x18B,,,listbox1, % title        ;총 리스트수 구하기
    getCOUNT := errorlevel
    guicontrol,,EDT,% "Total : " . errorlevel
    return
BTN2:
    sendmessage,0x180, , "리스트추가" . a_msec, listbox1, % title            ;추가
    gosub BTN1
    return
BTN3:
    gosub BTN7
    sendmessage,0x181, LB_GETCURSEL, "리스트삽입" . a_msec, listbox1, % title            ;선택한 줄 다음에 라인 삽입
    gosub BTN1
    return   
BTN4:
    gosub BTN1
    random,NUM,0,% getCOUNT-1
    sendmessage,0x186,NUM,,listbox1, % title            ;번호로 리스트 선택
    return   
BTN5:
    gosub BTN7
    sendmessage,0x182,LB_GETCURSEL-1,,listbox1, % title            ;선택리스트 삭제
    return   
BTN6:
    sendmessage,0x184,,,listbox1, % title            ;전체 삭제
    gosub BTN1
    return   
BTN7:
    sendmessage,0x188,,,listbox1, % title            ;선택한 리스트 번호
    LB_GETCURSEL := errorlevel+1
    controlget, getITEM, choice,, listbox1, % title         ;선택한 리스트이름
    guicontrol,,EDT,% LB_GETCURSEL . "`," . getITEM
    return   
BTN8:
    sendmessage,0x1A0,,15, listbox1, % title        ;Height 간격 조절
    guicontrol,+redraw,LB
    return   
listboxUPDOWN:            ;항목 이동하기
    gui,submit,nohide
    sendmessage,0x18B,,,listbox1, % title        ;총 줄수
    LB_GETCOUNT := errorlevel
    sendmessage,0x188,,,listbox1, % title            ;선택리스트 번호 얻기
    ifequal,a_guicontrol,itemUP,ifequal,errorlevel,0,return
    ifequal,a_guicontrol,itemDN,ifequal,errorlevel,% LB_GETCOUNT-1,return
    LB_GETCURSEL := errorlevel
    sendmessage,0x182,LB_GETCURSEL,,listbox1, % title            ; 리스트 삭제
    sendmessage,0x181,LB_GETCURSEL + (a_guicontrol="itemDN" ? 1:-1),"" . LB, listbox1, % title    ;추가
    sendmessage,0x186,LB_GETCURSEL + (a_guicontrol="itemDN" ? 1:-1),,listbox1, % title    ;선택
    return
BTN20:
    reload
guiescape:
guiclose:
 exitapp