SendMessage - NSIS

프로그래밍/NSIS 2007/02/11 15:02 게으른 엔지니어

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]

 위 코드2를 한번 실행해 보자. 재미난  현상을 볼 수 있을 것이다. Notepad가 실행되고 거기에 h라는 글이 쓰여  질것이다. 인스톨러에서 직접 실행해 보기 바란다. 분석하기 위해서 알아야  할 내용은 이때까지 충분히 알려 줬다고 생각한다.

크리에이티브 커먼즈 라이센스
Creative Commons License
  1. NSIS 홈페이지에서 가져 온 내용이다. [Back]
  2. 홈페이지에서 Borg Number One님이 올리신 내용을 발췌한  내용이다. 약간의 수정을 했다. notepad 실행이 안되서 실행되도록 추가 하고  필요없는 부분은 주석 처리했다. [Back]
이올린에 북마크하기(0) 이올린에 추천하기(0)
받은 트랙백이 없고, 댓글이 없습니다.

댓글+트랙백 RSS :: http://www.cipher.pe.kr/tt/cipher/rss/response/132

댓글+트랙백 ATOM :: http://www.cipher.pe.kr/tt/cipher/atom/response/132

트랙백 주소 :: http://www.cipher.pe.kr/tt/cipher/trackback/132

트랙백 RSS :: http://www.cipher.pe.kr/tt/cipher/rss/trackback/132

트랙백 ATOM :: http://www.cipher.pe.kr/tt/cipher/atom/trackback/132

댓글을 달아 주세요

댓글 RSS 주소 : http://www.cipher.pe.kr/tt/cipher/rss/comment/132
댓글 ATOM 주소 : http://www.cipher.pe.kr/tt/cipher/atom/comment/132
[로그인][오픈아이디란?]