[오토핫키] Gui창에 드래그 앤 드롭(Drag and Drop) 기능 만들기.

2024. 10. 1. 06:48오토핫키 오픈 스크립트

 

 

[오토핫키] 드래그 앤 드롭(Drag and Drop) 기능 만들기.

 

오토핫키 Gui창에 파일 또는 이미지를 드래그 앤 드롭을 사용하여 활용할 수 있다.

 

사용자가 프로그램에 직접 드래그 앤 드롭을 사용하게 한다면 편리함을 느낄것이다.

 

Gdip_All.ahk 라이브러리를 Include 하기때문에 스크립트와 같은 위치에 라이브러리가 존재 하여야한다.  

 

#Include, Gdip_All.ahk
#Persistent

; GDI+ 초기화
if !pToken := Gdip_Startup()
{
    MsgBox, GDI+ 초기화 실패
    ExitApp
}

Gui, +Resize  ; GUI 크기 조절 가능
Gui, Add, Picture, w300 h300 vMyImage,  ; 이미지 표시할 영역 추가
Gui, Show, w400 h400, 이미지 드래그 앤 드롭

; 드래그 앤 드롭 활성화
Gui, +LastFound
DllCall("Shell32.dll\DragAcceptFiles", "UInt", WinExist(), "Int", 1)
OnMessage(WM_DROPFILES := 0x233, "DropFilesHandler")
return

LoadImage:
FileSelectFile, imagePath, 3, , 이미지 파일 선택, 이미지 파일 (*.jpg; *.jpeg; *.png; *.bmp; *.gif; *.tiff)
if (imagePath = "")
{
    MsgBox, 파일이 선택되지 않았습니다.
    return
}
ProcessImage(imagePath)
return

DropFilesHandler(wParam, lParam)
{
    ; 드롭된 파일 경로 가져오기
    droppedFileCount := DllCall("Shell32\DragQueryFileW", "Ptr", wParam, "UInt", -1, "Ptr", 0, "UInt", 0)
    if (droppedFileCount > 0)
    {
        VarSetCapacity(filePath, 260 * 2) ; 최대 경로 길이 설정
        DllCall("Shell32\DragQueryFileW", "Ptr", wParam, "UInt", 0, "Str", filePath, "UInt", 260)
        DllCall("Shell32\DragFinish", "Ptr", wParam)
        ProcessImage(filePath)
    }
}

ProcessImage(imagePath)
{
    global ; 전역 변수 사용

    ; 이미지 로드
    pBitmap := Gdip_CreateBitmapFromFile(imagePath)
    if !pBitmap
    {
        MsgBox, 이미지 로드 실패
        return
    }

    ; 이미지 크기 가져오기
    width := Gdip_GetImageWidth(pBitmap)
    height := Gdip_GetImageHeight(pBitmap)

    ; 기존 이미지 미리보기 제거
    Gui, Destroy
    Gui, Add, Button, x10 y10 w100 h30 gLoadImage, 이미지 파일 선택
    Gui, Add, Picture, x10 y50 w%width% h%height% vImagePreview, %imagePath%
    Gui, Show, AutoSize, 이미지 검사기

}

GuiClose:
    ExitApp  ; GUI 닫기 시 프로그램 종료

 

 

 

 

 

프로그램 개발 의뢰 및 문의

검은망치 카카오톡오픈프로필 : https://open.kakao.com/o/sDUaoCNg

 

[오토핫키] 검은망치님의 오픈프로필

오토핫키 개발러

open.kakao.com