Problem with RichTextBox-Control WndProc and FindText Windows API Function,...

K

Kerem Gümrükcü

Hi,

i override the RichTextBox-Control Classes WndProc to get the FINDMSGSTRING
wich is always UINT 49261 on my system for "commdlg_FindReplace". Inside
the
OnHandleCreated Member Function i construct the FINDREPLACE-Structure like
this:

//in class section defined
private Win32API.FINDREPLACE FindReplaceData;
private IntPtr szFindWhat;
private IntPtr FRWndHandle;

//inside class constructor
this.FindWindowMessage =
Win32API.RegisterWindowMessage("commdlg_FindReplace");

//inside OnHandleCreated
this.szFindWhat = Marshal.AllocHGlobal(1024);
Win32API.ZeroMemory(this.szFindWhat, 1024);
this.FindReplaceData = new Win32API.FINDREPLACE();

this.FindReplaceData.lStructSize = (uint)
Marshal.SizeOf(typeof(Win32API.FINDREPLACE));
this.FindReplaceData.hwndOwner = this.Handle;
this.FindReplaceData.lpstrFindWhat = this.szFindWhat;
this.FindReplaceData.wFindWhatLen = 1024;

this.FindReplaceData.hInstance = IntPtr.Zero;
this.FindReplaceData.lCustData = IntPtr.Zero;
this.FindReplaceData.lpstrReplaceWith = IntPtr.Zero;
this.FindReplaceData.lpTemplateName = IntPtr.Zero;

this.FindReplaceData.Flags =
Win32API.FindReplaceFlags.FR_HIDEUPDOWN |
Win32API.FindReplaceFlags.FR_ENABLEHOOK;

this.FindReplaceData.lpfnHook = FRHookProc;

//inside WndProc
if (m.Msg == (int) this.FindWindowMessage)
{
//will never be executed, since the condition above never
meets!!!

Win32API.FINDREPLACE lpfr =
(Win32API.FINDREPLACE)Marshal.PtrToStructure(m.LParam,
typeof(Win32API.FINDREPLACE));
//never send to the debugger or stuff like DbgView
Win32API.Win32APIInternal.OutputDebugStringCRLF(Marshal.PtrToStringAuto(lpfr.lpstrFindWhat));
}

//this is how i make the dialog come up
private void ShowFindTextDialogInternal()
{
if (Win32API.IsWindow(this.FRWndHandle) == false)
{
this.FRWndHandle = Win32API.FindText(ref
this.FindReplaceData);

if (this.FRWndHandle == IntPtr.Zero)
{
//error will be handled here
}
}
}


The WndProc of the RichTextBox-Class never receives the FINDMSGSTRING
Message?
Why, why, why???


The Point is: Does the FINDREPLACE.hwndOwner has to be a REAL Window with
special window attributes or (Ex)Styles? Does the FindText check the target
Window
for some special Attributes or does it accept any WindowProc/WndProc that it
gets?
I ask this, because i do not get any FINDMSGSTRING Messages on the WndProc
of
the RichTextBox-Classes overriden WndProc,.....why? Am i doing something
wrong here,
or what could be the problem?


Any Ideas,...

TIA

Regards

Kerem

--
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Latest Project: http://www.pro-it-education.de/software/deviceremover
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
 
T

Tim Roberts

Kerem Gümrükcü said:
The WndProc of the RichTextBox-Class never receives the FINDMSGSTRING
Message?

Right. That message is sent to the hwndOnwer, not to the RichTextBox.
The Point is: Does the FINDREPLACE.hwndOwner has to be a REAL Window with
special window attributes or (Ex)Styles? Does the FindText check the target
Window for some special Attributes or does it accept any WindowProc/WndProc
that it gets?

It has to be a window that accepts messages, that's all.
 
K

Kerem Gümrükcü

Hi Tim,

thanks for your reply!
Right. That message is sent to the hwndOnwer, not to the RichTextBox.

The RichTextBox is a own system class named "RichEdit" or "RICHEDIT_CLASS",
depending on the Library Version you are using. It has a own Window Handle
and
a own WindowProc, that can either be overrided or subclassed/hooked. When i
use the RichEdit Handle to set the hwndOwner, the FindText function does not
complain, what means to me that it has accepted the Window Handle to send
messages to it. So why does the function not complain on the structure that
i pass
to the FindText() and silenlty accepts it without making sure it is a
special window
and not control? Is this some implementation bug?
It has to be a window that accepts messages, that's all.

HWND is a handle to a Window, so why does it fail? This is really not
clear to me, since e.g. SetWindowsHookEx() with WH_CALLWNDPROC
accepts anything that is a valid Window Handle and has a Window Procedure.

Well, whatever, i have to find a different solutuon for this,...

Regards

Kerem

--
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Latest Project: http://www.pro-it-education.de/software/deviceremover
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top