CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 36
  1. #16
    Join Date
    Jul 2007
    Location
    somwhere nearby
    Posts
    150

    Re: a program which repeats users action

    Quote Originally Posted by Eri523 View Post
    First, pardon my currently low responsiveness. Sometimes seemingly easy things can turn out to be much more time-consuming than expected...



    Of course there are differences in the API between those versions, but if that was the reason for your problems I would rather expect your program to work under XP but not 98, and not the other way 'round. I suspect a permission issue. Up to Win 98 (well, more exactly, ME) any program could practically do anything it wants. It stopped being that simple with XP (and that probably applies to 2000 too).



    I'm not sure whether I really understand how makro.exe and play.exe relate. Isn't one for recording and the other one for playback?



    You're right in that the Play button handler code (second snippet) doesn't access the ofn structure, but both snippets access the IDC_P_EDIT control's window text property and that's the "variable" they communicate over.

    I think you can set up a default file name by setting up the initial text in that edit control. At the moment I have no idea how to do that in your assembly code, though. (It would be so easy in Windows Forms... )
    about the Makro and Play , they are independent .
    while Makro is used to record and play, Play.exe is only used to run the pre recorded file at back ground through command prompt .
    i'll give it a try and then let you know what i found out
    thank you again

  2. #17
    Join Date
    Jul 2007
    Location
    somwhere nearby
    Posts
    150

    Re: a program which repeats users action

    Ok thanks to God its done
    with a simple line of code:
    Code:
    invoke SetDlgItemText,hWnd,IDC_P_EDIT,addr myFileName
    now i need to set a timer ,
    how can i do that ?
    (unless i need to use loops to simulate that timer! ) .

  3. #18
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: a program which repeats users action

    Quote Originally Posted by Master. View Post
    now i need to set a timer ,
    how can i do that ?
    I see some options, depending on what you want to do with that timer. Perhaps the simplest one is a call to Sleep() but that's not appropriate in all situations. Then there are Windows Timers which can be used in two ways: They can be set up to fire a window message or to call a callback function. (And there are certainly yet some other options that don't come to mind now.)

    (unless i need to use loops to simulate that timer! ) .
    Oh no! Not that again!

    You're kidding, aren't you?
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  4. #19
    Join Date
    Jul 2007
    Location
    somwhere nearby
    Posts
    150

    Re: a program which repeats users action

    all i want to do is to record {sleep } show and then again record { pause } show and so on .
    so far there are buttons ! i need to get rid of them and implement such a thing .
    whats your idea on this ?

  5. #20
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: a program which repeats users action

    If I understand you correctly (not 100% sure), Sleep() is no option here because your recording process is event-driven.

    So it's got to be a Windows Timer. I think it's mainly a matter of taste whether you prefer the timer to send WM_TIMER messages or use the callback method. To me it looks like what you want is a one-shot timer. This behavior isn't directly supported by the Windows Timer, but you can implement it by killing the timer in the first invocation of your timer tick handler.

    Your description of the scenario sounds to me as if you expect the user to pause after performing a single action on his app you're controlling and wait for the "echo" from your app before going on. If this is not the case, you suddenly have a much more complex scenario. In that case I think you would need some sort of queue of user actions that are time-stamped in some way to allow a correctly timed playback. (And a one-shot timer wouldn't do then.)
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  6. #21
    Join Date
    Jul 2007
    Location
    somwhere nearby
    Posts
    150

    Re: a program which repeats users action

    ok .
    i came up with the timer solution . on timer tick , i call a method inwhich Record and Play are initiated each time .
    but i have a problem here . i dont know how to invoke a button click ? i mean i know it can be done with SendMessage , but in this sample ! i have no idea how to go about it .
    i would really really appreciate any one helping on this cause i really have got no time left ( only two hours left )
    if im done with this part, its over , if not im dead (×_×)
    Code:
    onTimerTick proc hWnd:DWORD,mode2:WORD
    
      
     ; local  mode   0
     
      .IF mode2 == 0    ;start record 
          mov  realmode, 1
                               ;to test to see if this proc works well .( it does :) ) 
          ;invok e MessageBox, NULL, addr MsgBoxText1, addr MsgBoxCaption1, MB_OK 
                  ;How to simulate the Record button click here?  
                  mov ax , IDC_R_RECORD
     
    .ENDIF
       
      .IF mode2 == 1   ;start playing
          mov realmode , 0
                                ;for testing whether this proc works well or not      
          ;invok e MessageBox, NULL, addr MsgBoxText2, addr MsgBoxCaption2, MB_OK 
           ; how to simulate the play button click ? 
          mov ax , IDC_P_PLAY
          ;invoke SendMessage,IDC_P_PLAY,NULL,NULL
    
     .ENDIF
    
    
           ret 
    onTimerTick endp
    thanks in advance
    Last edited by Master.; June 12th, 2011 at 09:21 PM.

  7. #22
    Join Date
    Jul 2007
    Location
    somwhere nearby
    Posts
    150

    Re: a program which repeats users action

    ok i came up with this . thanks to God , everything works fine except a problem with file:
    here is the code:
    Code:
    onTimerTick proc hWnd:DWORD,mode2:WORD
    
      
     ; local  mode   0
     
      .IF mode2 == 0
          mov  realmode, 1
                                ;start record 
          ;invok e MessageBox, NULL, addr MsgBoxText1, addr MsgBoxCaption1, MB_OK 
    
    ;;;;;;;;;;;;;;;;;;;;;;;record
    
    
    ;.IF         0 == 0                                                                           
               ; mov stopflag,0
    	     ;	mov hookflag,1
                invoke SetDlgItemText,hWnd,IDC_R_RECORD,addr text1      ;IDC_R_RECORD.Text = "stop recording";
    
                invoke GetDlgItemText,hWnd,IDC_R_EDIT,addr recfilename,sizeof recfilename
    .IF         eax == 0                                                                                       
                invoke lstrcpy,addr recfilename,addr default
                invoke SetDlgItemText,hWnd,IDC_R_EDIT,addr default
    .ELSE                                                                                                
                                ;invoke lstrcat,addr recfilename,addr fileext 
                invoke lstrcpy,addr recfilename,addr playfilename     ; only use one filename
    .ENDIF
                invoke CreateFile,addr recfilename,GENERIC_READ+GENERIC_WRITE,0,+\
                NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0
                mov fhandle,eax
    
                invoke GetTickCount
                mov time,eax
                mov msgnbr,0
                invoke WriteFile,fhandle,addr header,12,addr byteswritten,0
    
                invoke SetWindowsHookEx,WH_JOURNALRECORD,addr RecordProc,NULL,0    
                mov hhandle,eax      
    
    
    
    .ELSE                                                                                                
                mov hookflag,0
                invoke SetDlgItemText,hWnd,IDC_R_RECORD,addr text2          ;start msg
    
                invoke SetFilePointer,fhandle,0,0,FILE_BEGIN
                invoke WriteFile,fhandle,addr header,12,addr byteswritten,0           
                invoke CloseHandle,fhandle            
                invoke UnhookWindowsHookEx,hhandle
    
    
    .ENDIF          
    ;.ENDIF            
    
    
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;
    
    ;.ENDIF
       
      .IF mode2 == 1
          mov realmode , 0
                                ;start playing     
          ;invok e MessageBox, NULL, addr MsgBoxText2, addr MsgBoxCaption2, MB_OK 
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;play
    ;.IF         hookflag == 0
     ;           mov stopflag,0
     ;           mov sleepflag,0
     ;           mov lasttime,0
                
                invoke SetDlgItemText,hWnd,IDC_P_EDIT,addr playname ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;maz ezafe kardam
                
                invoke GetDlgItemText,hWnd,IDC_P_EDIT,addr playfilename,sizeof playfilename
                invoke CreateFile,addr playfilename,GENERIC_READ,0,+\
                NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
                
                ;invoke SetDlgItemText,hWnd,IDC_P_EDIT,addr empty ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;maz ezafe kardam-2
    
                
    .IF         eax != INVALID_HANDLE_VALUE
                mov fhandle,eax
                invoke ReadFile,fhandle,addr oheader,12,addr byteswritten,0                        
    .IF         oheader == 1246259           
                invoke CloseWindow,hWnd
                invoke SetWindowsHookEx,WH_JOURNALPLAYBACK,addr PlaybckProc,NULL,0  
                mov hhandle,eax   
                
    .ELSE
                invoke CloseHandle,fhandle
                invoke MessageBox,hWnd,addr msg1,addr caption,MB_OK
    .ENDIF               
    .ELSE
                invoke MessageBox,hWnd,addr msg2,addr caption,MB_OK
    .ENDIF            
    
    .ENDIF
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
     
    
           ret 
    onTimerTick endp
    the problem is i get file is damaged or cant find file , while file is there , for frist execution of the application everything works just fine , but in the next onTimerTick proc call , i get the message "cant find the file or file is damage"
    and also system kinda hangs until the error message mentioned above shows up
    how to solve this ?

  8. #23
    Join Date
    Jul 2007
    Location
    somwhere nearby
    Posts
    150

    Re: a program which repeats users action

    ok , its over now .
    thanks to God , i could make it at last , but there are couple of minor bugs though .
    Eri523 Thank you very much for everything

  9. #24
    Join Date
    Jul 2007
    Location
    somwhere nearby
    Posts
    150

    Re: a program which repeats users action

    hello all again
    i encountered some problems concerning this program .
    my first problem is the random error message i get because of not being able to find the file !!! while the file is there next to the executable file! and i must mention that when you run the application , for the first time it can record and play just fine , but when it comes to other ticks ( there is a timer which toggles record/play mode, each 5 seconds )which happens each five seconds , the program says cant find the file!!!

    i attached the whole code+demo executable , i would greatly appreciate anyone helping me out .

    and the other problem is , when i try to use a variable (elapseTime) as a parameter for the SetTimer() function used in the project, i get that error message ( cant find file! ) . while using explicit value as parameter in SetTimer doesnt give that error !!
    any help ?

    Note:
    ( and if you are going to use the Demo executable , remember to do :
    Right click on it choose >Properties then >compatibility tab and check >Run this program in compatibility mode for Windows98/Me

  10. #25
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: a program which repeats users action

    Quote Originally Posted by Master. View Post
    my first problem is the random error message i get because of not being able to find the file !!! while the file is there next to the executable file! and i must mention that when you run the application , for the first time it can record and play just fine , but when it comes to other ticks ( there is a timer which toggles record/play mode, each 5 seconds )which happens each five seconds , the program says cant find the file!!!
    You're apparently using a relative path (i.e. a bare file name). That will fail to find the file if the current working directory has changed in the meantime. However, I have no idea what might cause this. It's just my first guess. I'd sugest to test whether using an absolute path instead helps.

    and the other problem is , when i try to use a variable (elapseTime) as a parameter for the SetTimer() function used in the project, i get that error message ( cant find file! ) . while using explicit value as parameter in SetTimer doesnt give that error !!
    I can't imagine how SetTimer could fail with anything like a "file not found", and you're not checking for failure of SetTimer at all. So first check the return value of SetTimer and in case of failure use GetLastError to determine the cause. What you describe there looks like some sort of consequential error.

    There's no sample of how you try to pass the variable to SetTimer but note that of course you need to pass it by value, not by reference. However, you're correctly passing by value all the way in the program so why should you fail to do so in this specific case?
    Last edited by Eri523; June 26th, 2011 at 09:08 AM.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  11. #26
    Join Date
    Jul 2007
    Location
    somwhere nearby
    Posts
    150

    Re: a program which repeats users action

    Quote Originally Posted by Eri523 View Post
    You're apparently using a relative path (i.e. a bare file name). That will fail to find the file if the current working directory has changed in the meantime. However, I have no idea what might cause this. It's just my first guess. I'd sugest to test whether using an absolute path instead helps.



    I can't imagine how SetTimer could fail with anything like a "file not found", and you're not checking for failure of SetTimer at all. So first check the return value of SetTimer and in case of failure use GetLastError to determine the cause. What you describe there looks like some sort of consequential error.

    There's no sample of how you try to pass the variable to SetTimer but note that of course you need to pass it by value, not by reference. However, you're correctly passing by value all the way in the program so why should you fail to do so in this specific case?
    hello
    thanks dear .
    well the first solution didnt work , used an absolute path like "C:\noname.rec" and just like before , the first time plays fine but for next tries it fails with that error : file cant be found! "
    the irony is there are cases where the application works up to 3 or four tries and this is all by chance ! it happens one time , and it doesn't happen the other time !

    and about that SetTimer, i dont know either ,
    when i write
    Code:
    invoke SetTimer,hWnd,1,5000,NULL
    everything works fine , but when i try to use :
    Code:
    invoke SetTimer,hWnd,1,elapsetime,NULL
    i get that error ( file not found ! at runtime ! )
    and i should say sth , the file not found error is shown by a messagebox , the irony here is , when i use the second method of calling SetTimer , the messagebox is just a blank white rectangle ! without any border !
    here is the pic:

  12. #27
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: a program which repeats users action

    Quote Originally Posted by Master. View Post
    Code:
    invoke SetTimer,hWnd,1,elapsetime,NULL
    Looks ok, but actually I didn't expect anything else.

    The fact that using a fully qualified path doesn't help either (so it's no problem with the CWD), in conjunction with the fact that the number of passes seemingly working correctly until the fault happens isn't constant, to me is an almost certain indication that something gets corrupted. I'd say memory corruption by a bogus write is the most probable cause, but it also can be corruption of registers, like ESP or EIP or even one of the segment registers. So now it's time to run your program in the debugger and see what's going on.

    I also never have seen a message box like that. Looks like a sign of corruption as well, though I can't point to what got corrupted causing that.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  13. #28
    Join Date
    Jul 2007
    Location
    somwhere nearby
    Posts
    150

    Re: a program which repeats users action

    Quote Originally Posted by Eri523 View Post
    Looks ok, but actually I didn't expect anything else.

    The fact that using a fully qualified path doesn't help either (so it's no problem with the CWD), in conjunction with the fact that the number of passes seemingly working correctly until the fault happens isn't constant, to me is an almost certain indication that something gets corrupted. I'd say memory corruption by a bogus write is the most probable cause, but it also can be corruption of registers, like ESP or EIP or even one of the segment registers. So now it's time to run your program in the debugger and see what's going on.

    I also never have seen a message box like that. Looks like a sign of corruption as well, though I can't point to what got corrupted causing that.
    ok how to debug it ? i have no idea how to go about it , can you help me out on this ?

  14. #29
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: a program which repeats users action

    Unfortunately not. I never had the need to debug stand-alone Windows GUI apps written in assembly yet, so I don't have any experience with that.

    Doesn't the assembler package you're using include a debugger? At least the one I used last time did. I suppose this debugger then comes with documentation and perhaps this helps to get you started.

    If that fails as well, I think we can only hope for someone who already did something like this to read the thread and jump in...
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  15. #30
    Join Date
    Jul 2007
    Location
    somwhere nearby
    Posts
    150

    Re: a program which repeats users action

    does anyone know what is that header?
    (in this line of code ?
    Code:
    invoke WriteFile,fhandle,addr header,12,addr byteswritten,0
    )
    and why it is 1246259 only ?
    i couldnt find anything on MSDN , i would appreciate if anyone can help me out .

Page 2 of 3 FirstFirst 123 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured