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.
=
joe
On Mon, 17 Nov 2008 00:14:24 -0800 (PST), Kuenga <sagku...@gmail.com> wro=
te:
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=
saves
data, but perhaps as a data storage class that "happens" to show a dia=
log.
Add a LoadData and SaveData method to your class that loads and saves =
the
data to/from member variables that aren't CWnd based (not control
variables).
These methods would be public and would be called instead of DoModal i=
n the
instince that you are in replay mode (whatever that means).
By doing this, you are adding a layer of abstraction between your GUI =
and
your datastorage/validation and other business logic.
Doing it this way is not the best design, but it is a step closer and =
would
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=
store.
OnInitDialog would check to see if LoadData was already called, if not=
, it
would call it. Then, it would transfer the data loaded in member va=
riables
to
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=
ess
logic to be used regardless of whether or not you show it (call DoModa=
l).
"Kuenga" <sagku...@gmail.com> wrote in message
news:b0e2715f-1c8b-46f8-9bb3-ac390804ce64@b31g2000prb.googlegroups.com.=
...
Hi,
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=
og
and overridden OnInitDialog and OnOk. In OnOk, the control values ar=
e
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
INT_PTR CFooDialog::DoModal()
{
CSagDumpDialogApp *pApp = (CSagDumpDialogApp *)AfxGetApp();
if(pApp->b_ReplayMode) {
return IDOK;
}
return CDialog::DoModal();
}
But In replay mode, the control are not getting initialised, since i=
t
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 -
Hi Joseph/Leo,
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:
INT_PTR FooDialog::DoModal()
{
COrMDIApp *pApp = (COrMDIApp *)AfxGetApp();
if(pApp->b_ReplayMode) {
LPCDLGTEMPLATE lpDialogTemplate = m_lpDialogTe=
mplate;
HINSTANCE hInst = AfxGetResourceHandle();
HGLOBAL hDialogTemplate = m_hDialogTemplate;
if (m_lpszTemplateName != NULL)
{
hInst = AfxFindResourceHandle(=
m_lpszTemplateName, RT_DIALOG);
HRSRC hResource = ::FindResour=
ce(hInst, m_lpszTemplateName,
RT_DIALOG);
hDialogTemplate = LoadResource=
(hInst, hResource);
}
if (hDialogTemplate != NULL)
lpDialogTemplate = (LPCDLGTEMP=
LATE)LockResource(hDialogTemplate);
// return -1 in case of failure to load the dial=
og template resource
if (lpDialogTemplate == NULL)
return -1;
CreateDlgIndirect(lpDialogTemplate,m_pParentWnd,=
hInst);
// destroy modal window
DestroyWindow();
// unlock/free resources as necessary
if (m_lpszTemplateName != NULL || m_hDialogTem=
plate != NULL)
UnlockResource(hDialogTemplate);
if (m_lpszTemplateName != NULL)
FreeResource(hDialogTemplate);
return IDOK;
}
return CDialog::DoModal();
}
Donot know it is good or bad. Will really appreciate if someone comes
up with a better way...
Joseph M. Newcomer [MVP]
email: newco...@flounder.com
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm- Hide quoted text -
- Show quoted text -
Hi Joseph,
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
{
CString str;
};
class CDialogB: public CFooDialog
{
int j;
};
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.
Thanks