Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am using C++ builder to add a search function to my text editor and am getting some odd behavior from the Windows API "Find: dialog box. When the program is running and text is entered into the Find what edit box, each character shows up four times! For example, if I type:
"Weird"
it displays on screen as
WWWWeeeeiiiirrrrdddd
Has anyone seen that happen before or know what might be causing the problem?
Windows handles all of the processing of the dialog until the user clicks on the find button, so I don't see how my code could be the culprit. To display the dialog I used
FindText()
and of course in between the parenthesis I put a reference to my FINDREPLACE structure.
P.S. I am not in school or taking any courses (this is not homework), I actually do this because I enjoy it. Although it can be extremely frustrating and confusing.

It almost sounds to me as if the MAPI interface isn't getting the message to stop or clear the keyboard message at the Find dialog object.
borelli35

It's Borland C++ builder 5.5 (free command line tools.)
All of the following code is declared globally at the beginning of the program:
char g_cFindBuff[80] = "";
FINDREPLACE frst;
UINT g_uFindMsg;
HWND g_hFind = NULL;In WinMain I initialize the FINDREPLACE structure (frst) with the following:
frst.lStructSize = sizeof(frst);
frst.hwndOwner = g_hMainWindow;
frst.Flags = FR_DOWN;
frst.lpstrFindWhat = g_cFindBuff;
frst.wFindWhatLen = 80;In my MDI window procedure the ID_EDIT_FIND message from my edit menu is handled using the following code:
g_hFind = FindText(&frst);
And finally in my main window procedure, before the switch/case statements filter the message I check for my registered message g_uFindMsg using this:
if(msg == g_uFindMsg)
{
LPFINDREPLACE lpfr;
lpfr = (LPFINDREPLACE)lParam;if (lpfr->Flags & FR_DIALOGTERM)
{
g_hFind = NULL;
return 0;
}if (lpfr->Flags & FR_FINDNEXT)
SearchFile((BOOL) (lpfr->Flags & FR_DOWN), (BOOL)
(lpfr->Flags & FR_MATCHCASE));
return 0;
}
I'm probably decalring too many global variables but I had a hard time just getting to this point, I will make the code better once it works correctly. I have the Windows API programmers reference help file and I use it, but it's not exactly a "how-to" style document!

Hey I solved the problem! And I found an error in the API programmer's reference unless I'm interpreting it incorrectly.
When it gives an example of using a find/replace dialog it states the following:
"When the dialog box is open, your main message loop must include a call to the IsDialogMessage function. Pass the window handle of the dialog box as a parameter in the IsDialogMessage call. This ensures that the dialog box correctly processes keyboard messages."
It says to pass the dialog boxes handle as a parameter in the IsDialogMessage function. I got to thinking about it and decided to try passing instead the handle to the main window since it receives my registered message. I tried it, expecting to get an illegal operation error message or worse a blue screen, but instead it stopped the problem and the dialog now takes keyboard input just as it should. Now I can work on programming the code to actually search for the string and highlight the appropriate text in my edit window.
Thanks to everyone who viewed this post and spent any amount of time scratching their head or racking their brain. :)

Update: The comment above was wrong! The API programmer's reference was correct. When I changed the handle in the IsDialogMessage statement it fixed the problem in the find/replace dialog but when I entered text in the open document it would type quadruple characters. I just moved the problem from one place to another.
I came to the conclusion that my main message loop could be causing the problem. I changed a couple of things and now everything works fine.
Here is the corrected message loop:
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
if (!TranslateMDISysAccel(g_hMDIClient, &Msg));
{
if(!IsDialogMessage(g_hFind, &Msg))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
}
return Msg.wParam;

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |