[vlc-commits] doc: libvlc: add drag and drop support to the basic set_hwnd sample app
Steve Lhomme
git at videolan.org
Thu Jul 2 11:38:43 CEST 2020
vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Thu Jul 2 11:36:10 2020 +0200| [d0cac57ed86ea1869230fa8e6f01c40c639374cd] | committer: Steve Lhomme
doc: libvlc: add drag and drop support to the basic set_hwnd sample app
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d0cac57ed86ea1869230fa8e6f01c40c639374cd
---
doc/libvlc/win_player.c | 61 +++++++++++++++++++++++++++++++++++++++----------
1 file changed, 49 insertions(+), 12 deletions(-)
diff --git a/doc/libvlc/win_player.c b/doc/libvlc/win_player.c
index d298c02a88..11867cba2d 100644
--- a/doc/libvlc/win_player.c
+++ b/doc/libvlc/win_player.c
@@ -8,13 +8,50 @@
#define SCREEN_WIDTH 1500
#define SCREEN_HEIGHT 900
+struct vlc_context
+{
+ libvlc_instance_t *p_libvlc;
+ libvlc_media_player_t *p_mediaplayer;
+};
+
+
static LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
+ if( message == WM_CREATE )
+ {
+ /* Store p_mediaplayer for future use */
+ CREATESTRUCT *c = (CREATESTRUCT *)lParam;
+ SetWindowLongPtr( hWnd, GWLP_USERDATA, (LONG_PTR)c->lpCreateParams );
+ return 0;
+ }
+
+ LONG_PTR p_user_data = GetWindowLongPtr( hWnd, GWLP_USERDATA );
+ if( p_user_data == 0 )
+ return DefWindowProc(hWnd, message, wParam, lParam);
+ struct vlc_context *ctx = (struct vlc_context *)p_user_data;
+
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
+ case WM_DROPFILES:
+ {
+ HDROP hDrop = (HDROP)wParam;
+ char file_path[MAX_PATH];
+ libvlc_media_player_stop_async( ctx->p_mediaplayer );
+
+ if (DragQueryFile(hDrop, 0, file_path, sizeof(file_path)))
+ {
+ libvlc_media_t *p_media = libvlc_media_new_path( ctx->p_libvlc, file_path );
+ libvlc_media_t *p_old_media = libvlc_media_player_get_media( ctx->p_mediaplayer );
+ libvlc_media_player_set_media( ctx->p_mediaplayer, p_media );
+ libvlc_media_release( p_old_media );
+
+ libvlc_media_player_play( ctx->p_mediaplayer );
+ }
+ }
+ break;
}
return DefWindowProc (hWnd, message, wParam, lParam);
@@ -27,9 +64,8 @@ int WINAPI WinMain(HINSTANCE hInstance,
{
WNDCLASSEX wc;
char *file_path;
- libvlc_instance_t *p_libvlc;
+ struct vlc_context Context;
libvlc_media_t *p_media;
- libvlc_media_player_t *p_mp;
(void)hPrevInstance;
HWND hWnd;
@@ -43,10 +79,10 @@ int WINAPI WinMain(HINSTANCE hInstance,
else
file_path = strdup( lpCmdLine );
- p_libvlc = libvlc_new( 0, NULL );
- p_media = libvlc_media_new_path( p_libvlc, file_path );
+ Context.p_libvlc = libvlc_new( 0, NULL );
+ p_media = libvlc_media_new_path( Context.p_libvlc, file_path );
free( file_path );
- p_mp = libvlc_media_player_new_from_media( p_media );
+ Context.p_mediaplayer = libvlc_media_player_new_from_media( p_media );
ZeroMemory(&wc, sizeof(WNDCLASSEX));
@@ -72,13 +108,14 @@ int WINAPI WinMain(HINSTANCE hInstance,
NULL,
NULL,
hInstance,
- NULL);
+ &Context);
+ DragAcceptFiles(hWnd, TRUE);
- libvlc_media_player_set_hwnd(p_mp, hWnd);
+ libvlc_media_player_set_hwnd(Context.p_mediaplayer, hWnd);
ShowWindow(hWnd, nCmdShow);
- libvlc_media_player_play( p_mp );
+ libvlc_media_player_play( Context.p_mediaplayer );
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
@@ -90,11 +127,11 @@ int WINAPI WinMain(HINSTANCE hInstance,
break;
}
- libvlc_media_player_stop_async( p_mp );
+ libvlc_media_player_stop_async( Context.p_mediaplayer );
- libvlc_media_player_release( p_mp );
- libvlc_media_release( p_media );
- libvlc_release( p_libvlc );
+ libvlc_media_release( libvlc_media_player_get_media( Context.p_mediaplayer ) );
+ libvlc_media_player_release( Context.p_mediaplayer );
+ libvlc_release( Context.p_libvlc );
return msg.wParam;
}
More information about the vlc-commits
mailing list