|
* 답변하시는 분들께 도움이 되도록 자신의 환경을 아래 항목 옆에 기재해 주세요.
1. 엑셀 버전(95,97,2000,2002):
2. 윈도우즈의 버전(win95,win98,winME,winNT,win2000,winXP):
3. CPU (486,PentiumI/II/III/IV...):
4. RAM (32,64,128,256,512MB,1G...):
* 아래줄에 질문을 작성하세요 >>
Sub DetectExcel()
' 실행 중인 Excel을 감지하여 등록시킵니다.
Const WM_USER = 1024
Dim hWnd As Long
' 만일 Excel이 실행 중이면 API 호출은 수행을 되돌립니다.
hWnd = FindWindow("XLMAIN", 0)
If hWnd = 0 Then ' 0이면 Excel이 실행 중이 아닙니다.
Exit Sub
Else
'실행 중인 Excel SendMessage API 함수를 사용하여 실행 중인 Excel 개체에 들어갑니다.
SendMessage hWnd, WM_USER + 18, 0, 0
End If
End Sub
위 구문은 도움말에 있는 예제문인데요......
여기서
hWnd = FindWindow("XLMAIN", 0)
FindWindow의 인수로 엑셀을 찾고자 할때 쓰는 구문에서 왜 하필
"XLMAIN" 인지? 즉 엑셀은 XLMAIN 이라고 적어야 된다는 사항을 어디서 확인할수 있는지궁금합니다. 다른응용프로그램들은 어떻게 적어줘야 되는지 그게 막막해서 질문드립니다.
FindWindow에 대해 도움말은 어디서 참고할수 있는지 조언 부탁합니다.
==============[놀란토끼님 글에 대한 답변입니다]==============
안녕하세요? 놀란토끼 님
엑셀2002에 위의 도움말이 있나요?
API함수 꽤(?) 배워둘만하고 쓸모있는 것도 꽤 있네요 ^^*
아래의 사이트에서 퍼온 VB예제입니다.
참고하세요.
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Const SW_SHOWNORMAL = 1
Const WM_CLOSE = &H10
Const gcClassnameMSWord = "OpusApp"
Const gcClassnameMSExcel = "XLMAIN"
Const gcClassnameMSIExplorer = "IEFrame"
Const gcClassnameMSVBasic = "wndclass_desked_gsk"
Const gcClassnameNotePad = "Notepad"
Const gcClassnameMyVBApp = "ThunderForm"
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim WinWnd As Long, Ret As String, RetVal As Long, lpClassName As String
'Ask for a Window title
Ret = InputBox("Enter the exact window title:" + Chr$(13) + Chr$(10) + "Note: must be an exact match")
'Search the window
WinWnd = FindWindow(vbNullString, Ret)
If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
'Show the window
ShowWindow WinWnd, SW_SHOWNORMAL
'Create a buffer
lpClassName = Space(256)
'retrieve the class name
RetVal = GetClassName(WinWnd, lpClassName, 256)
'Show the classname
MsgBox "Classname: " + Left$(lpClassName, RetVal)
'Post a message to the window to close itself
PostMessage WinWnd, WM_CLOSE, 0&, 0&
End Sub
|
|