HwndSource HwndSource HwndSource HwndSource Class

定義

在 Win32 視窗中顯示 Windows Presentation Foundation (WPF) 內容。Presents Windows Presentation Foundation (WPF) content in a Win32 window.

public ref class HwndSource : System::Windows::PresentationSource, IDisposable, System::Windows::Interop::IKeyboardInputSink, System::Windows::Interop::IWin32Window
public class HwndSource : System.Windows.PresentationSource, IDisposable, System.Windows.Interop.IKeyboardInputSink, System.Windows.Interop.IWin32Window
type HwndSource = class
    inherit PresentationSource
    interface IDisposable
    interface IWin32Window
    interface IKeyboardInputSink
Public Class HwndSource
Inherits PresentationSource
Implements IDisposable, IKeyboardInputSink, IWin32Window
繼承
實作

備註

重要

此類別的許多成員在網際網路安全性區域中無法使用。Many members of this class are unavailable in the Internet security zone.

會執行HwndSource可包含WPFWPF內容的視窗。Win32Win32An HwndSource implements a Win32Win32 window that can contain WPFWPF content. 視窗WPFWPF中的內容會進行排列、測量和轉譯, 而且是輸入的互動式。The WPFWPF content in the window is arranged, measured, and rendered; and is interactive to input. 因為是特別設計來與Win32Win32交互操作, 所以這個類別會公開數個Win32Win32低層級功能。 HwndSourceBecause the HwndSource is specifically designed to interoperate with Win32Win32, this class exposes several low-level Win32Win32 features. 您可以使用這個類別來執行下列動作:You can use this class to do the following:

  • 指定視窗樣式、視窗類別樣式和擴充視窗樣式。Specify window styles, window class styles, and extended window styles.

  • 掛上視窗程式。Hook the window procedure.

  • 提供視窗控制碼 (HWND) 的存取權。Provide access to the window handle (HWND).

  • 終結視窗。Destroy the window.

HwndSource類別是針對一般互通性而設計, 而且不是設計為 managed HWND 包裝函式。The HwndSource class is designed for general interoperability and is not designed as a managed HWND wrapper. 一般來說, 它不會提供管理方法來操作視窗或屬性來檢查其狀態。In general, it does not provide managed methods for manipulating the window or properties for inspecting its state. 相反地, HwndSource類別會透過Handle屬性來Win32Win32提供視窗控制碼 (HWND) 的存取權, 而這種方法可以利用 PInvoke 技術Win32Win32傳遞給APIAPIs來操作視窗。Instead, the HwndSource class provides access to the Win32Win32 window handle (HWND) through the Handle property, which can be passed by means of PInvoke techniques to Win32Win32 APIAPIs in order to manipulate the window.

完成Construction

HwndSource許多層面只能在結構時間指定。Many aspects of the HwndSource can only be specified at construction time. 若要建立HwndSource, 請先HwndSourceParameters建立結構, 並在其中填入所需的參數。To create an HwndSource, first create an HwndSourceParameters structure and populate it with the desired parameters. 這些參數包括下列各項:These parameters include the following:

  • [類別]、[視窗] 和 [擴充] 視窗樣式。The class, window, and extended window styles. 建立視窗之後, 您必須使用 PInvoke 來變更樣式。You must use PInvoke to change the styles after the window is created. 並非所有樣式都可以在視窗建立後變更。Not all styles can be changed after the window is created. 變更視窗Win32Win32樣式之前, 請先參閱檔。Consult the Win32Win32 documentation before changing window styles.

  • 視窗的初始位置。The initial position of the window.

  • 視窗的初始大小, 包括是否已指定大小, 或是否應該從WPFWPF內容的決定大小來決定。The initial size of the window, which includes whether the size is specified or should be determined from the determined size of the WPFWPF content.

  • 父視窗。The parent window.

  • HwndSourceHook包含在視窗程式鏈中的。The HwndSourceHook to include in the window procedure chain. 如果您在結構時間指定勾點, 它會接收視窗的所有訊息。If you specify a hook at construction time, it receives all messages for the window. 您可以使用AddHook , 在建立視窗之後加入攔截。You can use AddHook to add a hook after the window is created.

  • 透明度設定。The transparency settings. 最上層視窗可以根據WPFWPF內容的每圖元透明度, 設定成與桌面上的其他視窗 blend。A top-level window can be configured to blend with the other windows on the desktop according to the per-pixel transparency of the WPFWPF content. 若要啟用此功能, UsesPerPixelOpacity請將HwndSourceParameters中的true屬性設定為。To enable this, set the UsesPerPixelOpacity property in the HwndSourceParameters to true. 這個屬性只能在結構時間指定, 而且只能透過HwndSource(HwndSourceParameters)函式簽章, 而且會強加數個限制。This property can only be specified at construction time, and only through the HwndSource(HwndSourceParameters) constructor signature, and it imposes several limitations.

