ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SetTimer and KillTimer??

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
643 Views, 8 Replies

SetTimer and KillTimer??

in the below code i set a timer...but when i unload the timer keeps
going...whats wrong??

Jaime

// PropTimer.cpp : Initialization functions
#include "StdAfx.h"
#include "StdArx.h"
#include "resource.h"
#include "aced.h"
#include "adslib.h"
#include "time.h"
#include "windows.h"
#include "acutads.h"
#include "adsdef.h"
#include "acedads.h"





class AsdkCommandReactor;
HINSTANCE _hdllInstance =NULL ;
AsdkCommandReactor* cmdr = NULL;

// This command registers an ARX command.
void AddCommand(const char* cmdGroup, const char* cmdInt, const char*
cmdLoc,
const int cmdFlags, const AcRxFunctionPtr
cmdProc, const int idLocal = -1);

// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_MSG
void InitApplication();
void UnloadApplication();
//}}AFX_ARX_MSG

// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_ADDIN_FUNCS
//}}AFX_ARX_ADDIN_FUNCS



////////////////////////////////////////////////////////////////////////////
/
// DLL Entry Point
extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID
/*lpReserved*/)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
_hdllInstance = hInstance;
} else if (dwReason == DLL_PROCESS_DETACH) {

}
return TRUE; // ok
}



class AsdkCommandReactor : public AcEditorReactor {

public:

virtual void commandWillStart(const char * cmdStr);
virtual void commandEnded(const char* cmdStr);
};


void AsdkCommandReactor::commandWillStart(const char* cmdStr)
{

if (strcmp(cmdStr,"PROPERTIES") == 0 )
{
acutPrintf("\nPROPERTIES IS OPEN\n");
}

}

VOID CALLBACK MyTimerProc(
HWND hWnd, // handle of CWnd that called SetTimer
UINT nMsg, // WM_TIMER
UINT nIDEvent, // timer identification
DWORD dwTime // system time
)
{

struct resbuf *Result = NULL,*cmdlist;
cmdlist = acutBuildList(RTSTR,"PROPERTIESCLOSE",RTNONE);
acedInvoke(cmdlist, &Result);
acutRelRb(cmdlist);
acutPrintf("Hello %s",nMsg);

}


UINT IDT;

void AsdkCommandReactor::commandEnded(const char* cmdStr)
{
if (strcmp(cmdStr,"PROPERTIES") == 0 )
{
acutPrintf("\nClose Properties Next");

UINT uResult;


uResult = SetTimer(NULL,IDT,5000,(TIMERPROC) MyTimerProc);
if (uResult == 0)
{
acutPrintf("\nNo Timer Is Available.");
}




}
}









////////////////////////////////////////////////////////////////////////////
/
// ObjectARX EntryPoint
extern "C" AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt)
{
switch (msg) {
case AcRx::kInitAppMsg:
// Comment out the following line if your
// application should be locked into memory
acrxDynamicLinker->unlockApplication(pkt);
acrxDynamicLinker->registerAppMDIAware(pkt);
InitApplication();
break;
case AcRx::kUnloadAppMsg:
UnloadApplication();
break;
}
return AcRx::kRetOK;
}

// Init this application. Register your
// commands, reactors...
void InitApplication()
{

// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_INIT
//}}AFX_ARX_INIT

// TODO: add your initialization functions
acutPrintf("\nProgram Loaded\n");
cmdr = new AsdkCommandReactor();
acedEditor->addReactor(cmdr);





}

// Unload this application. Unregister all objects
// registered in InitApplication.
void UnloadApplication()
{
// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_EXIT
//}}AFX_ARX_EXIT

// TODO: clean up your application
acutPrintf("\nProgram Unloaded\n");
acedEditor->removeReactor(cmdr);
delete cmdr;
KillTimer(NULL, IDT);
}

// This functions registers an ARX command.
// It can be used to read the localized command name
// from a string table stored in the resources.
void AddCommand(const char* cmdGroup, const char* cmdInt, const char*
cmdLoc,
const int cmdFlags, const AcRxFunctionPtr
cmdProc, const int idLocal)
{
char cmdLocRes[65];

// If idLocal is not -1, it's treated as an ID for
// a string stored in the resources.
if (idLocal != -1) {

// Load strings from the string table and register the
command.
::LoadString(_hdllInstance, idLocal, cmdLocRes, 64);
acedRegCmds->addCommand(cmdGroup, cmdInt, cmdLocRes,
cmdFlags, cmdProc);

} else
// idLocal is -1, so the 'hard coded'
// localized function name is used.
acedRegCmds->addCommand(cmdGroup, cmdInt, cmdLoc, cmdFlags,
cmdProc);
}
8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: Anonymous

"Jaime" wrote in message
news:22C9763E1A36F7FBAE7B1649A6974FC2@in.WebX.maYIadrTaRb...
> in the below code i set a timer...but when i unload the timer keeps
> going...whats wrong??

You'll have to excuse my not answering your question,
but I'm at a loss to understand what your code is
attmpting to do.

For one thing, you're trying to execute a command
(PROPERTIESCLOSE) using acedInvoke(), which doesn't
execute commands.

acedCommand() executes commands, but you can't use
it from a timer callback.

I really don't know think I can go further without
knowing what it is your code is attempting to do.
Message 3 of 9
Anonymous
in reply to: Anonymous

Ok try this, see SetTimer() help

You write :
>UINT IDT;
>
>void AsdkCommandReactor::commandEnded(const char* cmdStr)
>{
> if (strcmp(cmdStr,"PROPERTIES") == 0 )
> {
> acutPrintf("\nClose Properties Next");
>
> UINT uResult;
>
> uResult = SetTimer(NULL,IDT,5000,(TIMERPROC) MyTimerProc);
> if (uResult == 0)
> {
> acutPrintf("\nNo Timer Is Available.");
> }

> }
>}

Correction :
void AsdkCommandReactor::commandEnded(const char* cmdStr)
{
if (strcmp(cmdStr,"PROPERTIES") == 0 )
{
acutPrintf("\nClose Properties Next");

IDT = SetTimer(NULL,0,5000,(TIMERPROC) MyTimerProc);
if (IDT == 0)
{
acutPrintf("\nNo Timer Is Available.");
}

}
}

Here is SetTimer Doc (from MSDN) :

UINT SetTimer(
HWND hWnd, // handle of window for timer messages
UINT nIDEvent, // timer identifier
UINT uElapse, // time-out value
TIMERPROC lpTimerFunc // address of timer procedure
);

-----------------------------HERE IS UR MISTAKE -------------------------
nIDEvent
Specifies a nonzero timer identifier. If the hWnd parameter is NULL, this
parameter is ignored.

-----------------------------HERE IS WHAT U HAVE TO DO-------------
Return Values

If the function succeeds, the return value is an integer identifying the new
timer. An application can pass this value, or the string identifier, if it
exists, to the KillTimer function to destroy the timer.

If the function fails to create a timer, the return value is zero. To get
extended error information, call GetLastError.
Message 4 of 9
Anonymous
in reply to: Anonymous

well at the moment all its tring to do is kill the timer 🙂
Message 5 of 9
Anonymous
in reply to: Anonymous

sorry but youll have to use english to explain this.i dont understand why
your saying my "settimer" is wrong when that part of it works

and ive stared blankly at the msdn help files for serveal hours. (which is
where i got the examples im working from)
Message 6 of 9
Anonymous
in reply to: Anonymous

thanks for the help..but i think i figured it out (at least it works anyway)

Jaime
Message 7 of 9
Anonymous
in reply to: Anonymous

When "hwnd" parameter in SetTimer is NULL, you have to kill the timer by
returned ID.
E.g.

m_uTimerId = SetTimer(NULL, NULL, 5000, ,(TIMERPROC) MyTimerProc);
...
...
and in UnloadApplication function:

KillTimer(NULL, m_uTimerId);

MSDN Library says:
" If the hWnd parameter is NULL, second parameter (nIDEvent) is ignored."

You should declare m_uTimerId as global variable or (better) as data member
of class,
in member of which you call SetTimer.

Regards,
Vladimir Kolesnikov.

"Jaime" wrote in message
news:f105210.4@WebX.maYIadrTaRb...
> thanks for the help..but i think i figured it out (at least it works
anyway)
>
> Jaime
>
>
Message 8 of 9
Anonymous
in reply to: Anonymous

hi,

your settimer funktion only works, if there is a
ontimer (...) (mfc-code)
funktion in your code, which do something if your
timermessage
is fired.

regards
chris
Message 9 of 9
Anonymous
in reply to: Anonymous

hi,

here is a litle peace of code, may it help's

chris


////////////////////////////////////////////////////////////////////////////
////

void SomeFunktion()
{
m_nTimer = SetTimer(1, 100, NULL); // 1/10 sec
}


void OnTimer(UINT nIDEvent)
{
TRACE0( " OnTimer() entered\n" );

if (nIDEvent == 1)//
{
Do something here = 0;
}

if (nIDEvent == 2)//
{
Do something here = 1;
}

if (nIDEvent == 3)
{
Do something here = 5;
}
}

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost