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...? 6 1354
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]
"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]
>> 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?
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
"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
"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] This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |