CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 2009
    Posts
    1,355

    [RESOLVED] the timer isn't created :(

    see these code:
    Code:
    case WM_LBUTTONUP:
                    case WM_RBUTTONUP:
                    case WM_MBUTTONUP:
                    case WM_XBUTTONUP:
                    {
                        int a= SetTimer(inst ->hWnd(),JoystickTimer,120,NULL);
                        SetWindowText(inst->hwnd,to_string(a).c_str());
    //...............
    the inst is the form instance pointer.
    seems a normal code.
    the set window text works fine, so the problem isn't the 'inst' pointer. but the timer isn't created.. my question: why the timer isn't created?

  2. #2
    Join Date
    Apr 2009
    Posts
    1,355

    Re: the timer isn't created :(

    see the GetlastError():
    Code:
     case WM_LBUTTONUP:
                    case WM_RBUTTONUP:
                    case WM_MBUTTONUP:
                    case WM_XBUTTONUP:
                    {
                        SetTimer(inst ->hWnd(),JoystickTimer,120,NULL);
                        int a=GetLastError();
                        SetWindowText(inst->hwnd,to_string(a).c_str());
    the SetTimer() give me '1', and the GetLastError() give 0(zero). so what isn't right?

  3. #3
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: the timer isn't created :(

    inst->hWnd() ???
    wut ?

  4. #4
    Join Date
    Apr 2009
    Posts
    1,355

    Re: the timer isn't created :(

    Quote Originally Posted by OReubens View Post
    inst->hWnd() ???
    wut ?
    sorry about that. but it's the same of inst->hwnd

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: the timer isn't created :(

    but the timer isn't created
    ..
    the SetTimer() give me '1', and the GetLastError() give 0(zero)
    How do you know the timer isn't created as SetTimer() returns a non-zero integer to indicate success.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  6. #6
    Join Date
    Apr 2009
    Posts
    1,355

    Re: the timer isn't created :(

    Quote Originally Posted by 2kaud View Post
    How do you know the timer isn't created as SetTimer() returns a non-zero integer to indicate success.
    in form window procedure:
    Code:
     case WM_TIMER:
                    {
                        if (wParam == timerid)//for mouse stoped and it's working normaly
                        {
                            PreviousLocation = Location;
                            GetCursorPos(&Location);
                            if ((Location.x = PreviousLocation.x) && (Location.y = PreviousLocation.y))
                            {
                                KillTimer(inst->hWnd(), timerid);
                                inst->MouseStoped();
                            }
                        }
                        else if(wParam==JoystickTimer)//for joystick, but the timer isn't created :(
                        {
                            MessageBox(NULL,"heello","hi",MB_OK);
                            inst->setText("joystick");
                            joySetCapture(inst->hWnd(),JOYSTICKID1,120,true);
                            JOYINFOEX  b;
                            b.dwSize=sizeof(JOYINFOEX );
                            b.dwFlags=JOY_RETURNALL;
                            joyGetPosEx(JOYSTICKID1,&b);
                            inst->setText(to_string(b.dwButtonNumber));
                            joyReleaseCapture(JOYSTICKID1);
                        }
                    }
                    break;
    the messagebox isn't showed

  7. #7
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: the timer isn't created :(

    Is this
    case WM_TIMER:
    in the WindowProc of the inst->hWnd?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  8. #8
    Join Date
    Apr 2009
    Posts
    1,355

    Re: the timer isn't created :(

    Quote Originally Posted by VladimirF View Post
    Is this
    case WM_TIMER:
    in the WindowProc of the inst->hWnd?
    yes..
    Code:
    static LRESULT CALLBACK WndProcForm(HWND HandleWindow, UINT msg, WPARAM wParam, LPARAM lParam)
            {
                static POINT PreviousLocation, Location;
                static bool Tracking = false;
                static MouseButtons MBButtons;
                static bool blControl = false;
                static bool blShift = false;
                static bool blResize = false;
                static int xPos = 0;
                static int yPos = 0;
                static UINT_PTR timerid=0;
                static UINT_PTR JoystickTimer=0;
                static bool blnDrag = false;
                static bool KeyPressed=false;
                static int KeyDownCount=0;
                UINT JoystickCount =0;
    
                form *inst = (form *)GetWindowLongPtr(HandleWindow, GWLP_USERDATA);//the inst is created here
    
    
    
                if(inst!=NULL && inst->Create!=NULL )
                {
                    static bool i=true;
                     if(i==true)
                     {
                        i=false;
    
                        inst -> Create(inst->getLeft(), inst->getTop());
                     }
                }
    
                HBRUSH g_hbrBackground = NULL;
    
                //Working with messages
                switch(msg)
                {
                    case WM_NCCREATE:
                    {
                        CREATESTRUCT *p = (CREATESTRUCT *)lParam;
                        inst = (form *)p->lpCreateParams;
                        SetWindowLongPtr(HandleWindow, GWLP_USERDATA, (LONG_PTR)inst);
                        inst->hwnd = HandleWindow;
    
    
                    }
                    break;
                    case WM_TIMER:
                    {
                        if (wParam == timerid)//for mouse stoped and it's working normaly
                        {
                            PreviousLocation = Location;
                            GetCursorPos(&Location);
                            if ((Location.x = PreviousLocation.x) && (Location.y = PreviousLocation.y))
                            {
                                KillTimer(inst->hWnd(), timerid);
                                inst->MouseStoped();
                            }
                        }
                        else if(wParam==JoystickTimer)//for joystick, but the timer isn't created :(
                        {
                            MessageBox(NULL,"heello","hi",MB_OK);
                            inst->setText("joystick");
                            joySetCapture(inst->hWnd(),JOYSTICKID1,120,true);
                            JOYINFOEX  b;
                            b.dwSize=sizeof(JOYINFOEX );
                            b.dwFlags=JOY_RETURNALL;
                            joyGetPosEx(JOYSTICKID1,&b);
                            inst->setText(to_string(b.dwButtonNumber));
                            joyReleaseCapture(JOYSTICKID1);
                        }
                    }
                    break;

  9. #9
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: the timer isn't created :(

    Code:
    static UINT_PTR timerid=0;
    static UINT_PTR JoystickTimer=0;
    Are you changing these values to distinct ones somewhere - otherwise your timeid for mouse and joystick timer have the same ID!!!!!!!!

    Also shouldn't
    Code:
    if ((Location.x = PreviousLocation.x) && (Location.y = PreviousLocation.y))
    be
    Code:
    if ((Location.x == PreviousLocation.x) && (Location.y == PreviousLocation.y))
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  10. #10
    Join Date
    Apr 2009
    Posts
    1,355

    Re: the timer isn't created :(

    Quote Originally Posted by 2kaud View Post
    Code:
    static UINT_PTR timerid=0;
    static UINT_PTR JoystickTimer=0;
    Are you changing these values to distinct ones somewhere - otherwise your timeid for mouse and joystick timer have the same ID!!!!!!!!

    Also shouldn't
    Code:
    if ((Location.x = PreviousLocation.x) && (Location.y = PreviousLocation.y))
    be
    Code:
    if ((Location.x == PreviousLocation.x) && (Location.y == PreviousLocation.y))
    you have right in both situations.. thanks for all
    now it's working.
    thanks for all.. thank you

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