예지력
W
예지력

블로그 메뉴

  • 문의 & 피드백
  • GitHub
  • 분류 전체보기
    • 주식
    • 파생상품
    • crypto
      • 차트에 현대미술
      • 복기
      • 시스템 트레이딩
      • 기술적 분석
      • 블록체인
      • 생각
      • 리서치
      • Token Engineering
    • 이더리움 | ETH
      • 리서치
    • 테라 | LUNA
      • Tefi
      • 루나 LUNA
      • 아스트로포트 Astro
      • 앵커 프로토콜 ANC
      • 미러 프로토콜 MIR
      • 아폴로 다오 APOLLO
      • 프리즘 프로토콜 PRISM
      • 넥서스 프로토콜 NEXUS
      • 레바나 프로토콜 LEV
      • 마스 프로토콜 MARS
      • 더비 스타즈 Derby Stars
    • 프로그래밍
      • AHK 메뉴얼
      • AHK 레퍼런스
      • Delphi XE7
      • C
      • Python
      • Reversing
      • Archive
    • 일상
    • 영화
    • 낙서장
    • Deprecated
      • 로다 플레이어
      • 어의

인기 글

최근 댓글

전체 방문자
오늘
어제

티스토리

hELLO · Designed By 정상우.
예지력

W

[Lib] CleanNotify
프로그래밍/Archive

[Lib] CleanNotify

2015. 11. 21. 19:29

Language : AutoHotkey

Author : 예지력

Function : 팝업메시지


/**
    * CleanNotify.ahk
    *        미려한 팝업, 알림메시지
    * 버전:
    *        v1.1 [마지막 업데이트 11/21/2015 (MM/DD/YYYY)]
    * 라이센스:
    *        WTFPL [http://wtfpl.net/]
    * 시스템 요구사항:
    *        AutoHotkey v1.1.22.09
    * 설치:
    *        #Include CleanNotify.ahk 또는, Lib 폴더로 이동
    * 정보:
    *        라이브러리 제작자 - 예지력 (http://knowledgeisfree.tistory.com)
*/

class CleanNotify
{
    /**
        * 인스턴스 Instance:
        *        new CleanNotify( 제목, [텍스트], [x], [y], [w], [h], [시간] )
        *            제목 - 팝업알림의 타이틀
        *            [텍스트] - 팝업알림의 텍스트, 생략 시 ""
        *            [x], [y] - 창의 x좌표와 y좌표, 생략시 화면 정중앙으로 설정됨
        *                "vc" "hc" 와 같은 단어로 상대위치 설정가능 (예제 코드 참고)
        *            [w], [h] - 창의 넓이와 높이
        *                생략시, 컴퓨터 해상도 0.3 배로 설정
        *            [시간] - 몇 초 동안 팝업을 유지할껀지, 생략 시 5초로 설정됨
    */
    __New(Title, Text := "", X := "vc", Y := "hc", W := "", H := "", Time := "5")
    {
        this.Gui :={BackgroundColor: "0xF2F2F0"
        , Title: {Color: "0x07D82F"
        , Style: "s18 wBold"
        , Font: "Segoe UI"}
        , Text: {Color: "Black"
        , Style: "s15 wRegular"
        , Font: ""}}
       
        this.Gui.Title.Msg := Title
        this.Gui.Text.Msg := Text
        this.Gui.X := X
        this.Gui.Y := Y
        W ? this.Gui.W := W : this.Gui.W := A_ScreenWidth * 0.3
        H ? this.Gui.H := H : this.Gui.H := A_ScreenHeight * 0.2
       
        LastFound := WinExist()
        Gui, new, +hwndhNotify -DPIScale
        this.Gui.hWnd := hNotify
       
        Gui, % this.Gui.hWnd ": Default"
        Gui, % this.Gui.hWnd ": +AlwaysOnTop +ToolWindow -SysMenu -Caption +LastFound +E0x20"
        Gui, % this.Gui.hWnd ": Color", % this.Gui.BackgroundColor
        WinSet, Transparent, 0
       
        ; Title
        Gui, % this.Gui.hWnd ": Font", % "c" . this.Gui.Title.Color " " . this.Gui.Title.Style, % this.Gui.Title.Font
        Gui, % this.Gui.hWnd ": Add", Text, % " x" 20 " y" 9 " w" this.Gui.W " h" 100 " hwndhThis", % this.Gui.Title.Msg
        this.Gui.Title.hWnd := hThis
       
        ; Text
        Gui, % this.Gui.hWnd ": Font", % "c" . this.Gui.Text.Color " " . this.Gui.Text.Style, % this.Gui.Text.Font
        Gui, % this.Gui.hWnd ": Add", Text, % " x" 20 " y" 56 " w" this.Gui.W " h" this.Gui.H - 56 " hwndhThis", % this.Gui.Text.Msg
        this.Gui.Text.Hwnd := hThis
       
        ; Show Gui
        Gui, % this.Gui.hWnd ": Show", % "W " this.Gui.W . " H" this.Gui.H + 20 " NoActivate"
       
        if X is number
            WinMove, % "ahk_id " . this.Gui.hWnd,, % this.Gui.X, % this.Gui.Y
        else
            this.WinMove(this.Gui.hWnd, this.Gui.X . " " . this.Gui.Y)
       
        WinSet, Region, % "0-0 w" . this.Gui.W . " h" . this.Gui.H . " R40-40", % "ahk_id " . this.Gui.hWnd
        this.WinFade("ahk_id " . this.Gui.hWnd, 210, 5)
       
        if (Time != "P")
            this.Timer(ObjBindMethod(this, "TimerExpired"), Time * 1000)
       
         if (WinExist(LastFound))
            Gui, % LastFound ": Default"
        this.Set := new this.__Control(this.Gui)
    }
   
    /**
        * 서브 클래스: __Control
        *        인스턴스로 받아온 CleanNotify 창의 속성을 변경
        *메소드 Methods:
        *        Title(...문법 자유)
        *            newTitle ... - 제목 변경
        *            newColor ... - 제목 글자 색 변경 (hex RGB코드)
        *            newFont ... - 폰트 변경
        *            newStyle ... - 폰트 스타일 변경
       
        *        Text(... 문법 자유)
        *            Title 메소드와 구조 동일
    */
    class __Control
    {
        __New(Parent)
        {
            this.Gui := Parent
        }
       
        BackgroundColor(Color)
        {
            this.Gui.BackgroundColor := Color
            Gui, % this.Gui.hWnd ": Color", % this.Gui.BackgroundColor
        }
       
        Title(args*)
        {
            for i, Item in args
            {
                if InStr(Item, "newTitle ")
                    this.Gui.Title.Msg := SubStr(Item, 10)
                else if InStr(Item, "newColor ")
                    this.Gui.Title.Color := SubStr(Item, 10)
                else if InStr(Item, "newStyle ")
                    this.Gui.Title.Style := SubStr(Item, 10)
                else if InStr(Item, "newFont ")
                    this.Gui.Title.Font := SubStr(Item, 9)
            }
           
            return this.UpdateGui(this.Gui.Title)
        }
       
        Text(args*)
        {
            for i, Item in args
            {
                if InStr(Item, "newText ")
                    this.Gui.Text.Msg := SubStr(Item, 9)
                else if InStr(Item, "newColor ")
                    this.Gui.Text.Color := SubStr(Item, 10)
                else if InStr(Item, "newStyle ")
                    this.Gui.Text.Style := SubStr(Item, 10)
                else if InStr(Item, "newFont ")
                    this.Gui.Text.Font := SubStr(Item, 9)
            }
           
            return this.UpdateGui(this.Gui.Text)
        }
       
        UpdateGui(Parent)
        {
            Gui, % this.Gui.hWnd ": Font", % "c" . Parent.Color " " . Parent.Style, % Parent.Font
            GuiControl, % this.Gui.hWnd ": Font", % Parent.hWnd
            GuiControl, % this.Gui.hWnd ": Text", % Parent.hWnd, % Parent.Msg
            Gui, % this.Gui.hWnd ": Font",
            WinSet, Redraw,,% "ahk_id " . this.Gui.hWnd
        }
    }
   