在您填入HwndSourceParameters結構之後, 請將它傳遞HwndSource(HwndSourceParameters)HwndSource的函式。After you populate the HwndSourceParameters structure, pass it to the HwndSource(HwndSourceParameters) constructor for the HwndSource.

物件存留期Object Lifetime

HwndSource是一般通用語言執行平台 (CLR)common language runtime (CLR)物件, 其存留期是由垃圾收集行程管理。An HwndSource is a regular 通用語言執行平台 (CLR)common language runtime (CLR) object, and its lifetime is managed by the garbage collector. 因為代表非受控資源IDisposable, HwndSource所以會執行。 HwndSourceBecause the HwndSource represents an unmanaged resource, HwndSource implements IDisposable. 如果從Dispose擁有者執行緒Win32Win32呼叫, 同步呼叫會立即終結視窗。Synchronously calling Dispose immediately destroys the Win32Win32 window if called from the owner thread. 如果是從另一個執行緒呼叫Win32Win32 , 則會以非同步方式終結視窗。If called from another thread, the Win32Win32 window is destroyed asynchronously. 某些Dispose互通案例可能需要明確地從互通性程式碼呼叫。Calling Dispose explicitly from the interoperating code might be necessary for certain interoperation scenarios.

視窗程式Window Procedures

HwndSource類別會實作為其本身的視窗程式。The HwndSource class implements its own window procedure. 這個視窗程式是用來處理重要的視窗訊息, 例如與版面配置、轉譯和輸入相關的訊息。This window procedure is used to process important window messages, such as those related to layout, rendering, and input. 不過, 您也可以將視窗程式與您自己的使用連結在一起。However, you can also hook the window procedure for your own use. 您可以藉由設定HwndSourceParameters.HwndSourceHook屬性在您的結構中指定自己的攔截, 或者也可以使用AddHookRemoveHook來新增和移除視窗建立後的勾點。You can specify your own hook during construction by setting the HwndSourceParameters.HwndSourceHook property, or you can also use AddHook and RemoveHook to add and remove hooks after the window is created. 攔截會由後進先出順序呼叫, 這可讓您的勾點在內建處理之前執行。The hooks are called by last-in first-out order, which enables your hooks to execute before the built-in processing. 實際的勾點是由弱式參考所持有。The actual hooks are held by a weak reference. 因此, 請確定您管理攔截委派的存留期。Therefore, make sure that you manage the lifetime of your hook delegate.

如需HwndSource和其他交互操作類別的詳細資訊, 請參閱WPF 和 Win32 交互操作For more information about HwndSource and other interoperation classes, see WPF and Win32 Interoperation.

請注意, HwndSource的函式會採用類似CreateWindowEx等函Win32Win32式參數的參數。Notice how the constructors for HwndSource take parameters that resemble the parameters for Win32Win32 functions such as CreateWindowEx.

縮放轉換不應套用至RootVisual HwndSource的。Scale transformations should not be applied to the RootVisual of an HwndSource. 請參閱的RootVisual備註。See Remarks for RootVisual.

建構函式

HwndSource(HwndSourceParameters) HwndSource(HwndSourceParameters) HwndSource(HwndSourceParameters) HwndSource(HwndSourceParameters)

使用包含初始設定值的結構,初始化 HwndSource 類別的新執行個體。Initializes a new instance of the HwndSource class by using a structure that contains the initial settings.

HwndSource(Int32, Int32, Int32, Int32, Int32, Int32, Int32, String, IntPtr) HwndSource(Int32, Int32, Int32, Int32, Int32, Int32, Int32, String, IntPtr) HwndSource(Int32, Int32, Int32, Int32, Int32, Int32, Int32, String, IntPtr) HwndSource(Int32, Int32, Int32, Int32, Int32, Int32, Int32, String, IntPtr)

使用指定的類別樣式、樣式、延伸樣式、x-y 位置、寬度、高度、名稱和父視窗,初始化 HwndSource 類別的新執行個體。Initializes a new instance of the HwndSource class with a specified class style, style, extended style, x-y position, width, height, name, and parent window.

HwndSource(Int32, Int32, Int32, Int32, Int32, Int32, Int32, String, IntPtr, Boolean) HwndSource(Int32, Int32, Int32, Int32, Int32, Int32, Int32, String, IntPtr, Boolean) HwndSource(Int32, Int32, Int32, Int32, Int32, Int32, Int32, String, IntPtr, Boolean) HwndSource(Int32, Int32, Int32, Int32, Int32, Int32, Int32, String, IntPtr, Boolean)

使用指定的類別樣式、樣式、延伸樣式、x-y 位置、寬度、高度、名稱和父視窗,以及指定視窗是否自動調整大小,初始化 HwndSource 類別的新執行個體。Initializes a new instance of the HwndSource class with a specified class style, style, extended style, x-y position, width, height, name, and parent window, and by specifying whether the window is autosized.

HwndSource(Int32, Int32, Int32, Int32, Int32, String, IntPtr) HwndSource(Int32, Int32, Int32, Int32, Int32, String, IntPtr) HwndSource(Int32, Int32, Int32, Int32, Int32, String, IntPtr) HwndSource(Int32, Int32, Int32, Int32, Int32, String, IntPtr)

使用指定的類別樣式、樣式、延伸樣式、x-y 位置、名稱和父視窗,初始化 HwndSource 類別的新執行個體。Initializes a new instance of the HwndSource class with a specified class style, style, extended style, x-y position, name, and parent window.

屬性

AcquireHwndFocusInMenuMode AcquireHwndFocusInMenuMode AcquireHwndFocusInMenuMode AcquireHwndFocusInMenuMode

取得值,這個值決定是否針對此 HwndSource,為包含 WPF 的視窗取得 Win32 焦點。Gets the value that determines whether to acquire Win32 focus for the WPF containing window for this HwndSource.

ChildKeyboardInputSinks ChildKeyboardInputSinks ChildKeyboardInputSinks ChildKeyboardInputSinks

取得註冊的輸入接收器序列。Gets a sequence of registered input sinks.

CompositionTarget CompositionTarget CompositionTarget CompositionTarget

取得所裝載之視窗的視覺管理員。Gets the visual manager for the hosted window.

DefaultAcquireHwndFocusInMenuMode DefaultAcquireHwndFocusInMenuMode DefaultAcquireHwndFocusInMenuMode DefaultAcquireHwndFocusInMenuMode

取得或設定 AcquireHwndFocusInMenuMode 之新執行個體的 HwndSource 預設值。Gets or sets the default AcquireHwndFocusInMenuMode value for new instances of HwndSource.

Dispatcher Dispatcher Dispatcher Dispatcher

取得與這個 Dispatcher 關聯的 DispatcherObjectGets the Dispatcher this DispatcherObject is associated with.

(Inherited from DispatcherObject)
Handle Handle Handle Handle

取得這個 HwndSource 的視窗控制代碼。Gets the window handle for this HwndSource.

IsDisposed IsDisposed IsDisposed IsDisposed

取得值,指出是否已針對這個 Dispose() 呼叫 HwndSourceGets a value that indicates whether Dispose() has been called on this HwndSource.

KeyboardInputSiteCore KeyboardInputSiteCore KeyboardInputSiteCore KeyboardInputSiteCore

取得或設定對元件容器之 IKeyboardInputSite 介面的參考。Gets or sets a reference to the component's container's IKeyboardInputSite interface.

RestoreFocusMode RestoreFocusMode RestoreFocusMode RestoreFocusMode

取得視窗的 RestoreFocusModeGets the RestoreFocusMode for the window.

RootVisual RootVisual RootVisual RootVisual

取得或設定視窗的 RootVisualGets or sets the RootVisual of the window.

SizeToContent SizeToContent SizeToContent SizeToContent

取得或設定視窗是否以及如何調整至其內容大小。Get or sets whether and how the window is sized to its content.

UsesPerPixelOpacity UsesPerPixelOpacity UsesPerPixelOpacity UsesPerPixelOpacity

取得值,這個值會宣告是否遵守來源視窗內容之每像素的不透明度。Gets a value that declares whether the per-pixel opacity of the source window content is respected.

方法

AddHook(HwndSourceHook) AddHook(HwndSourceHook) AddHook(HwndSourceHook) AddHook(HwndSourceHook)

加入接收所有視窗訊息的事件處理常式。Adds an event handler that receives all window messages.

AddSource() AddSource() AddSource() AddSource()

新增 PresentationSource 衍生類別執行個體至已知展示來源的清單。Adds a PresentationSource derived class instance to the list of known presentation sources.

(Inherited from PresentationSource)
CheckAccess() CheckAccess() CheckAccess() CheckAccess()

判斷呼叫的執行是否可以存取這個 DispatcherObjectDetermines whether the calling thread has access to this DispatcherObject.

(Inherited from DispatcherObject)
ClearContentRenderedListeners() ClearContentRenderedListeners() ClearContentRenderedListeners() ClearContentRenderedListeners()

ContentRendered 事件的接聽程式清單設定為 nullSets the list of listeners for the ContentRendered event to null.

(Inherited from PresentationSource)
CreateHandleRef() CreateHandleRef() CreateHandleRef() CreateHandleRef()

取得 HwndSource 的視窗控制代碼。Gets the window handle for the HwndSource. 視窗控制代碼會封裝為 HandleRef 結構的一部分。The window handle is packaged as part of a HandleRef structure.

Dispose() Dispose() Dispose() Dispose()

釋放 HwndSource 所使用的所有 Managed 資源,並引發 Disposed 事件。Releases all managed resources that are used by the HwndSource, and raises the Disposed event.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
FromHwnd(IntPtr) FromHwnd(IntPtr) FromHwnd(IntPtr) FromHwnd(IntPtr)

傳回指定之視窗的 HwndSource 物件。Returns the HwndSource object of the specified window.

GetCompositionTargetCore() GetCompositionTargetCore() GetCompositionTargetCore() GetCompositionTargetCore()

取得視窗的視覺目標。Gets the visual target of the window.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
HasFocusWithinCore() HasFocusWithinCore() HasFocusWithinCore() HasFocusWithinCore()

取得值,這個值表示接收或其包含的其中一個元件是否有焦點。Gets a value that indicates whether the sink or one of its contained components has focus.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
OnDpiChanged(HwndDpiChangedEventArgs) OnDpiChanged(HwndDpiChangedEventArgs) OnDpiChanged(HwndDpiChangedEventArgs) OnDpiChanged(HwndDpiChangedEventArgs)

於視窗的 DPI 將變更時呼叫。Called when the DPI is going to change for the window.

OnMnemonicCore(MSG, ModifierKeys) OnMnemonicCore(MSG, ModifierKeys) OnMnemonicCore(MSG, ModifierKeys) OnMnemonicCore(MSG, ModifierKeys)

當叫用這個接收的其中一個助憶鍵 (便捷鍵 (Access Key)) 時呼叫。Called when one of the mnemonics (access keys) for this sink is invoked.

RegisterKeyboardInputSinkCore(IKeyboardInputSink) RegisterKeyboardInputSinkCore(IKeyboardInputSink) RegisterKeyboardInputSinkCore(IKeyboardInputSink) RegisterKeyboardInputSinkCore(IKeyboardInputSink)

註冊所包含之元件的 IKeyboardInputSink 介面。Registers the IKeyboardInputSink interface of a contained component.

RemoveHook(HwndSourceHook) RemoveHook(HwndSourceHook) RemoveHook(HwndSourceHook) RemoveHook(HwndSourceHook)

移除由 AddHook(HwndSourceHook) 加入的事件處理常式。Removes the event handlers that were added by AddHook(HwndSourceHook).

RemoveSource() RemoveSource() RemoveSource() RemoveSource()

PresentationSource 衍生類別執行個體從已知展示來源的清單中移除。Removes a PresentationSource derived class instance from the list of known presentation sources.

(Inherited from PresentationSource)
RootChanged(Visual, Visual) RootChanged(Visual, Visual) RootChanged(Visual, Visual) RootChanged(Visual, Visual)

提供告知,指出根 Visual 已變更。Provides notification that the root Visual has changed.

(Inherited from PresentationSource)
TabIntoCore(TraversalRequest) TabIntoCore(TraversalRequest) TabIntoCore(TraversalRequest) TabIntoCore(TraversalRequest)

將焦點設定在接收的第一個定位停駐點 (Tab Stop) 或最後一個定位停駐點。Sets focus on either the first tab stop or the last tab stop of the sink.

ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)
TranslateAcceleratorCore(MSG, ModifierKeys) TranslateAcceleratorCore(MSG, ModifierKeys) TranslateAcceleratorCore(MSG, ModifierKeys) TranslateAcceleratorCore(MSG, ModifierKeys)

在按下按鍵時的訊息層級處理鍵盤輸入。Processes keyboard input at the key-down message level.

TranslateCharCore(MSG, ModifierKeys) TranslateCharCore(MSG, ModifierKeys) TranslateCharCore(MSG, ModifierKeys) TranslateCharCore(MSG, ModifierKeys)

