[PATCH v2 4/4] comctl32/taskdialog: Add support for timer.

Zhiyi Zhang zzhang at codeweavers.com
Fri May 18 04:23:58 CDT 2018


Signed-off-by: Zhiyi Zhang <zzhang at codeweavers.com>
---
 dlls/comctl32/taskdialog.c       | 25 ++++++++++++++++++++++-
 dlls/comctl32/tests/taskdialog.c | 34 ++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/dlls/comctl32/taskdialog.c b/dlls/comctl32/taskdialog.c
index ba19ed51a6..f458e32002 100644
--- a/dlls/comctl32/taskdialog.c
+++ b/dlls/comctl32/taskdialog.c
@@ -48,10 +48,13 @@ static const UINT DIALOG_MIN_WIDTH = 240;
 static const UINT DIALOG_SPACING = 5;
 static const UINT DIALOG_BUTTON_WIDTH = 50;
 static const UINT DIALOG_BUTTON_HEIGHT = 14;
+static const UINT DIALOG_TIMER_MS = 200;
 
 static const UINT ID_MAIN_INSTRUCTION = 0xf000;
 static const UINT ID_CONTENT          = 0xf001;
 
+static const UINT ID_TIMER = 1;
+
 struct taskdialog_control
 {
     struct list entry;
@@ -85,6 +88,7 @@ struct taskdialog_info
 {
     HWND hwnd;
     const TASKDIALOGCONFIG *taskconfig;
+    DWORD last_timer_tick;
 };
 
 static void pixels_to_dialogunits(const struct taskdialog_template_desc *desc, LONG *width, LONG *height)
@@ -533,6 +537,19 @@ static void taskdialog_on_button_click(struct taskdialog_info *dialog_info, WORD
         EndDialog(dialog_info->hwnd, command_id);
 }
 
+static void taskdialog_init(struct taskdialog_info *dialog_info, HWND hwnd)
+{
+    const TASKDIALOGCONFIG *taskconfig = dialog_info->taskconfig;
+
+    dialog_info->hwnd = hwnd;
+
+    if (taskconfig->dwFlags & TDF_CALLBACK_TIMER)
+    {
+        SetTimer(hwnd, ID_TIMER, DIALOG_TIMER_MS, NULL);
+        dialog_info->last_timer_tick = GetTickCount();
+    }
+}
+
 static INT_PTR CALLBACK taskdialog_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 {
     static const WCHAR taskdialog_info_propnameW[] = {'T','a','s','k','D','i','a','l','o','g','I','n','f','o',0};
@@ -550,8 +567,8 @@ static INT_PTR CALLBACK taskdialog_proc(HWND hwnd, UINT msg, WPARAM wParam, LPAR
             break;
         case WM_INITDIALOG:
             dialog_info = (struct taskdialog_info *)lParam;
-            dialog_info->hwnd = hwnd;
             SetPropW(hwnd, taskdialog_info_propnameW, dialog_info);
+            taskdialog_init(dialog_info, hwnd);
 
             taskdialog_notify(dialog_info, TDN_DIALOG_CONSTRUCTED, 0, 0);
             break;
@@ -568,9 +585,15 @@ static INT_PTR CALLBACK taskdialog_proc(HWND hwnd, UINT msg, WPARAM wParam, LPAR
         case WM_HELP:
             taskdialog_notify(dialog_info, TDN_HELP, 0, 0);
             break;
+        case WM_TIMER:
+            if (ID_TIMER == wParam
+                && taskdialog_notify(dialog_info, TDN_TIMER, GetTickCount() - dialog_info->last_timer_tick, 0) == S_FALSE)
+                dialog_info->last_timer_tick = GetTickCount();
+            break;
         case WM_DESTROY:
             taskdialog_notify(dialog_info, TDN_DESTROYED, 0, 0);
             RemovePropW(hwnd, taskdialog_info_propnameW);
+            if (dialog_info->taskconfig->dwFlags & TDF_CALLBACK_TIMER) KillTimer(dialog_info->hwnd, ID_TIMER);
             break;
         default:
             return FALSE;
diff --git a/dlls/comctl32/tests/taskdialog.c b/dlls/comctl32/tests/taskdialog.c
index ad455554b2..94fb25abb3 100644
--- a/dlls/comctl32/tests/taskdialog.c
+++ b/dlls/comctl32/tests/taskdialog.c
@@ -323,6 +323,39 @@ static void test_help(void)
     run_test(&info, IDOK, msg_got_tdn_help, "send f1");
 }
 
+static HRESULT CALLBACK taskdialog_callback_proc_timer(HWND hwnd, UINT notification, WPARAM wParam, LPARAM lParam,
+                                                       LONG_PTR ref_data)
+{
+    int elapsed_ms;
+    int delta;
+    static int last_elapsed_ms = 0;
+    static int fired_count = 0;
+    if (notification == TDN_TIMER)
+    {
+        fired_count++;
+        elapsed_ms = (int)wParam;
+        delta = elapsed_ms - last_elapsed_ms;
+        ok(delta > 0, "Expect timer delta positive\n");
+        last_elapsed_ms = elapsed_ms;
+    }
+
+    if (fired_count == 2) SendMessageW(hwnd, TDM_CLICK_BUTTON, IDOK, 0);
+
+    return S_OK;
+}
+
+static void test_timer(void)
+{
+    TASKDIALOGCONFIG info = {0};
+
+    info.cbSize = sizeof(TASKDIALOGCONFIG);
+    info.pfCallback = taskdialog_callback_proc_timer;
+    info.dwFlags = TDF_CALLBACK_TIMER;
+    info.dwCommonButtons = TDCBF_OK_BUTTON;
+
+    pTaskDialogIndirect(&info, NULL, NULL, NULL);
+}
+
 START_TEST(taskdialog)
 {
     ULONG_PTR ctx_cookie;
@@ -360,6 +393,7 @@ START_TEST(taskdialog)
     test_callback();
     test_buttons();
     test_help();
+    test_timer();
 
     unload_v6_module(ctx_cookie, hCtx);
 }
-- 
2.17.0




More information about the wine-devel mailing list