Problem concerning with Find common dialog box(关于查找通用对话框的问题) RRS feed

  • 问题

  • I come across a situation that two applications need to communicate with each other.  After reflecting I think the proper way may be via windows message. I search MSDN and think RegisterWindowMessage may give the favor. The document also contains a sample demonstrating using of Find common dialog box. I try to do just as the document's description, namely I created a project of Windows Application type, and copied the sample code into proper positions in my view in the source file generated by VS wizard.  However,  there's some exception in the message pump code part in the WinMain function,  I didn't do any altration in the WinMain function and what I only modified is the message processing function WndProc. I paste the code as follows. Can any one give some help? No more thanks.

    我遇到两个应用程序需要相互通信的一个场合,思考之后我认为通过Windows消息可能更为合适。在MSDN上查找之后,我发现RegisterWindowMessage 这个函数比较有帮助。文档同时给出了查找对话框利用此的例子。我尝试按照文档所述,建立了一个Windows应用程序类型的工程,将示例代码插入到由向导自动生成的源文件中我认为合适的位置。但是在主函数WinMain的消息循环代码片段有了异常。我没有对主函数作过更改,只是更改了消息处理函数。我在下面贴出了代码,希望有人能给予帮助。不胜感激!

    #define MAX_STRING 256

    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
     int wmId, wmEvent;
     HDC hdc;
     HWND hWndFind;

     static UINT uFindReplaceMsg;
      uFindReplaceMsg = RegisterWindowMessage(FINDMSGSTRING);

     ZeroMemory(&fr, sizeof(fr));
     TCHAR szFind[MAX_STRING] = { 0 };
     TCHAR szRep[MAX_STRING] = { 0 };

     if(message == uFindReplaceMsg)
      TCHAR szMsg[MAX_STRING] = { 0 };
      _stprintf(szMsg, L"您要查找的内容是%s\n", szFind);
      MessageBox(hWnd, szMsg, L"查找", MB_OK);
      return DefWindowProc(hWnd, message, wParam, lParam);
     switch (message)
     case WM_COMMAND:
      wmId    = LOWORD(wParam);
      wmEvent = HIWORD(wParam);
      // Parse the menu selections:
      switch (wmId)
      case IDM_ABOUT:
       DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
      case IDM_EXIT:
      case ID_FILE_FIND:
       fr.lStructSize = sizeof(fr);
       fr.hwndOwner = hWnd;
       fr.hInstance = hInst;
       fr.lpstrFindWhat = szFind;
       fr.lpstrReplaceWith = szRep;
       fr.wFindWhatLen = MAX_STRING;
       fr.wReplaceWithLen = MAX_STRING;

       hWndFind = FindText(&fr);
       return DefWindowProc(hWnd, message, wParam, lParam);
     case WM_PAINT:
      hdc = BeginPaint(hWnd, &ps);
      // TODO: Add any drawing code here...
      EndPaint(hWnd, &ps);
     case WM_DESTROY:
      return DefWindowProc(hWnd, message, wParam, lParam);
     return 0;

    This is the platform: Windows 7 Home Basic, MS VS 2008

    系统平台是Windows 7 Home Basic, MS VS 2008

    2010年6月29日 2:09



    • 已标记为答案 mingcraeer 2010年6月30日 13:28
    • 已编辑 ID已删 2010年8月16日 6:14
    2010年6月30日 3:44
  • Dear 江写生:

    Yes, sir, you are right. After change the storage type of the local variables from auto(here 'auto' not exactly meaning in the VS 2010 context) to static,  the problems solved. Although seems a little work to do to get the input edit box in the Find dialog box getting focus(actually it gets focus when clicked, though there's no cursor flickering),  thanks a lot for your observation.

    2010年6月30日 13:28