先處理 WM_CHAR、WM_SYSCHAR、WM_DEADCHAR 和 WM_SYSDEADCHAR 輸入訊息,接著呼叫 OnMnemonic(MSG, ModifierKeys) 方法。Processes WM_CHAR, WM_SYSCHAR, WM_DEADCHAR, and WM_SYSDEADCHAR input messages before the OnMnemonic(MSG, ModifierKeys) method is called.

VerifyAccess() VerifyAccess() VerifyAccess() VerifyAccess()

請強制執行可以存取這個 DispatcherObject 的呼叫執行緒。Enforces that the calling thread has access to this DispatcherObject.

(Inherited from DispatcherObject)

事件

AutoResized AutoResized AutoResized AutoResized

當進行配置而需要 HwndSource 自動調整大小時發生。Occurs when layout causes the HwndSource to automatically resize.

ContentRendered ContentRendered ContentRendered ContentRendered

內容已呈現且可以進行使用者互動時發生。Occurs when content is rendered and ready for user interaction.

(Inherited from PresentationSource)
Disposed Disposed Disposed Disposed

在這個物件上呼叫 Dispose() 方法時發生。Occurs when the Dispose() method is called on this object.

DpiChanged DpiChanged DpiChanged DpiChanged

發生於此 Hwnd 的螢幕 DPI 已變更時,或是將 Hwnd 移至不同 DPI 的螢幕時。Occurs when the DPI of the monitor of this Hwnd has changed, or the Hwnd is moved to a monitor with a different DPI.

SizeToContentChanged SizeToContentChanged SizeToContentChanged SizeToContentChanged

發生於 SizeToContent 屬性的值變更時。Occurs when the value of the SizeToContent property changes.

明確介面實作

IKeyboardInputSink.HasFocusWithin() IKeyboardInputSink.HasFocusWithin() IKeyboardInputSink.HasFocusWithin() IKeyboardInputSink.HasFocusWithin()

如需這個成員的說明,請參閱 IList.Remove(Object)For a description of this member, see IList.Remove(Object).

IKeyboardInputSink.KeyboardInputSite IKeyboardInputSink.KeyboardInputSite IKeyboardInputSink.KeyboardInputSite IKeyboardInputSink.KeyboardInputSite

如需這個成員的說明,請參閱 KeyboardInputSiteFor a description of this member, see KeyboardInputSite.

IKeyboardInputSink.OnMnemonic(MSG, ModifierKeys) IKeyboardInputSink.OnMnemonic(MSG, ModifierKeys) IKeyboardInputSink.OnMnemonic(MSG, ModifierKeys) IKeyboardInputSink.OnMnemonic(MSG, ModifierKeys)

如需這個成員的說明,請參閱 OnMnemonic(MSG, ModifierKeys)For a description of this member, see OnMnemonic(MSG, ModifierKeys).

IKeyboardInputSink.RegisterKeyboardInputSink(IKeyboardInputSink) IKeyboardInputSink.RegisterKeyboardInputSink(IKeyboardInputSink) IKeyboardInputSink.RegisterKeyboardInputSink(IKeyboardInputSink) IKeyboardInputSink.RegisterKeyboardInputSink(IKeyboardInputSink)

如需這個成員的說明,請參閱 RegisterKeyboardInputSink(IKeyboardInputSink)For a description of this member, see RegisterKeyboardInputSink(IKeyboardInputSink).

IKeyboardInputSink.TabInto(TraversalRequest) IKeyboardInputSink.TabInto(TraversalRequest) IKeyboardInputSink.TabInto(TraversalRequest) IKeyboardInputSink.TabInto(TraversalRequest)

如需這個成員的說明,請參閱 TabInto(TraversalRequest)For a description of this member, see TabInto(TraversalRequest).

IKeyboardInputSink.TranslateAccelerator(MSG, ModifierKeys) IKeyboardInputSink.TranslateAccelerator(MSG, ModifierKeys) IKeyboardInputSink.TranslateAccelerator(MSG, ModifierKeys) IKeyboardInputSink.TranslateAccelerator(MSG, ModifierKeys)

如需這個成員的說明,請參閱 TranslateAccelerator(MSG, ModifierKeys)For a description of this member, see TranslateAccelerator(MSG, ModifierKeys).

IKeyboardInputSink.TranslateChar(MSG, ModifierKeys) IKeyboardInputSink.TranslateChar(MSG, ModifierKeys) IKeyboardInputSink.TranslateChar(MSG, ModifierKeys) IKeyboardInputSink.TranslateChar(MSG, ModifierKeys)

如需這個成員的說明,請參閱 TranslateChar(MSG, ModifierKeys)For a description of this member, see TranslateChar(MSG, ModifierKeys).

適用於

另請參閱