Thanks for getting back, I was beginning to think this thread had crawled
off and died. I''ll have to copy and paste from below for clarity, not to
deliberately take your comments out of context.
Post by Joseph M. NewcomerWell, if I really needed to do a static library, I'd consider duing a DialogBoxIndirect
call.
Which is what I recommeded to the OP in my first post on the thread. It
makes a reusable solution, but hardly a two minute job. I wonder how many
other MFC programmers have followed parallel lines to augment the MFC in a
similar way. Now, I'm not advocating that MS should have released a new
version of MFC every 6 months. Just pointing out (to the OP) that this
functionality is missing. I then rail against any solution that involves
either distributing an extra dll or having to include resources in calling
exes.
Post by Joseph M. NewcomerSo I'd more likely put it in a DLL, and if someone really,
really needed to do static linking, they can add the necessary resources by hand as well.
I know it's a pain, which is why I'd use a DLL
And presumably hope that they use early binding so that if they try to
distribute without the dll then they get a message on app load. Or that if
they use late binding that they check the return value from LoadLibrary.
Both of which can be expected from disciplined progammers. But who can
guarantee that their code will be used in such a way? Or that your dll will
be included in the install. Or that a bug fixed version will be sent out
with a patch. Or that everything will be updated and work when the interface
to the dll *has* to change. In the ideal world, of course, none of these
things happen. But I know that you've been in software long enough to
appreciate that mismatching dlls represent a recurring problem.
Post by Joseph M. NewcomerYes, but you are arguing that because it is trivial in VB it has to be trivial in MFC.
...the point seemed to be that MFC owes VB programmers a
degree of simplicity that MFC never pretended to provide. I don't follow the logic of
this at all.
I only chose VB because it's a common language that most people have heard
of. And the reason that it's popular is because it's productive. Delphi
would be another good example.
My argument, or complaint, if you like is this:
The reason we use MFC at all is because we don't want to write our own
framework to call the WinAPI. Because we want to save time. When MS promote
MFC they use precisely this rationale. Even at the inception of MFC, the
InputBox functionality was available in other languages. But it wasn't
included, probably because someone thought that the IDE was so good that
programmers would be pleased to add the InputBox functionality to every
project, and tailor it accordingly. But the reality is that my apps are
complicated enough, I just want a one line solution to grab a bit of input
and get on with the job in hand. No worries about resource includes, or dll
distribution. I don't care if the exe size jumps up a tad. In the long run,
I want to save time.
I responded to the original poster because I'd done excactly the same,
namely look for a function that surely must be there. Find it isn't then
devise my own solution. From a pragmatic point of view you just have to
accept that MFC provides the functionality that it does, and then it's up to
the MFC consumer. "F" is for "Foundation", after all. But I can't see why
you would try to argue that the decision not to include the InputBox type
functionality was not a bad decision. That somehow the MFC is better off
without it.
Post by Joseph M. NewcomerSee below..
Post by KMAsee below...
Post by Joseph M. NewcomerCopy and paste is a nice methodology.
So why write a class for anything? If you need to change it you can just
amend all the pasted versions. I can hardly believe you wrote that.
Post by Joseph M. NewcomerYou can't put it in a DLL and have it statically bound; the concepts are incompatible.
Exactly. The problem is that you can't include resources in the static
library, which you well know, even if you seem reluctant to admit it.
****
I've never been reluctant to admit that resources can't be put into static libraries; in
fact, I think this is one of the significant holes in the whole Microsoft methodology.
There should be a way to link in precompiled .res files, and the resource symbols should
even be relocatable. But that's not something we expect to see done right in our
lifetimes.
****
Post by KMAPost by Joseph M. NewcomerYes, it takes longer than InputBox to write, but as already established, that is a
pointless comparison because InputBox doesn't exist, so why worry about it?
It's not pointless. *If* the MFC designers had included it, it would be
used. I suspect quite often, as AfxMessageBox is used by most MFC programers
now, as as "InputBox" type methods are routinely used by other programmers
using different tools.
****
Sure it would be used. Sure, it might be nice to have it. But it doesn't have it, but
you are talking under two minutes to re-create it. This is not a major issue.
*****
Post by KMAPost by Joseph M. NewcomerThe point is that the VB group is dealing with a different audience than the MFC group.
Frankly, the number of times I've needed InputBox funcitonality is so
small that I don't
mind taking the three minutes to do it...
Then maybe we don't work on the same kinds of programs. But imagine you were
supplying a static lib to a customer, and you must have some place for
parameter input. What do you do then? Tell them to make sure that every
calling exe has a chunk of rc data that your dialog class expects to be
bound in the exe? Force them to use a(nother) DLL?
*****
Well, if I really needed to do a static library, I'd consider duing a DialogBoxIndirect
call. But I'd be disinclined to put something like this in a static library because of
the deficiencies of the VS environment. After all, the only reason all the other controls
work is because they are already in DLLs, so there is a recognition that you can't put
CFileDialog, CFontDialog, CColorDialog, CPrintDialog, etc. in a statically-linked
environment; only a DLL works. So I'd more likely put it in a DLL, and if someone really,
really needed to do static linking, they can add the necessary resources by hand as well.
I know it's a pain, which is why I'd use a DLL. I haven't delivered a serious product
that didn't use DLLs in so long that it doesn't seem to be a problem. My clients use DLLs
because they want to avoid opening their code but want to use a GPL subroutine, or because
they have code so proprietary that even under NDA I'm not allowed to see it so they give
me a DLL to interface to. Or they are using a third-party DLL to get some sophisticated
control system. I am not sure why there is such a reluctance to use DLLs; they are a fact
of life.
****
Post by KMAPost by Joseph M. NewcomerNever mind. I just sat here with a stopwatch and did it.. I
apologize;
my three minute
estimate was wrong. It took me one minute and forty seconds to create
the
dialog, the
variables, and the class.
Since you're being petulant, one minute forty is still many times longer
than (hang on, I'll type it now).... 12 seconds, and I'm a two finger
typist.
****
Yes, but you are arguing that because it is trivial in VB it has to be trivial in MFC.
There are *lots* of things that are trivial in VB that are not trivial in MFC, such as
interfacing to ActiveX controls, using embedded documents, etc. VB has lots of support
that makes a lot of things easy. But we don't expect any of these in MFC, so focussing on
a trivial feature instead of a major feature seems odd.
****
Post by KMAThe solution you proposed would be longer in the short run, and much longer
in the long-run.
You appear to have misunderstood the OPs' question and have subsequently
tried to subvert the thread to justify your misunderstanding. Even to the
point of advocating copy and pasting common code. Not what I expected at
all.
*****
Copy and paste is still a good methodology. However, creating a DLL once takes only a few
more minutes.
I was not subverting the thread; the point seemed to be that MFC owes VB programmers a
degree of simplicity that MFC never pretended to provide. I don't follow the logic of
this at all. Particularly when the solution is trivial.
****
Post by KMAPost by Joseph M. Newcomerjoe
Post by KMAOK, and now I want to use the same dialog in another project. Go through
same procedure again, making sure I drop the controls in exactly the same
place for consistancy?. Copy and paste from the resource file?
Or put it in a library? A separate dll for one dialog box? And if I want the
class statically bound?
And you really think the above take less than three minutes? I doubt it, but
CString s = InputBox("Please enter your name");
Of course, you can write the function yourself. It's just a pity the MFC
group didn't take a peek at what the VB group were doing and incorporate
this very useful idea.
Post by Joseph M. NewcomerYou have not said much about what you expect here. It sounds like you are
willing to have
a dialog pop up and get the input. It should take you under three minutes
to create this.
(1) Create a dialog
(2) Place an edit control on the dialog
(3) Resize the dialog to minimum size (this may involve rearranging
the
buttons)
(4) Create a dialog class for it, for example, CMyInputDialog
(5) In the dialog class, create a value member variable, a CString,
coupled to the edit
control. For example, call it m_Input.
CMyInputDialog dlg;
if(dlg.DoModal() == IDOK)
... use dlg.m_Input;
Done.
joe
Post by s***@gmail.comHi I need to input certain text value from a user. This is a MFC
application and I am not able to find a control which can do this. Do
I _have_ to write a custom Dialog box or is there something like
MessageBox which can also take user input ?
Regards
Sandeep
Joseph M. Newcomer [MVP]
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
Joseph M. Newcomer [MVP]
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
Joseph M. Newcomer [MVP]
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm