Timer Help, Message box help

Discussion in 'MFC' started by John Miogi, Apr 15, 2007.

  1. John Miogi

    John Miogi New Member

    Joined:
    Apr 15, 2007
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    Hello all, I have posted a message before, but I cant see it so I will post agian..

    I am having such a hard time with MFC SDI . I have have to make a simple timer that goes every second and I have tried everything. I also have to make a message box, and most of all, I have to get the location of the mouse when I click on the screen to print out the corordinates to the screen. I have been on thiese things for sometime and I am not getting anywhere. The only thing I made was a menu that I have to use for these things.

    Please help, and if you can, could you please help me step by step cause I am so confused with this and I have tried online google help and cannot get it..

    Thanks so much..

    John Miogi
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    All you need to be doing is add the WM_ON_TIMER and have a function OnTimer in the class.
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Of course you need to be calling the SetTimer for starting the timer.
     
  4. John Miogi

    John Miogi New Member

    Joined:
    Apr 15, 2007
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    ok, but thats my problem, I dont know how to call these things and where to get them.. I know that the class wizard will let me choose the timer, but how do I actually get it to work?
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    If you depend on Class Wizard for MFC you will know very little of how things are working. I will tell you what needs to be done.

    Add the Following in the Message Map.
    ON_WM_TIMER()

    Now add the afx_msg OnTimer(UINT nIDEvent) function in the class where you have added the above line.

    And in the InitDialog or Constructor you can call the SetTimer(ID) function to start the Timer.

    This is just the pseudo code type of thing and the function may parameter may not be correct but as far as I remember they are.
     
  6. John Miogi

    John Miogi New Member

    Joined:
    Apr 15, 2007
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    I put that code : afx_msg OnTimer(UINT nIDEvent) in the constrcutor, and added a meeage OPn_WM_Timer to the view class and I am lost after that,, I am sorry Shabbir, but I am having a hard time with it..

    Thanks

    John Miogi
     
  7. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Are you lost in the text I have written.
     
  8. John Miogi

    John Miogi New Member

    Joined:
    Apr 15, 2007
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    here is a few functions, I am using the bot one to call the timer from a drop-down menu start..
    most of it it commented off because I was getting errors
    I did not add the constrcutor here.
    Code:
    void CTest69View::OnTimer(UINT nIDEvent) 
    {
    	// TODO: Add your message handler code here and/or call default
    	
    	CView::OnTimer(nIDEvent);
        //afx_msg OnTimer(UINT nIDEvent) 
    
    }
    
    void CTest69View::OnTimerStart() 
    {
    	// TODO: Add your command handler code here
         //afx_msg OnTimer(UINT nIDEvent) 
        // SetTimer(ID)
    
       
    }
     
    Last edited by a moderator: Apr 16, 2007
  9. John Miogi

    John Miogi New Member

    Joined:
    Apr 15, 2007
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    Sorry man for being such a pain.. This summer I am going to catch up on this programming, I really want to make this work.. I am almost done the first year at colllege, have another 2 years to go..
     
  10. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Please put the code blocks when having code snippets in the post.

    Also I could not get what you have done.

    Now you need to SetTimer somewhere in constructor of the view class.

    Also after doing that please tell me if your OnTimer function is called. If yes I would assume you have the message map step done.
     
  11. John Miogi

    John Miogi New Member

    Joined:
    Apr 15, 2007
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    I want to show you my code structure, but how do I put code in blocks? lol, I am useless...
    I got the call to work, but I need to print out the timer in Int values, I have a drop-down menu which I have start, and stop. I start with a flag true, and stop with flag false. could you please help me with how I could get the timer to go to window and count in int value? and where would I put this code..

    Thanks agian..
     
  12. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Have a variable in the class and increment in the every timer event.
     
  13. John Miogi

    John Miogi New Member

    Joined:
    Apr 15, 2007
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    I want to show you my code structure, but how do I put code in blocks? lol, I am useless...
    I got the call to work, but I need to print out the timer in Int values, I have a drop-down menu which I have start, and stop. I start with a flag true, and stop with flag false. could you please help me with how I could get the timer to go to window and count in int value? and where would I put this code..

    Thanks agian..



    Code:
    void CDrawMFCView::OnTimer(UINT nIDEvent) 
    {
    	// TODO: Add your message handler code here and/or call default
    	if(flag6)
    	{
    	CView::OnTimer(nIDEvent);
    	}
    }
    
    void CDrawMFCView::OnTimerStart() 
    {
    	// TODO: Add your command handler code here
    	flag6=1;
    	SetTimer(2,5000,NULL);
    	MessageBox("100");
    }
    
    void CDrawMFCView::OnTimerStop() 
    {
    	// TODO: Add your command handler code here
    	flag6=0;
    }
     
  14. John Miogi

    John Miogi New Member

    Joined:
    Apr 15, 2007
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    Ok make up a variable, private, or public? and put the variable in the function and increament it with the timer? Ok how could I set that up.. and while you are in the mood to help(hehe), is it easy to get mouse coordinated when clicked (left or rt button) anywhere on screen to to show y, and x location? This is a bonus part us my lab, but I need this bonus to pass the course cause I am borderline..

    Thanks Shabbir..
     
  15. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Yes getting the mouse point location is very much possible but I would suggest you to go one step at a time. Is the Timer thing working.
     
  16. John Miogi

    John Miogi New Member

    Joined:
    Apr 15, 2007
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    I am sorry I did not get back to you, I was waiting for an e-mail reply to tell me that I revieved a reply..

    Anyhow, yes I got the counter(timer) thing working. I have been on the coordinates of the mouse for the last three hours. I need to click on screen after prog executes and it will show x, and y coordinates. I have not figured it out, except that I have been messing around with
    getcursorposition. I dont know if this is what I am suppose to use, but at this time, I am just going around in circles..

    BTW, Thanks alot for your help earlier and just to note that This is not from a lack of trying.. I have been in from of my laptop for three straight days trying to do these things and I am almost done, except for the mouse thingy.
     
  17. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Did you get the email reply. We have moved to another hosting and server and is just curious if anything is not functioning as expected.

    Thats good.
    Thats the best way to be doing but what you can do is have some variable of type point which stores the mouse position for the WM_MOUSEMOVE event and updates in mouse move.

    My pleasure
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice