Skip to main content
GameDev.net gamedev.net
🔒 Locked

Initializing a CProgressCtrl Object Inside CDialog :: MFC

Started by kuphryn Apr 15, 2002 at 8:41 PM 3 replies 3.6k views
Original Post
kuphryn
kuphryn
Hi. I have a CDialog (modal) object. It serves as a progress dialog similar to the one that you see while waiting for EI to finish downloading. Inside the actual dialogbox is a CProgressCtrl object. Right now, the progress bar does not do anything. I tried initializing it like this: m_MyProgressBar.SetRange(0, 100); m_MyProgressBar.SetPos(0); The program crashed when I add the code above. I did *not* create the object. The reason is I did not know the size of the object. For example, this code comes from Prosise''s book: m_MyProgressBar.Create(WS_CHILD | WS_VISIBLE, rect, this, -); I added a progressbar via Dialogbox Editor. I need to create the progressbar, but I do not know the actual rectangle of the progressbar I made using Dialogbox Editor. How you to initialize a progressbar made using Dialog Editor? Thanks, Kuphryn
Ehamliptoran
Ehamliptoran
goto View->Classwizard...

under classwizard click on the tab labeled

Select ur progress bar, defaultly named IDC_PROGRESS#

# - being a number

click the add variable button to the right of the form, and choose an appropriate name, m_MyProgressBar - is a good one

and click okay, and there u have it, u just initialized a progress bar, voila it should hopefully work

The worst way to miss someone is to be sitting next to them, knowing you cant have them
The worst way to miss someone is to be sitting next to them, knowing you cant have them
Stoffel
Stoffel
Also, you can''t manipulate that object until _after_ CDialog::OnInitDialog () has been called--it doesn''t exist until then.
kuphryn
kuphryn
Thanks.

Here is something I learned and have implemented. Prosise described a good way to enable/disable a control (i.e. button) inside a dialog box. Here is the technique.

CWnd *pWnd = GetDlgItem(IDOK); // item you want to control
pWnd->EnableWindow(FALSE); // this will disable the control
pWnd->EnableWindow(TRUE); // this will enable the control

As for updating the progress bar inside a dialog box, I thought about sending CMainFrm a message which then gets redirected to CChildView. CChildView will then pass a new position to a function in CDialog. I would have to declare the CDialogBox as private in CChildView instead of local in a function. What do you think?

Kuphryn


[edited by - kuphryn on April 16, 2002 10:56:04 AM]
kuphryn
kuphryn
Conventionally speaking, should the dialogbox (progressbar) comes first or the access data processing. In other words, when creating a progressbar inside a dialog box, should I begin data manipulation, which is what the dialog box will ultimately depend on to update the progressbar, *before* creating the dialog box or *after*? Either way, it looks like I will need to seen a message to the MainFrm or view after InitDialog() in the dialog box.

Kuphryn

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.