CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2009
    Posts
    13

    [RESOLVED] Modal dialogs

    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:

    Code:
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
    	DialogBox(hInstance, MAKEINTRESOURCE(101), NULL, DialogProc);
    	MSG msg;
    	while (GetMessage(&msg, NULL, 0, 0) != 0)
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    	return (int)msg.wParam;
    }
    
    INT_PTR CALLBACK DialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
    HDC hdc; PAINTSTRUCT ps;
    switch (message) {
    	case WM_COMMAND:
    		switch(LOWORD(wParam)) {
    			case IDSAVE:
    				OPENFILENAME OFN;
    				OFN.hwndOwner = hWnd;
    				[...]
    				//PROBLEM IS HERE. The save file dialog is half-frozen and never returns.
    				if (GetSaveFileName(&OFN)) {[...]}
    				break;
    			default:
    				return DefWindowProc(hWnd, message, wParam, lParam);
    		}
    		return true;
    	case WM_PAINT:
    		hdc = BeginPaint(hWnd, &ps);
    		EndPaint(hWnd, &ps);
    		break;
    	case WM_INITDIALOG:
    		[...]
    		return true;
    	case WM_CLOSE:
    		[...]
    		return true;
    	case WM_DESTROY:
    		[...]
    		return true;
    	default:
    		return DefWindowProc(hWnd, message, wParam, lParam);
    	}
    	return false;
    }
    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!
    Last edited by sixstorm1; September 7th, 2009 at 01:37 AM.

  2. #2
    Join Date
    Jul 2005
    Location
    E: 120°.6, N: 31°.3′
    Posts
    795

    Re: Modal dialogs

    Firstly, please use code tag.
    2nd, Take a look at this
    Last edited by sunny_sz; September 7th, 2009 at 12:51 AM.
    Little by little one goes far
    Keep moving.......!
    Nothing is impossible !

  3. #3
    Join Date
    Jan 2009
    Posts
    13

    Re: Modal dialogs

    @sunny_sz:

    Thanks for your reply, but the link you gave is for .NET. I am programming in native Win32.

    The problem does not lie within the save file dialog, but rather within the dialog procedure and/or API calls. If I replace the save file dialog part with a print dialog or even a new modal or modeless dialog, the same problem occurs. The second dialog shows itself but is unusable.

    I want my modal dialog to open another dialog!

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Modal dialogs

    Could you post a small project (in zip archive not including .ncb, .clw, .aps, .opt files nor Debug/Release folders) reproducing this behaviour?
    Victor Nijegorodov

  5. #5
    Join Date
    Jan 2009
    Posts
    13

    Re: Modal dialogs

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured