FindWindow와 함께 자주 많이 쓰이는 함수가 SendMessage이다. 윈도우 응용 프로그램을 만들어 본 사람은 자주 사용하는 기능이다. FindWindow로 찾은 핸들에 사용자가 뭔가 작업을 하기 위해서 메시지를 보내는 함수이다. 메뉴얼에 적혀 있는 설명을 보도록 하자.
4.9.14.10 SendMessage
HWND msg wparam lparam [user_var(return value)] [/TIMEOUT=time_in_ms]Sends a message to HWND. If a user variable $x is specified as the last parameter (or one before the last if you use /TIMEOUT), the return value of SendMessage will be stored to it. Note that when specifying 'msg' you must just use the integer value of the message. If you wish to send strings use "STR:a string" as wParam or lParam where needed.
- WM_CLOSE 16
- WM_COMMAND 273
- WM_USER 1024
Include WinMessages.nsh to have all of Windows messages defined in your script.
To send a string param, put STR: before the parameter, for example: "STR:Some string".
Use /TIMEOUT=time_in_ms to specify the duration, in milliseconds, of the time-out period.
!include WinMessages.nsh
FindWindow $0 "Winamp v1.x"
SendMessage $0 ${WM_CLOSE} 0 0
위의 설명을 보면 SendMessage를 사용하기 위해서는 항상 컴포넌트의 핸들이 필요하다. 이 핸들을 구하기 위해서 필요한 함수가 FindWindow 이다. 그리고 메시지에 대한 정수 값을 알아야 하는데, 이를 윈도우와 같이 정의한 파일인 WinMessages.nsh를 포함시키면 "WM_CLOSE"와 같이 사용할 수 있다. 설명보다는 아래 코드1를 실행해 보면 어떤 일을 하는지 알 수 있을 것이다.
[code];Classic UI
!include "WinMessages.nsh"
Name "dummy"
OutFile "dummy.exe"
XPStyle on
ShowInstDetails show
InstallDir $EXEDIR
Page directory "" "DirShowProc" ""
Page instfiles
Function "DirShowProc"
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $0 1019
CreateFont $1 "Arial" 8 0
SendMessage $0 ${WM_SETFONT} $1 0
SetCtlColors $0 0x00BAB0A6 0x000000
FunctionEnd
Section
; void
SectionEnd[/code]
아래 결과 화면을 보면 Destination Folder 부분에 적혀 있는 글을 보면 평소보다 글씨 크기가 큰 것을 알 수 있다. 이는 17번째줄에서 SendMessage를 이용하여 크기를 15로 바꾸도록 메시지를 보냈기 때문이다. 이와 같이 NSIS에서 미리 정의된 화면을 바꿀때도 사용할 수 있지만, 아이디어만 있으면 다양하게 사용할 수 있는 명령어이다.
[code]!include "WinMessages.nsh"
OutFile "UsingNotepad.exe"
Name "Print text to editor"
;Caption "CD input Plug-in Changer Built by Borg_No.One"
;SilentInstall "silent"
ShowInstDetails "hide"
;DirShow "hide"
;InstallDir $PROGRAMFILESWinamp
Function .onInit
FunctionEnd
Section DoItAll
Call CloseWinamp
SectionEnd
Function CloseWinamp
Exec $WINDIR\Notepad.exe
findloop:
Sleep 500
FindWindow $0 "Notepad"
StrCmp $0 0 findloop
FindWindow $1 "Edit" "" $0
SendMessage $1 ${WM_CHAR} 0x68 0x230001
MessageBox MB_OK "Click OK to close Notepad"
SendMessage $0 ${WM_CLOSE} 0 0
Pop $0
FunctionEnd[/code]




글
댓글을 달아 주세요
댓글 RSS 주소 : http://www.cipher.pe.kr/tt/cipher/rss/comment/132댓글 ATOM 주소 : http://www.cipher.pe.kr/tt/cipher/atom/comment/132