Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Losing access to my dialog box in MFC

Posted on 1998-01-26
6
Medium Priority
?
308 Views
Last Modified: 2013-12-03
I have recently been implementing an app to download some files from the internet and stumbled across the following problem:-

I bring up a dialog box using DoModal(), and in that dialog box I have a button called start. I have a handler called OnStartButtonPressed() which is called when ever I press the start button. The code within this button handler downloads a bunch of files from the internet, however I seem to not be able to interact with it once it starts downloading the files. I can no longer do any of the following:-

a) Adjust the dialogs position or size etc...
b) interact with any of the buttons or text boxes within the dialog box
c) Cancel and OK do not even respond.
d) I cant even close the dialog box.

The only way I can stop it before it has finished downloading the files is to use CTRL+ALT+DEL and shuit it down even then it hangs around in the system for a bit.

I have a CProgressCtrl in the dialog which is the only that that works.

I can get to other applications and use them fine, it seems like I have locked my dialog window up whilst the handler downloads the internet files.

How do I get around this, is it possible without using threads?

Thanx

matth
0
Comment
Question by:matth012098
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1410389
Instead of using a modal dialog, you can create a modeless dialog box. The problem is your function that downloads files is not processing any messages. You can use

  GetApp()->PumpMessages();

to process messages in your loop.

0
 
LVL 3

Author Comment

by:matth012098
ID: 1410390
PumpMessage() is a CSocket method, unfortunately I cannot use this since I am using WinINet CInternetSession (sorry, I should have mentioned this). I created a modeless dialog box as follows:-

I created a dialog box and class from it using ClassWizard
I have overriden the Create function as follows:-

CWebGet::Create(UINT nID, CWnd *pWnd)
{
  return CDialog::Create(nID, pWnd);
}
I also overriden OnOK(), OnCancel() and CWnd::PostNcDestroy() in the dialog class as follows:-

void CWebGet::OnCancel()
{
    DestroyWindow();
}
void CWebGet::OnOK()
{
    if (!UpdateData(TRUE))
    {
       return;
    }
    DestroyWindow();
}
virtual void CWebGet::PostNcDestroy() {delete this;}

I then create the dialog box like this:-

CWebGet *dlg = new CWebGet;
dlg.Create(IDD_DIALOG_WEB, this);

The dialog box is displayed and I can interact with it, but as soon as I click the START button and the handler starts downloading internet files, I am locked out of the dialog box again, I have still the same probs.

matth

0
 
LVL 3

Author Comment

by:matth012098
ID: 1410391
Also, the dialog box is not getting redrawn whilst downloading. If I switch to a dos prompt and alt-TAB back to my application the window is white with borders. I guess this is something to do with the dialog box not processing the redraw message. I understand that creating a modeless dialog is ran as a seperate thread to the window that created it, and when I press START on the dialog, it gets trapped in my loop downloading files from the net, so the dialog window will not process messages. Is there a specific command to force the dialog to handle any messages within the internet download loop?


0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 3

Author Comment

by:matth012098
ID: 1410392
I have found half the solution to this question and that is to use the win32 functions GetMessage(), TranslateMessage() and DispatchMessage(). I wrote the following function to take care of it

BOOL ProcessMessages(HWND hWnd, int loop)
{
  MSG msg;
  int t;
  BOOL ret = TRUE;

  for (t=0; t<loop; t++)
  {
    ret=GetMessage(&msg, hWnd, 0, 0);
    TranslateMessage(&msg);
    DispatchMessage(&mdg);
    if (!ret)
      break;
  }
  return ret;
}

This will process a number of messages for the required window which is in my case the dialog box defined by CWebGet.

This works but it maybe 2 seconds or so before the message is acknowledged, if anyone knows of a better way especially in MFC of doing this that I can easily implement I will award them the points

matth

0
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 210 total points
ID: 1410393
Sorry, added an extra s at the end of PumpMessage() which is a virtual function of CWinThread. CWinApp is derived from CWinThread.
0
 
LVL 3

Author Comment

by:matth012098
ID: 1410394
Thanks

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question