From a4fe95b0d8d339ba5afbdb5346ad8fd367a4a1c1 Mon Sep 17 00:00:00 2001 From: Martin Herkt Date: Fri, 20 Dec 2013 20:27:56 +0100 Subject: w32_common: support file drag and drop --- video/out/w32_common.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/video/out/w32_common.c b/video/out/w32_common.c index 66c540a99b..bda267a290 100644 --- a/video/out/w32_common.c +++ b/video/out/w32_common.c @@ -176,6 +176,42 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, case WM_CLOSE: mp_input_put_key(vo->input_ctx, MP_KEY_CLOSE_WIN); break; + case WM_DROPFILES: { + HDROP hDrop = (HDROP)wParam; + UINT nfiles = DragQueryFileW(hDrop, 0xFFFFFFFF, NULL, 0); + + for (UINT i; i < nfiles; i++) { + UINT len = DragQueryFileW(hDrop, i, NULL, 0); + wchar_t *buf = talloc_array(NULL, wchar_t, len + 1); + + if (DragQueryFileW(hDrop, i, buf, len + 1) == len) { + char *fname = mp_to_utf8(NULL, buf); + + const char *cmd[] = { + "raw", + "loadfile", + fname, + /* Start playing the dropped files right away */ + (i == 0) ? "replace" : "append" + }; + + MP_VERBOSE(vo, "win32: received dropped file: %s\n", fname); + mp_cmd_t *cmdt = mp_input_parse_cmd_strv(vo->log, + MP_ON_OSD_AUTO, + cmd, ""); + mp_input_queue_cmd(vo->input_ctx, cmdt); + + talloc_free(fname); + } else { + MP_ERR(vo, "win32: error getting dropped file name\n"); + } + + talloc_free(buf); + } + + DragFinish(hDrop); + return 0; + } case WM_SYSCOMMAND: switch (wParam) { case SC_SCREENSAVE: @@ -651,6 +687,8 @@ int vo_w32_init(struct vo *vo) return 0; } + DragAcceptFiles(w32->window, TRUE); + w32->tracking = FALSE; w32->trackEvent = (TRACKMOUSEEVENT){ .cbSize = sizeof(TRACKMOUSEEVENT), -- cgit v1.2.3