回 帖 发 新 帖 刷新版面

主题:FindText函数使用问题请教?

UINT uFindReplaceMsg;  // message identifier for FINDMSGSTRING 
uFindReplaceMsg = RegisterWindowMessage(FINDMSGSTRING);
FINDREPLACE fr;       // common dialog box structure
static char szFindWhat[80];  // buffer receiving string
HWND hfdlg = NULL;     // handle to Find dialog box

// Initialize FINDREPLACE
ZeroMemory(&fr, sizeof(fr));
fr.lStructSize = sizeof(fr);
fr.hwndOwner = hWndEdit;
fr.lpstrFindWhat = szFindWhat;
fr.wFindWhatLen = 80;
fr.Flags = 0;

hfdlg = FindText(&fr);

接着怎么写?小菜查msdn,好象还要用到IsDialogMessage这个函数?
要用sdk实现象记事本上的查找功能,怎么写?菜鸟请教..谁能最好给个例子(最好),大致讲讲思路也行.谢谢了

回复列表 (共2个回复)

沙发

//消息循环这样写

while(GetMessage(&Msg,NULL,0,0))
{
  if(! IsDialogMessage(hdlg,&Msg))//是对话框消息,就直接发给该对话框窗口过程
  {
    if(!TranslateAccelerator(hwnd,hAccel,&Msg))
    {
      TranslateMessage(&Msg);
      DispathMessage(&Msg);

    }
  }


}

为该查找对话框写个窗口过程,并将该窗口过程(函数)的地址赋给FINDREPLACE的LPFRHOOKPROC lpfnHook; 域,这样就能接收注册的消息了。
-----------------------------------------------------------------

板凳

case IDM_FIND:
    uFindReplaceMsg = RegisterWindowMessage(FINDMSGSTRING);
            
    FINDREPLACE fr;       // common dialog box structure
    static char szFindWhat[80];  // buffer receiving string

    // Initialize FINDREPLACE
    ZeroMemory(&fr, sizeof(fr));
    fr.lStructSize = sizeof(fr);
    fr.hwndOwner = hWndEdit;
    fr.lpstrFindWhat = szFindWhat;
    fr.wFindWhatLen = 80;
    fr.Flags = FR_DIALOGTERM | FR_DOWN | FR_FINDNEXT | FR_ENABLEHOOK;
    fr.lpfnHook = FRHookProc;

    hfdlg = FindText(&fr);

UINT CALLBACK FRHookProc(
  HWND hdlg,      // handle to the dialog box window
  UINT uiMsg,      // message identifier
  WPARAM wParam,  // message parameter
  LPARAM lParam   // message parameter
)
{
    LPFINDREPLACE lpfr;
    if (uiMsg == uFindReplaceMsg){
    // Get pointer to FINDREPLACE structure from lParam.
        lpfr = (LPFINDREPLACE)lParam;}

    MessageBox(NULL,"挂钩成功","",MB_OK);
    return 0;
}
这样,一点菜单IDM_FIND消息,就MessageBox(NULL,"挂钩成功","",MB_OK);执行成功.
一直这样.怎么hfdlg = FindText(&fr);连查找弹出框都没了?还有就是如何处理输入的要查找的字符串?要写一个搜索字符串的函数吗?要怎么写?还有一个疑问就是消息直接发给默认处理函数能处理吗?不需要FRHookProc来处理可以吗?多谢大虾帮忙.小菜一直在线等.

我来回复

您尚未登录,请登录后再回复。点此登录或注册