    __Delete()
    {
        this.Destroy()
    }
 
    Destroy()
    {
        this.WinFade("ahk_id " this.Gui.hWnd, 0, 5)
        Gui, % this.Gui.hWnd ": Destroy"
    }
 
    Timer(Bind, Tick)
    {
        SetTimer, % Bind, % "-" . Tick
    }
 
    TimerExpired()
    {
        this.Destroy()
    }
 
    WinMove(hwnd,position)
    {
       SysGet, Mon, MonitorWorkArea
       WinGetPos, ix, iy, w, h, ahk_id %hwnd%
       x := InStr(position,"l") ? MonLeft : InStr(position,"hc") ?  (MonRight-w)/2 : InStr(position,"r") ? MonRight - w : ix
       y := InStr(position,"t") ? MonTop : InStr(position,"vc") ?  (MonBottom-h)/2 : InStr(position,"b") ? MonBottom - h : iy
       WinMove, ahk_id %hwnd%,, x, y
    }
 
    WinFade(w := "", t:=128, i:=1, d:=10) ; Thanks, Joedf
    {
        Critical
        w := (w="") ? ("ahk_id " WinActive("A")) : w
        t := (t>255) ? 255 : (t<0) ? 0 : t
        WinGet, s, Transparent, % w
        s := (s="") ? 255 : s
        WinSet,Transparent,% s,% w
        i := (s<t) ? abs(i) : -1*abs(i)
        while (k := (i<0) ? (s>t) : (s<t) && WinExist(w)) {
            WinGet, s, Transparent, % w
            s+=i
            WinSet, Transparent, % s, % w
            Sleep, % d
        }
        Critical, Off
    }
}


#Include CleanNotify.ahk
#SingleInstance force
#NoEnv
SetBatchLines, -1

new CleanNotify("CleanNotify", "기본위치 x 'vc' y 'hc'`n넓이, 높이 = 해상도 * 0.3`n5초 지속")
new CleanNotify("CleanNotify", "위치 t hc", "t", "hc")
new CleanNotify("CleanNotify", "위치 b hc", "b", "hc")

new CleanNotify("CleanNotify", "위치 t r", "t", "r")
new CleanNotify("CleanNotify", "위치 t l", "t", "l")

new CleanNotify("CleanNotify", "위치 b r", "b", "r")
new CleanNotify("CleanNotify", "위치 b l", "b", "l")

Sleep, 5000
Test := new CleanNotify("CleanNotify", "위치 x200 y100`n폰트: Segoe UI`t색상: 0x07D82F`n'F1' 을 눌러보세요!", 200, 100,,, "P")
return

F1::
; 배경색을 변경
Test.Set.BackgroundColor("0x0B161D")

; 화면 중앙으로 이동
Test.WinMove(Test.Gui.hWnd, "vc hc")

; 제목 설정 변경
Test.Set.Title("newTitle 안녕!", "newFont Arial", "newStyle s30")

; 텍스트 설정 변경
Test.Set.Text("newText 배경색: 0x0B161D`n폰트: Arial`t색상: 0xFF8000`n5초후에 사라져요", "newFont Arial", "newColor 0xFF8000")
Sleep, 5000

; 오브젝트 초기화, free the object!
Test := ""

ExitApp


728x90
저작자표시 비영리 동일조건 (새창열림)

'프로그래밍 > Archive' 카테고리의 다른 글

DynaScript - Child 프로세스로 코드 실행  (34) 2015.12.14
[Lib] Class Msgbox  (6) 2015.11.27
WinWaitCreated()  (0) 2015.10.17
MS Office Style Gui 프로토타입  (4) 2015.10.09
GetActiveObjects 활성중인 객체를 불러온다  (0) 2015.03.04
    '프로그래밍/Archive' 카테고리의 다른 글
    • DynaScript - Child 프로세스로 코드 실행
    • [Lib] Class Msgbox
    • WinWaitCreated()
    • MS Office Style Gui 프로토타입
    예지력
    예지력

    티스토리툴바