Winapi can';t使windows公用查找对话框正常工作

Winapi can';t使windows公用查找对话框正常工作,winapi,replace,common-dialog,Winapi,Replace,Common Dialog,我真的不理解这些网络上的例子。它们都是零碎的。没有一个简单简洁的例子可以说明如何创建一个经典的查找文本对话框 我把我所知道的放到这里,但是没有显示任何窗口并返回:2147500037 0x80004005 #include <windows.h> #include <iostream> #include <iomanip> int main() { using namespace std; UINT uFindReplaceMsg; // mess

我真的不理解这些网络上的例子。它们都是零碎的。没有一个简单简洁的例子可以说明如何创建一个经典的查找文本对话框

我把我所知道的放到这里,但是没有显示任何窗口并返回:
2147500037
0x80004005

#include <windows.h>
#include <iostream>
#include <iomanip>

int main() {
  using namespace std;
  UINT uFindReplaceMsg;  // message identifier for FINDMSGSTRING 
  uFindReplaceMsg = RegisterWindowMessage(FINDMSGSTRING);
  wstring search_str = L"text to search";
  HWND findDialog = NULL;
  wchar_t szFindWhat[MAX_PATH];
  FINDREPLACEW fr;
  ZeroMemory( & fr, sizeof( FINDREPLACEW ) );
  fr.lStructSize = sizeof( FINDREPLACEW );
  fr.hwndOwner = NULL;
  fr.lpstrFindWhat = szFindWhat;
  fr.wFindWhatLen = MAX_PATH;
  findDialog = FindTextW(&fr);
  cout << GetLastError() << endl;
  cout << hex << GetLastError() << endl;
}
#包括
#包括
#包括
int main(){
使用名称空间std;
UINT uFindReplaceMsg;//FINDMSGSTRING的消息标识符
uFindReplaceMsg=registerwindwessage(FINDMSGSTRING);
wstring search_str=L“要搜索的文本”;
HWND findDialog=NULL;
wchar_t szFindWhat[MAX_PATH];
FINDREPLACEW fr;
零内存(&fr,sizeof(FINDREPLACEW));
fr.lsstructsize=sizeof(FINDREPLACEW);
fr.hwndOwner=NULL;
fr.lpstrFindWhat=szFindWhat;
fr.wfindhattlen=最大路径;
findDialog=FindTextW(&fr);

cout您没有检查来自
FindTextW
的返回结果。也就是说,您有:

findDialog = FindTextW(&fr);
cout << GetLastError() << endl;
findDialog=FindTextW(&fr);

根据上的示例,您的应用程序必须处理FINDMSGSTRING消息。您可以通过调用
RegisterWindowMessage
进行设置。请参见示例。使用管理的无模式公共对话框有一系列要求,其中许多要求您没有达到。我建议您查看该API的详细信息。更新了code,仍然不起作用。我试图实现的是,尽管显示了窗口。没有任何与此错误和功能相关的信息。我通过谷歌得到的只是我自己的问题。再多读一读那篇文章。你的windows程序必须实际处理注册的消息并对其进行处理。我已经检查过了,通信DlgExtendedError是0xFFFF,即CDERR_DIALOGFAILURE,hmmm...*例如,如果公共对话框调用指定了无效的窗口句柄,则会发生此错误。*-在此对话框中,必须使用有效的hwndOwner,即使GetConsoleWindow()也可以工作。现在对话框显示,我可以继续。(这个错误消息很神秘,应该清楚地说是父窗口句柄。这些怪癖让我非常讨厌winapi文档。)