[This is preliminary documentation and is subject to change.]

Gets or sets wnd proc of current window. Used for so-called window sub-classing.

Namespace: Tools.WindowsT.NativeT
Assembly: Tools.Win (in Tools.Win.dll) Version: 1.5.3.38916 (1.5.3.38916)

Syntax

C#
[LCategoryAttribute(typeof(ControlsWin), "LowLevel_c", "Low-level", 
	LCategoryAttribute..::..enmLookUpOrder.ResourceFirst)]
public virtual WndProc WndProc { get; set; }
Visual Basic
<LCategoryAttribute(GetType(ControlsWin), "LowLevel_c", "Low-level",  _
	LCategoryAttribute..::..enmLookUpOrder.ResourceFirst)> _
Public Overridable Property WndProc As WndProc
	Get
	Set
Visual C++
[LCategoryAttribute(typeof(ControlsWin), L"LowLevel_c", L"Low-level", 
	LCategoryAttribute..::..enmLookUpOrder::ResourceFirst)]
public:
virtual property WndProc^ WndProc {
	WndProc^ get ();
	void set (WndProc^ value);
}
F#
[<LCategoryAttribute(typeof(ControlsWin), "LowLevel_c", "Low-level", 
    LCategoryAttribute..::..enmLookUpOrder.ResourceFirst)>]
abstract WndProc : WndProc with get, set
[<LCategoryAttribute(typeof(ControlsWin), "LowLevel_c", "Low-level", 
    LCategoryAttribute..::..enmLookUpOrder.ResourceFirst)>]
override WndProc : WndProc with get, set
JScript
function get WndProc () : WndProc
function set WndProc (value : WndProc)

Field Value

New window proc. Note: Old window proc is lost by setting this property. You should consider backing it up.

Warning: By setting value of this property youar passing delegate to unmanaged code! You must keep that delegate alive as long as it is in use - that means while the window exists or until WndProc property is changed again. For example following VB code is completely invalid!

Examples

CopyVB.NET
instance.WndProc = AddressOf MyReplacementProc

This example creates new delegate, passes it to unmanaged code, and forgets it. The is no reference to that delegate keeping it alive (protecting it from being garbage collected), so you can get unexpected error when the runtime garbage collector collects the delegate and the there is an attempt to call it. The proper way of setting this property is create an instance of WndProc, store it somewhere, pass it here and keep that 'somewhere' alive as long as window uses that replaced wnd proc.

The need to keep delegate alive may be problem when creating backup of previos window procedure in order to revert change of window procedure in the future. This property returns a managed delegate (to possibly onmanaged code). So, this delegate must be kept alive as long as it is used by window. That is not always the think you want to (or can) do. In such case you should considering backing up pointer to the old wnd proc. Pointer can be used to restore the procedure with no need to keep it alive. To do so use the WndProcPointer property. It is common parctise to backup old wnd proc in order to call it from new one. You cannot call a pointer. So, if you need to back up old wnd proc in order to restore it as well as in order to call it, the best think you can do is back it up as pointer as well as as delegate.

Return Value

Delegate to old window proc

Remarks

Window procedure is used to handle messages of current window.

If current window represents .NET Form or other Control and you have chance to derive from it, you'd better to do so and the override WndProc(Message%). You are the proctedted from problems with keeping delegate alive. You can also derive from NativeWindow and override it's WndProc(Message%).

Exceptions

ExceptionCondition
Tools.API..::..Win32APIExceptionGetting or setting value failed (i.e. Handle is invalid). This is also usually thrown when window comes from another process than property is being got.

See Also