나눔터  
  HOME > 나눔터 > 묻고답하기 > 엑셀
엑셀
엑셀에 대한 질문과 답변을 올려주세요. 단, 취지에 맞지 않는 글은 운영자가 삭제합니다.
 "000 님, 도와주세요", "부탁 드립니다.", "급합니다!" 등과 같이 막연한 제목을 달지 말아주세요.
[필독] 빠르고 정확한 답변을 얻는 16가지 Tip !
[필독] 저작권법 개정에 따른 이용안내
작성자:  

 작은오리 (수연108)

추천:  2
파일:     조회:  2313
제목:   [RE]질문하는김에 또한가지 더.... FindWindow
     
  * 답변하시는 분들께 도움이 되도록 자신의 환경을 아래 항목 옆에 기재해 주세요.

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
 

 
[불량 게시물 신고]  
놀란토끼오웃... 작은오리님 캄사합니다.
GetClassName 에 키뽀인뜨가 있었네요. 자료 잘 간직하께요...
08-26 (14:54)
삭제 ■신고
        
  

작성일 : 2003-08-26(13:53)
최종수정일 : 2003-08-26(13:53)
 


 ◎ 관련글

  제 목   작성자   날짜
질문하는김에 또한가지 더.... FindWindow 놀란토끼 2003-08-25
[RE]질문하는김에 또한가지 더.... FindWindow 작은오리 2003-08-26