uiTimer() Refactor TimerHandler for Windows timer IDs
This commit is contained in:
parent
4e6adca08c
commit
c9d11a85cc
|
@ -77,17 +77,6 @@ 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);
|
||||
|
@ -106,8 +95,25 @@ extern const char *initUtilWindow(HICON hDefaultIcon, HCURSOR hDefaultCursor);
|
|||
extern void uninitUtilWindow(void);
|
||||
|
||||
// main.cpp
|
||||
struct TimerHandler {
|
||||
public:
|
||||
TimerHandler() : TimerHandler(NULL, NULL) {}
|
||||
TimerHandler(int(*f)(void *data), void *data)
|
||||
{
|
||||
this->f = f;
|
||||
this->data = data;
|
||||
}
|
||||
int operator()()
|
||||
{
|
||||
return this->f(this->data);
|
||||
}
|
||||
private:
|
||||
int(*f)(void *data);
|
||||
void *data;
|
||||
};
|
||||
extern int registerMessageFilter(void);
|
||||
extern void unregisterMessageFilter(void);
|
||||
extern std::map<UINT_PTR, TimerHandler> timerHandlers;
|
||||
|
||||
// parent.cpp
|
||||
extern void paintContainerBackground(HWND hwnd, HDC dc, RECT *paintRect);
|
||||
|
|
|
@ -39,8 +39,7 @@ static LRESULT CALLBACK utilWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, L
|
|||
return 0;
|
||||
case WM_TIMER:
|
||||
id = (UINT_PTR)wParam;
|
||||
TimerHandler timer = timerHandlers[id];
|
||||
if (!timer.f(timer.data)) {
|
||||
if (!timerHandlers[id]()) {
|
||||
if (!KillTimer(utilWindow, id))
|
||||
logLastError(L"KillTimer()");
|
||||
timerHandlers.erase(id);
|
||||
|
|
Loading…
Reference in New Issue