I am working on an MFC application and want to record all the events
carried out by user. Selecting a object, a menu item, invoking dialog
etc, so that I can replay it later.
What's the strategy to start with ? Which desing pattern suitable for
this ?
By logging the WM_message, is it a good idea and then for replay I use
POSTMessage ?
I needed the same functionally so I produced a macro record and play.
As it had to be flexible I used a string parameter on the record
interface. Anything can be converted into a string and recorded in the
macro file. Playback is a little more complex. The recorded strings
are converted back into functions and parameters and called as needed.
Steve
--
Neural Planner Software Ltd http://www.NPSL1.com
JustNN. Just Neural Networks. http://www.justnn.com
EasyNN-plus. Neural Networks plus. http://www.easynn.com
SwingNN. Forecast with Neural Network. http://www.swingnn.com
Logging WM_ messages will almost certainly result in failure. Imagine that you log a
message OnRButtonDown which has a particular x,y coordinate. Play it back with the
application a half-inch to the left. What do you think you will get?
One approach is to divide your program into two components: GUI manipulation and object
manipulation. The GUI is just a way to manipulate objects. Record the object
manipulations and ignore the existence of the GUI.
Note that this only works if your initial state on replay is identical to the initial
state during recording.
joe
On Thu, 16 Oct 2008 02:57:52 -0700 (PDT), Kuenga <sagk...@gmail.com> wrote:
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
I am working on large code base. So came up with the following logging
strategy. I am just logging the menu commands. Is it correct way of
doing it or there exist better way ?
BOOL CTestApp::PreTranslateMessage( MSG* pMsg )
{
if (pMsg->message == WM_COMMAND)
{
if(gCommandDumpFlag==1){
if(HIWORD(pMsg->wParam)==0)
{
CString str;
CWnd *wnd = CWnd::FromHandle(pMsg->hwnd);
if(wnd) {
wnd->GetWindowText(str);
gCmdDump.WriteToBuffer(str);
CMenu *pCMenu = wnd->GetMenu();
if(pCMenu) {
CString str;
pCMenu->GetMenuString(LOWORD(pMsg->wParam),str,MF_BYCOMMAND);
char buf[255];
sprintf(buf," ID=%d",LOWORD(pMsg->wParam));
str+=" ";
str+=buf;
gCmdDump.WriteToBuffer(str);
}
}
}
}
return CWinApp::PreTranslateMessage(pMsg);
}