Re: Modal Dialog Record and Replay
On Nov 18, 2:42 am, Joseph M. Newcomer <newco...@flounder.com> wrote:
Since you are not showing the dialog, what value is there in "replaying" =
the input? Why
not just store the dialog state and restore it? That would be VASTLY e=
asier. And since
you are not showing the dialog, what value is there in creating an invisi=
ble dialog that
serves no purpose? All you care about is the data state.
On Mon, 17 Nov 2008 00:14:24 -0800 (PST), Kuenga <sagku...@gmail.com> wro=
On Nov 16, 6:17 am, "Leo Violette" <l...@primenet.com> wrote:
Don't initialize your data in OnInitialize.
Maybe think of your dialog class, not as a dialog class that loads and=
data, but perhaps as a data storage class that "happens" to show a dia=
Add a LoadData and SaveData method to your class that loads and saves =
data to/from member variables that aren't CWnd based (not control
These methods would be public and would be called instead of DoModal i=
instince that you are in replay mode (whatever that means).
By doing this, you are adding a layer of abstraction between your GUI =
your datastorage/validation and other business logic.
Doing it this way is not the best design, but it is a step closer and =
be fairly easy to implement from where you are now with the code.
LoadData would load the data from wherever you store it into member
variables (not control variables).
SaveData would store the data from the member variables into your data=
OnInitDialog would check to see if LoadData was already called, if not=
would call it. Then, it would transfer the data loaded in member va=
the control variables.
OnOK would transfer data from your control variables to the member
variables, then call SaveData.
Doing this makes it possible for your class to be access and its busin=
logic to be used regardless of whether or not you show it (call DoModa=
"Kuenga" <sagku...@gmail.com> wrote in message
How do we do record and replay of modal dialog in a large code base =
I have created a new dialog class, say CFooDialog derived from CDial=
and overridden OnInitDialog and OnOk. In OnOk, the control values ar=
dumped into a file and in OnInitDialog the values are read from the
file and controls populated.
In replay mode I donot want the dialog box to be shown. For that I
have overridden DoModal and done the following
CSagDumpDialogApp *pApp = (CSagDumpDialogApp *)AfxGetApp();
But In replay mode, the control are not getting initialised, since i=
is done by DoModal function.
So I want the dialog controls to be initialised but the dialog box
should not be shown to user ? How to do that ?
Thanks- Hide quoted text -
- Show quoted text -
Thanks for your time. My goal is to record the user actions and then
replay the action carried out by him/her. If user has launched some
dialog thru menu command, during replay( for this created a CDialogBar
with EditControl where user can type in the command) I donot want the
dialog box to be shown but carry out the action which dialog box used
to do. I understand the correct way is to separate the data from the
dialog controls and during replay I just set the data members. But I
am working on large code base with many CDialog and CPropertySheet and
it is time consuming to refactory whole code to separate the data from
the dialog control.
So I decided to create a new CDialog class and derive all dialog
classes from this, so that the dumping of data present in the dialog
box is done automatically.
When logged action is replayed through command line(thru text command
entered in EditControl in CDialogBar), the dialog box should not be
shown. so came up with the above strategy.
I hope I have made the problem statement clear.
I have overcome the DoModal problem thru following code:
COrMDIApp *pApp = (COrMDIApp *)AfxGetApp();
LPCDLGTEMPLATE lpDialogTemplate = m_lpDialogTe=
HINSTANCE hInst = AfxGetResourceHandle();
HGLOBAL hDialogTemplate = m_hDialogTemplate;
if (m_lpszTemplateName != NULL)
hInst = AfxFindResourceHandle(=
HRSRC hResource = ::FindResour=
hDialogTemplate = LoadResource=
if (hDialogTemplate != NULL)
lpDialogTemplate = (LPCDLGTEMP=
// return -1 in case of failure to load the dial=
og template resource
if (lpDialogTemplate == NULL)
// destroy modal window
// unlock/free resources as necessary
if (m_lpszTemplateName != NULL || m_hDialogTem=
plate != NULL)
if (m_lpszTemplateName != NULL)
Donot know it is good or bad. Will really appreciate if someone comes
up with a better way...
Joseph M. Newcomer [MVP]
MVP Tips:http://www.flounder.com/mvp_tips.htm- Hide quoted text -
- Show quoted text -
I also donot want to Create DialogBox. But I didnot find a way in
which I can get the data state of a Dialog box without calling the
DoModal function of it.
Consider we have
class CFooDialog : public CDialog
class CDialogA : public CFooDialog
class CDialogB: public CFooDialog
The data state for CDialogA is different from CDialogB. Do we have any
method in CDialog which tells us which datas are used ?. If that the
case i can have a single function in CFooDialog which dumps the state
and reads the state and the user of CDialogA and CDialogB is not
concerned about writing the state and reading it since the base class
has handled it. It provides less maintainance.
But MFC CDialog do not provide a way in which we can know which member
variables are declared in a CDialog derived class.
So I created a base class in which overridden the OnOK(), in which the
value of all the controls in the dialog box is dumped to file and then
in DoModal function checks if the command is entered thru EditControl,
then create a dialogbox without showing it so that control variables
are being populated with values. We can easily get all the controls in
a dialog box thru iterating over CWnd present on it.
If there is a better way which CDialog provides but I am not aware, do
let me know. It will be great help.