473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

simple modal dialog

I need to put up a simple modal dialog, and am surprised how hard it seems
to be. Am I missing something here?

I have created a dialog resource IDD_DELETE_S9. It has some static text
plus 3 buttons. The buttons have ids of IDOK, IDCANCEL and IDC_RENAME. All
I want to do is put up this modal dialog asking the user what to do. All I
care is which button he pressed.

I tried using

int answer = DialogBox(0, MAKEINTRESOURCE(IDD_DELETE_S9),
hwnd, (DLGPROC)Import_DialogProc);

but the dialog never shows and it just drops through, giving me a non-useful
'answer'.

Everything I am now reading in MSDN seems to indicate that I need to write a
new class inheriting from CDialog to handle this and return the button
pressed. Is that really needed?

This sure seems like something that should be accomplished in a one-line
call...?
Nov 17 '05 #1
6 1107
Burt wrote:
I need to put up a simple modal dialog, and am surprised how hard it seems
to be. Am I missing something here?

I have created a dialog resource IDD_DELETE_S9. It has some static text
plus 3 buttons. The buttons have ids of IDOK, IDCANCEL and IDC_RENAME. All
I want to do is put up this modal dialog asking the user what to do. All I
care is which button he pressed.

I tried using

int answer = DialogBox(0, MAKEINTRESOURCE(IDD_DELETE_S9),
hwnd, (DLGPROC)Import_DialogProc);

but the dialog never shows and it just drops through, giving me a non-useful
'answer'.

Everything I am now reading in MSDN seems to indicate that I need to write a
new class inheriting from CDialog to handle this and return the button
pressed. Is that really needed?

This sure seems like something that should be accomplished in a one-line
call...?


It's only hard if you have no idea what you are doing. If you are using
MFC then the DialogBox API call is not applicable.

In Visual C++ the IDE 'class wizard' writes the new class derived from
CDialog for you. Right click on your dialog template and select Class
Wizard. Name your CDialog class.

CYourDialog dlg;
dlg.DoModal();

DoModal returns IDOK or IDCANCEL. Detecting your unique button requires
you to do something, like set a bool when it is clicked.

--
Scott McPhillips [VC++ MVP]

Nov 17 '05 #2
"Burt" <bu**@mindstorm-inc.com> wrote in message
news:2Q*******************@fe04.news.easynews.com. ..
I need to put up a simple modal dialog, and am surprised how hard it seems
to be. Am I missing something here?

I have created a dialog resource IDD_DELETE_S9. It has some static text
plus 3 buttons. The buttons have ids of IDOK, IDCANCEL and IDC_RENAME. All I want to do is put up this modal dialog asking the user what to do. All I care is which button he pressed.

I tried using

int answer = DialogBox(0, MAKEINTRESOURCE(IDD_DELETE_S9),
hwnd, (DLGPROC)Import_DialogProc);
What happens if you replace your (HINSTANCE)0 argument with
GetModuleHandle(NULL)...?

but the dialog never shows and it just drops through, giving me a non-useful 'answer'.
What does it return?

Everything I am now reading in MSDN seems to indicate that I need to write a new class inheriting from CDialog to handle this and return the button
pressed. Is that really needed?
Not really.

This sure seems like something that should be accomplished in a one-line
call...?


Yup. Followed by evaluation of the return of course.

--
Jeff Partch [VC++ MVP]
Nov 17 '05 #3
>> I tried using

int answer = DialogBox(0, MAKEINTRESOURCE(IDD_DELETE_S9),
hwnd, (DLGPROC)Import_DialogProc);
What happens if you replace your (HINSTANCE)0 argument with
GetModuleHandle(NULL)...?


Same thing. No change in behavior

but the dialog never shows and it just drops through, giving me a

non-useful
'answer'.


What does it return?


-1
This sure seems like something that should be accomplished in a one-line
call...?


Yup. Followed by evaluation of the return of course.


Yes, I have code folloing that that looks like:

if (answer == IDCANCEL)
return FALSE; // user decided to stop

etc. So you are saying that my DialogBox call should be enough? It never
enters my CALLBACK and never shows the dialog. Any idea why that would be?
Nov 17 '05 #4
Scott McPhillips [MVP] <org-dot-mvps-at-scottmcp> wrote:
It's only hard if you have no idea what you are doing. If you are using
MFC then the DialogBox API call is not applicable.
I never said I knew what I was doing. I have only been using MFC for a
couple months, after 32 years programming other environments. No need
to be insulting though...

Why is DialogBox not applicable for MFC? Is that another of the
'managed memory model' (or whatever it is called) routines? If so, how
the heck can I tell the difference when reading MSDN. I have led down
that path a couple times now, and it is frustrating, to say the least.

In Visual C++ the IDE 'class wizard' writes the new class derived from
CDialog for you. Right click on your dialog template and select Class
Wizard. Name your CDialog class.

CYourDialog dlg;
dlg.DoModal();

DoModal returns IDOK or IDCANCEL. Detecting your unique button requires
you to do something, like set a bool when it is clicked.


Yeah, I know how to go through that hoop. Just seems silly to have to
add a whole new class just to get something simple like this. In other
environments I have programmed in, it was a simple one-line call with
the addition of a resource to define the appearance (which I have
created).
--
- Burt Johnson
MindStorm, Inc.
http://www.mindstorm-inc.com/software.html
Nov 17 '05 #5
"Burt Johnson" <bu**@mindstorm-inc.com> wrote in message
news:1gyu2tx.1kec1cfihl85aN%bu**@mindstorm-inc.com...
Scott McPhillips [MVP] <org-dot-mvps-at-scottmcp> wrote:
It's only hard if you have no idea what you are doing. If you are using
MFC then the DialogBox API call is not applicable.
I never said I knew what I was doing. I have only been using MFC for a
couple months, after 32 years programming other environments. No need
to be insulting though...

Why is DialogBox not applicable for MFC?


DialogBox() is a function in the Win32 API. MFC provides a CDialog class to
simplify things and hide some of the details.
Is that another of the 'managed memory model' (or whatever
it is called) routines? If so, how the heck can I tell the
difference when reading MSDN.
No, it is not. MFC is a class library used by and large to build native
applications.
I have led down that path a couple times now, and it is frustrating,
to say the least.
Well, it is at worst an embarassment of choices. There is the native API,
MFC, ATL, WTL, .Net Framework, etc
Yeah, I know how to go through that hoop. Just seems silly to have to
add a whole new class just to get something simple like this.
I guess that depends on one's perspective and expectations.
In other environments I have programmed in, it was a simple one-line call
with
the addition of a resource to define the appearance (which I have
created).


Well, there is the MessageBox() function which can put up a dialog in one
line but you'll have to settle for predefined sets of buttons such as ok, or
yes and no or yes and no and cancel etc

Back to your problem ... One thing you can do is to pass the ID of the
button used to close the dialog to the EndDialog() call that dismisses the
dialog. EndDialog() sees to it that that value is returned by the call to
DialogBox(). Since control IDs are small positive numbers, if you get 0 or a
negative result then the call failed. In that case call GetlastError() to
determine the reason why the call failed. If you don't understand the code -
they are defined in <winerror.h> - you can post it here.

Regards,
Will

Nov 17 '05 #6
"Burt" <bu**@mindstorm-inc.com> wrote in message
news:Y4*******************@fe01.news.easynews.com. ..
but the dialog never shows and it just drops through, giving me a non-useful
'answer'.


What does it return?


-1


Do then follow the advice to see what GetLastError has to say. What OS are
you testing on?
This sure seems like something that should be accomplished in a one-line call...?


Yup. Followed by evaluation of the return of course.


Yes, I have code folloing that that looks like:

if (answer == IDCANCEL)
return FALSE; // user decided to stop

etc. So you are saying that my DialogBox call should be enough? It never
enters my CALLBACK and never shows the dialog. Any idea why that would

be?

I agree that it's not the MFC way to so it -- and concur with the
admonitions for the most part, but in a quick test it works for me -- even
using the (HINSTANCE)0.

--
Jeff Partch [VC++ MVP]

Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Patrick Lim | last post by:
Here is the problem: I have written a non-modal frame class in Java for displaying help text when a user is using an application. It works as desired in that if the user selects "help" again,...
2
by: martin de vroom | last post by:
Hi, I have a web page that opens a modal dialog (client side) in the following manner onclick="window.showModalDialog('/dialog.asp',null,'dialogHeight: 200px; dialogWidth: 400px; dialogTop:...
2
by: Gilles T. | last post by:
Hi, How I can refresh a modal dialog in asp.net? I open a modal dialog in first with a dropdownlist. To add a element in my dropdownlist (table), I open a second modal dialog to ask element and...
2
by: cassidyc | last post by:
Hi, I was wondering if anyone has come accross this issue? And if they have any solutions I have that can create new copies of itself Form1 as = new form1(); af.show(); This form can also...
6
by: Burt | last post by:
I need to put up a simple modal dialog, and am surprised how hard it seems to be. Am I missing something here? I have created a dialog resource IDD_DELETE_S9. It has some static text plus 3...
10
by: Guadala Harry | last post by:
I have a modal dialog that currently does all of the following except item 4. 1. lets users select a graphic from a list of thumbnails (and when selected, displays the full-size image in a...
2
by: sthrudel | last post by:
Hi! I'm working on a web application in Asp.net and what I would like to have is a cross borwser modal dialog which accepts user's input. I would like to catch what the user clicked on the...
11
by: VK | last post by:
In the continuation of the discussion at "Making Site Opaque -- This Strategy Feasible?" and my comment at http://groups.google.com/group/comp.lang.javascript/msg/b515a4408680e8e2 I have...
2
by: diogenes | last post by:
I have created many shortcut/popup (aka context, or right-click) menus for my application - instead of toolbars or standard drop-down menus. Within my custom menu, I am using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.