Who are you?


이동범(Dongbum Lee)


Microsoft Regional Director


Microsoft MVP - VB.net


MHVB.net 시삽

Wanna talk with me?

Here I am

Subscription

MSN 메신저를 통해 글이 갱신되면 알려드립니다.

Windows Live Alerts

Search

Navigation

Categories

.net (14) Ajax (1) asp.net (2) AxWebBrowser (1) blog (3) browser (1) das blog (1) dasBlog (2) DataGridView (1) Google (1) ie (1) iis (1) javascript (1) jQuery (1) Microsoft (14) Office (2) OOXML (1) Silverlight (1) Team System (2) UX (1) VB (3) vb.net (4) Vista (1) visual studio (5) visual studio 2010 (1) windows7 (1) Winform (3) WinFX (1) WPF (2) 독점 (1) 음악 (1) 일상 (7) 조용필 (1)

On this page

AxWebBrowser 컨트롤을 사용하는 MDI 폼에서 Focus를 받을 수 없다구?

Archive

Blogroll

Notice

알림
본 블로그는 저의 개인적인 의견을 담고 있습니다.
제가 몸담고 있는 조직의 공식적인 의견과는 다를 수 있습니다.

RSS 2.0 | Atom 1.0 | CDF Send mail to the author(s) E-mail

BlogStats

Total Posts: 39
This Year: 14
This Month: 0
This Week: 0
Comments: 9

Sign In

# Thursday, December 13, 2007
Thursday, December 13, 2007 1:52:31 AM (Korea Standard Time, UTC+09:00) ( .net | AxWebBrowser | vb.net | Winform )

(MDI Childform contains AxWebBrowser control can not be focused(activated) when this control is selected.)

비따 회원의 질문 중에 흥미로운 것이 있어 옮겨 본다.
윈폼 개발 중 WebBrowser 컨트롤을 사용할 경우 부득 WebBrowser Control 대신 기존 방식처럼 AxWebBrowser컨트롤(AxImp를 통한 RCW 생성을 통해)을 만들어 사용하게 된다.

이 경우 해당 폼이 MDI Child로 사용될 경우, MDI Form 내부에서 해당 웹브라우저 컨트롤을 사용자가 클릭했음에도 불구하고 타이틀바를 클릭하지 않는 이상 폼이 활성화 되지 않는 황당한 경우가 발생한다. 아마도 제대로 웹브라우저 RCW 코드에서 메세지 처리를 완벽하게 못 만들어 내는 것 같다.

Reflector로 까 봐야 자세히 알겠지만, 귀찮아서 생략한다. 대신 직감으로 WM_MOUSEACTIVATE 메세지를 가로채 해당 이벤트에서 컨트롤이 담겨진 폼을 찾아 Focus 받도록 메서드 날려준다.

소스는 초 간단. RCW - AxWebBrowser 컨트롤을 상속받아 WndProc 메서드를 재정의 해 준다.

Public Class AxFocusedBrowser
    Inherits AxSHDocVw.AxWebBrowser

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If m.Msg = &H21 Then 'WM_MOUSEACTIVATE 
            Dim parentObject As Object = Me.Parent
            Do While Not (TypeOf parentObject Is System.Windows.Forms.Form)
                parentObject = parentObject.Parent
            Loop
            parentObject.Focus()
        End If
        MyBase.WndProc(m)
    End Sub
End Class

아.. 깔끔한 VB 코드.. 난 이 Object 타입에 아무렇지 않게 메서드와 프로퍼티를 지정해 줄 수 있는 융통성이 좋다.
Dynamic VB! <img alt=" src="smilies/happy.gif">