Implement uiTimer() for Windows
This commit is contained in:
parent
68e1223e4d
commit
b1210165a0
|
@ -1,6 +1,7 @@
|
|||
// 6 april 2015
|
||||
#include "uipriv_windows.hpp"
|
||||
|
||||
std::map<UINT_PTR, TimerHandler> timerHandlers;
|
||||
static HHOOK filter;
|
||||
|
||||
static LRESULT CALLBACK filterProc(int code, WPARAM wParam, LPARAM lParam)
|
||||
|
@ -131,4 +132,8 @@ void uiQueueMain(void (*f)(void *data), void *data)
|
|||
|
||||
void uiTimer(int milliseconds, int (*f)(void *data), void *data)
|
||||
{
|
||||
UINT_PTR id = timerHandlers.size() + 1;
|
||||
if (SetTimer(utilWindow, id, milliseconds, NULL) == 0)
|
||||
logLastError(L"SetTimer()");
|
||||
timerHandlers[id] = TimerHandler(f, data);
|
||||
}
|
||||
|
|
|
@ -77,6 +77,17 @@ extern void setWindowInsertAfter(HWND hwnd, HWND insertAfter);
|
|||
extern HWND getDlgItem(HWND hwnd, int id);
|
||||
extern void invalidateRect(HWND hwnd, RECT *r, BOOL erase);
|
||||
|
||||
struct TimerHandler {
|
||||
int(*f)(void *data);
|
||||
void *data;
|
||||
TimerHandler() {}
|
||||
TimerHandler(int(*f)(void *data), void *data) {
|
||||
this->f = f;
|
||||
this->data = data;
|
||||
}
|
||||
};
|
||||
extern std::map<UINT_PTR, TimerHandler> timerHandlers;
|
||||
|
||||
// text.cpp
|
||||
extern WCHAR *windowTextAndLen(HWND hwnd, LRESULT *len);
|
||||
extern WCHAR *windowText(HWND hwnd);
|
||||
|
|
|
@ -18,6 +18,7 @@ static LRESULT CALLBACK utilWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, L
|
|||
{
|
||||
void (*qf)(void *);
|
||||
LRESULT lResult;
|
||||
UINT_PTR id;
|
||||
|
||||
if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE)
|
||||
return lResult;
|
||||
|
@ -36,6 +37,15 @@ static LRESULT CALLBACK utilWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, L
|
|||
qf = (void (*)(void *)) wParam;
|
||||
(*qf)((void *) lParam);
|
||||
return 0;
|
||||
case WM_TIMER:
|
||||
id = (UINT_PTR)wParam;
|
||||
TimerHandler timer = timerHandlers[id];
|
||||
if (!timer.f(timer.data)) {
|
||||
if (!KillTimer(utilWindow, id))
|
||||
logLastError(L"KillTimer()");
|
||||
timerHandlers.erase(id);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue