943,719 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 2227
  • C++ RSS
Sep 6th, 2009
1

Modal dialogs HELP!!!

Expand Post »
Hi everyone,

I have a modal dialog box which is called by the main thread. This dialog has no parent (appears at center screen, overlapped, and shown in taskbar). When the user clicks "Save" in the dialog, the dialog procedure receives the command and displays a save file dialog (GetSaveFileName).
The problem is that the second dialog (Save Dialog) doesn't work at all. It can't be activated, and seems kind of frozen (can't be closed, buttons and scroll bars are frozen). Here's my code:

c++ Syntax (Toggle Plain Text)
  1. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
  2. DialogBox(hInstance, MAKEINTRESOURCE(101), NULL, DialogProc);
  3. MSG msg;
  4. while (GetMessage(&msg, NULL, 0, 0) != 0)
  5. {
  6. TranslateMessage(&msg);
  7. DispatchMessage(&msg);
  8. }
  9. return (int)msg.wParam;
  10. }
  11.  
  12. INT_PTR CALLBACK DialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
  13. HDC hdc; PAINTSTRUCT ps;
  14. switch (message) {
  15. case WM_COMMAND:
  16. switch(LOWORD(wParam)) {
  17. case IDSAVE:
  18. OPENFILENAME OFN;
  19. OFN.hwndOwner = hWnd;
  20. [...]
  21. //PROBLEM IS HERE. The save file dialog is half-frozen and never returns.
  22. if (GetSaveFileName(&OFN)) {[...]}
  23. break;
  24. default:
  25. return DefWindowProc(hWnd, message, wParam, lParam);
  26. }
  27. return true;
  28. case WM_PAINT:
  29. hdc = BeginPaint(hWnd, &ps);
  30. EndPaint(hWnd, &ps);
  31. break;
  32. case WM_INITDIALOG:
  33. [...]
  34. return true;
  35. case WM_CLOSE:
  36. [...]
  37. return true;
  38. case WM_DESTROY:
  39. [...]
  40. return true;
  41. default:
  42. return DefWindowProc(hWnd, message, wParam, lParam);
  43. }
  44. return false;
  45. }
Whatever dialog type I put at this line (print dialog, modal dialog, modeless dialog), it doesn't behave properly. What am I missing?
I tried with OFN.hwndOwner = NULL, but doesn't work.

Thanks in advance!
Reputation Points: 23
Solved Threads: 0
Newbie Poster
sixstorm1 is offline Offline
5 posts
since Sep 2009
Sep 7th, 2009
0

Re: Modal dialogs HELP!!!

Is there too much code to post the whole thing, so i can try and compile exactly what you've got? I'm sure I could solve it if i could compile it.
Last edited by William Hemsworth; Sep 7th, 2009 at 2:27 pm.
Reputation Points: 1429
Solved Threads: 129
Posting Virtuoso
William Hemsworth is offline Offline
1,542 posts
since Mar 2008
Sep 7th, 2009
0

Re: Modal dialogs HELP!!!

Problem solved!!! The problem was within the procedure. Replaced "return DefWindowProc(hWnd, message, wParam, lParam)" by "return false" and now everything works. return DefWindowProc is for windows created with CreateWindow, not dialogs.
Reputation Points: 23
Solved Threads: 0
Newbie Poster
sixstorm1 is offline Offline
5 posts
since Sep 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: infinte loop
Next Thread in C++ Forum Timeline: my first "real" program :twisted:





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC