I'm using Win32 API timer procedure like this:
typedef struct my_parameter {
}MyParam,*pMyParam;
pMyParam my_param;
void MyTimeProc(HWND hwnd,UINT msg,UINT_PTR nIDEvent,DWORD tickCount) {
}
int MyStartTimerProcedure(HWND hwnd) {
UINT msg=WM_TIMER;
UINT_PTR nIDEvent;
UINT uElapse=1000;
TIMERPROC timeProc=MyTimeProc;
SetTimer(hwnd,nIDEvent,uElapse,timeProc);
return 0;
}
As you see,win32 function pointer
TIMERPROC and Win32 API
SetTimer both have serval parameters. If I want to change the global variable
my_param as a parameter passing between SetTimer and TimerProc, the interface seems not supported.
What I have tried:
In order to replace the global variable , from what I know, I have to write some code to manage the variable between SetTimer and TimerProc, like this:
typedef struct timer_param {
UINT_PTR param_idevent;
void* param_data;
timer_param* next;
}TimerParam,pTimerParam;
pTimerParam global_timerparam;
pTimerParam NewGlobalTimerParam() {
pTimerParam param=(pTimerParam)calloc(sizeof(Timer),1);
return param;
}
pTimerParam GetTimerParam() {
return global_timerparam;
}
int AppendNewGlobalTimerParam(UINT_PTR nIDEvent,void* data) {
pTimerParam param=NewGlobalTimerParam();
if(param==NULL) return -1;
param->param_idevent=nIDEvent;
param->param_data=data;
pTimerParam tmp=GetTimerParam();
pTimerParam pre=tmp;
while(tmp) {
pre=tmp;
tmp=tmp->next;
}
if(pre==NULL) pre=param;
else pre->next=param;
return 0;
}
pTimerParam FetchParamFromIDEvent(UINT_PTR nIDEvent) {
pTimerParam tmp=GetTimerParam();
while(tmp) {
if(tmp->param_idevent==nIDEvent) return tmp;
tmp=tmp->next;
}
return NULL;
}
typedef struct my_parameter {
}MyParam,*pMyParam;
void MyTimeProc(HWND hwnd,UINT msg,UINT_PTR nIDEvent,DWORD tickCount) {
pMyParam param=(pMyParam)FetchParamFromIDEvent(nIDEvent);
if(param) {
}
}
int MyStartTimerProcedure(HWND hwnd) {
UINT msg=WM_TIMER;
UINT_PTR nIDEvent;
UINT uElapse=1000;
TIMERPROC timeProc=MyTimeProc;
pMyParam my_param;
AppendNewGlobalTimerParam(nIDEvent,my_param);
SetTimer(hwnd,nIDEvent,uElapse,timeProc);
return 0;
}
Yes, it would work. But it's too much inconvenient. I have to do a lot to manage the parameters passing into the timerprocedure.
Is there a more easy way to pass parameters into the TIMERPROC function ?