Showing loading animation or dialog box?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Showing loading animation or dialog box?

  1. #1
    Join Date
    Jul 2009
    Posts
    10

    Showing loading animation or dialog box?

    I need to preface by saying that I'm new to Visual C++, so forgive me if I'm asking a question with an obvious answer

    I'm trying to get either a loading animation or a dialog box that says "Calling..." to appear when the user clicks a certain button. I've tried it with a dialog box but it doesn't let the rest of the program continue doing what it's supposed to be doing -- it sits waiting for a user response. I need something that will indicate something is happening in the background and will, at the same time, let that background stuff occur!

    Oh, and this is for Windows Mobile.

    I'm totally lost as to where to go! Help would be appreciated Thanks!

  2. #2
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    Re: Showing loading animation or dialog box?

    This is usually done by creating a new thread and showing the dialog from that thread.
    Not sure how its done in Windows Mobile.
    _Superman_
    I love work. It gives me something to do between weekends.

    Microsoft MVP (Visual C++)

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Showing loading animation or dialog box?

    There are two types of dialogs: modal and modeless. Modal dialogs are created with DoModal, and they don't let the user access the other windows of the application, until they close it. Modeless dialogs are created with Create(), and allow the user to use the other windows of the applications.

    Now, you can create a modeless dialog instead, but I'm wondering, what are you actually trying to do?
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Jul 2009
    Posts
    10

    Re: Showing loading animation or dialog box?

    The program I'm working on is a sort of chat program on mobile phones. The user selects a contact from a list and clicks "Call". In the background the phone is going through all sorts of functions to establish a connection with the other device over Wi-Fi. Sometimes this takes a while and I'd like to show a dialog box that says "Calling..." while this is happening, because otherwise it just looks like the program has frozen up.

    I'll try looking at threads and modeless dialogs for now, thanks for the hints

  5. #5
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Showing loading animation or dialog box?

    I think you should display a modal dialog, that shows the status, and also has a Cancel button. The user should not be able to do anything until the connection is established, except for Canceling? Or maybe I'm missing something.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  6. #6
    Join Date
    Jul 2009
    Posts
    10

    Re: Showing loading animation or dialog box?

    Thanks everyone! I used to a Modeless Dialog Box and it does the trick -- it shows some feedback to the user while allowing the program to continue connecting in the background.

    However, I'm having a bit of trouble figuring out how to Cancel connecting... I know how to do something like create a MessageBox when the cancel button is clicked, but there's a problem -- the program sort of freezes while it's trying to create a connection (especially if the user the phone is trying to contact is unavailable). Also, how do I stop a function from outside of it?

    I hope I'm making sense, haha. Thanks!

  7. #7
    Join Date
    Sep 2008
    Posts
    11

    Re: Showing loading animation or dialog box?

    Are you creating the dialog in different thread? If you don't, implementing cancel button might wont help.
    Try this below article
    http://www.codeguru.com/cpp/controls...cle.php/c2269/

  8. #8
    Join Date
    Jul 2009
    Posts
    10

    Re: Showing loading animation or dialog box?

    Thanks for the article, Najet! This is really helpful.

    So I've put the Dialog Box in a different thread... the cancel button doesn't freeze anymore and it will do something when I click it, but it still waits to disappear until the other thread finishes its task. Is there some way I can abort right away?

    I think I'm probably using the WaitForSingleObject thing wrong. Here's how I implemented it:
    - in the dialog box thread, clicking the cancel button will call SetEvent(cancelCall);
    - in the main thread, the calling tasks are wrapped in a while(WaitForSingleObject(cancelCall, 0) == WAIT_TIMEOUT) { //make the call }

    but this won't abort out of the calling task right away since the while condition is only tested after an iteration, right? I'm probably misunderstanding the article najet linked to.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center