Thread: Dialog box halting program

  1. #1
    george7378
    Guest

    Dialog box halting program

    Hi everyone,

    I have some code which downloads an image from the internet when a button IDC_DOWNLOAD is pressed in a Win32 program:

    Code:
    case IDC_DOWNLOAD:
    	DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_LOADING), hwnd, ToolDlgProc);
    	URLDownloadToFile( NULL, "http://website.com/image.jpg", "image.bmp", 0, NULL );
            ShellExecute(NULL, "open", "image.bmp", NULL, NULL, SW_SHOWNORMAL);					
    break;
    It works fine and downloads and displays the image when I get rid of the DialogBox line, but for some reason when I put the DialogBox part in, it just opens the dialog box and doesn't download the image. Is there a way to load a dialog box and also continue to download and display the image?

    Thanks.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    From MSDN:
    DialogBox does not return control until the specified callback function terminates the modal dialog box by calling the EndDialog function.
    If that's not what you want, then don't use DialogBox.

  3. #3
    george7378
    Guest
    Thanks - what are the alternatives?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Opening up any other type of window? (e.g. with CreateWindow)

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by george7378 View Post
    Thanks - what are the alternatives?
    Look up CreateDialog() ...

  6. #6
    george7378
    Guest
    Thanks for the tips. I had a look at CreateDialog(), and I put it into the code. It compiles OK, but when I press the button, the dialog box doesn't appear (the image downloads and opens OK, but the box doesn't work). Is there anything else I need to add in apart from changing 'DialogBox' for 'CreateDialog'?

    Thanks.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Not having looked at MSDN, perhaps ShowWindow?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    george7378
    Guest
    Quote Originally Posted by Elysia View Post
    Not having looked at MSDN, perhaps ShowWindow?
    Yep, that sorted it. Thanks for all your help guys!

  9. #9
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by george7378 View Post
    Thanks for the tips. I had a look at CreateDialog(), and I put it into the code. It compiles OK, but when I press the button, the dialog box doesn't appear (the image downloads and opens OK, but the box doesn't work). Is there anything else I need to add in apart from changing 'DialogBox' for 'CreateDialog'?

    Thanks.
    Sigh... read the requirements... CreateDialog Function (Windows)

    See the lpTemplate parameter in there... That is for a dialog box template stored in your program's resources.

    Read this... theForger's Win32 API Tutorial for a tutorial on the proper construction of Windows GUI mode programs.

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You might want to use a GUI library for your GUI programming. Which ones exist depend on which language you're using.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 06-24-2008, 03:14 PM
  2. Dialog Box causes program to exit
    By norbs27 in forum Windows Programming
    Replies: 10
    Last Post: 01-14-2008, 10:09 PM
  3. Halting execution
    By rickyoswaldiow in forum C++ Programming
    Replies: 1
    Last Post: 10-19-2006, 07:10 AM
  4. Exiting program from secondary dialog
    By Garfield in forum Windows Programming
    Replies: 4
    Last Post: 03-08-2004, 12:53 PM
  5. Dialog popup when program executed.
    By xlnk in forum Windows Programming
    Replies: 1
    Last Post: 03-03-2004, 06:44 PM