-
July 31st, 2014, 06:08 AM
#1
[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?
-
July 31st, 2014, 06:11 AM
#2
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?
-
July 31st, 2014, 07:16 AM
#3
Re: the timer isn't created :(
-
July 31st, 2014, 07:19 AM
#4
Re: the timer isn't created :(
Originally Posted by OReubens
inst->hWnd() ???
wut ?
sorry about that. but it's the same of inst->hwnd
-
July 31st, 2014, 07:26 AM
#5
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)
-
July 31st, 2014, 07:29 AM
#6
Re: the timer isn't created :(
Originally Posted by 2kaud
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
-
July 31st, 2014, 10:49 AM
#7
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...
-
July 31st, 2014, 10:59 AM
#8
Re: the timer isn't created :(
Originally Posted by VladimirF
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;
-
July 31st, 2014, 11:40 AM
#9
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)
-
July 31st, 2014, 11:45 AM
#10
Re: the timer isn't created :(
Originally Posted by 2kaud
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|