window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
and that
hWndMain = ( HWND )gdk_win32_drawable_get_handle( GTK_WIDGET( window )->window );
hInst = ( HINSTANCE )GetWindowLong( hWndMain, GWL_HINSTANCE );
getting hwnd for window and set that to libvlc will result a strange result in gtk player. all player gtk window will be covered by the played stream.
we need a window handler inside the gtk player, and this is the vlc widget.
first step, attach a windows window to a gtk window, and followi with the windows window the evolution of gtk widget.
Code:
#include <windows.h>
#include <gdk\gdkwin32.h>
#include <gtk\gtk.h>
#include <glib.h>
static HWND hWndMain;
static HINSTANCE hInst;
char *pszVLC = "vlc";
HWND hWndVLC = ( HWND )0;
#define WM_RESIZE 1213
LRESULT CALLBACK VLCProc( HWND hWnd,
UINT iMsg,
WPARAM wParam,
LPARAM lParam ) {
switch ( iMsg ) {
case WM_CREATE:
return( TRUE );
case WM_PAINT: {
HDC hdc;
PAINTSTRUCT ps;
hdc = BeginPaint( hWnd, &ps );
EndPaint( hWnd, &ps );
}
return( 0L );
case WM_RESIZE:
// here we get frame2 coordinates and size and we do the same with windows window.
MoveWindow( hWnd, LOWORD( wParam ), HIWORD( wParam ), LOWORD( lParam ), HIWORD( lParam ), TRUE );
break;
case WM_CLOSE:
DestroyWindow( hWnd );
return( TRUE );
case WM_DESTROY:
hWndVLC = 0;
UnregisterClass( pszVLC, hInst );
return( TRUE );
} /* endswitch */
return DefWindowProc( hWnd, iMsg, wParam, lParam );
} // ***** Function VLCProc ***** //
ATOM pascal RegisterVLCClass( HINSTANCE hInstance ) {
ATOM atResult;
WNDCLASSEX wndclass ;
wndclass.hInstance = hInstance;
wndclass.lpszClassName = ( LPSTR )pszVLC;
wndclass.lpfnWndProc = VLCProc;
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
wndclass.cbSize = sizeof( WNDCLASSEX );
wndclass.hIcon = NULL;
wndclass.hIconSm = NULL;
wndclass.hCursor = LoadCursor( NULL, IDC_ARROW );
wndclass.lpszMenuName = NULL;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hbrBackground = ( HBRUSH )( COLOR_BTNFACE + 1 );
return( RegisterClassEx( &wndclass ) );
} // ***** Function RegisterVLCClass ***** //
static WPARAM BuildWParam( unsigned short low, unsigned short high ) {
return ((( WPARAM )high << 16 ) | ( WPARAM )low );
}
gint destroyapp( GtkWidget *widget, gpointer gdata ) {
g_print ("Quitting...\n");
SendMessage( hWndVLC, WM_CLOSE, 0L, 0L );
gtk_main_quit();
return (FALSE);
}
void gtkVLCEvent( GtkWidget *widget, gpointer gdata ) {
if ( hWndVLC )
SendMessage( hWndVLC,
WM_RESIZE,
BuildWParam( widget->allocation.x , widget->allocation.y ),
BuildWParam( widget->allocation.width, widget->allocation.height ));
}
int main( int argc,
char *argv[] ) {
GtkWidget *window = NULL;
GtkWidget *main_vbox;
GtkWidget *vbox;
GtkWidget *frame_horz;
GtkWidget *button;
gtk_init( &argc, &argv );
window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
gtk_window_set_title( GTK_WINDOW( window ), "test window" );
gtk_widget_set_size_request( GTK_WIDGET( window ), 200, 200 );
g_signal_connect( G_OBJECT( window ), "destroy", G_CALLBACK( gtk_main_quit ), NULL );
gtk_container_set_border_width( GTK_CONTAINER( window ), 10 );
main_vbox = gtk_vbox_new( FALSE, 0 );
gtk_container_add( GTK_CONTAINER ( window ), main_vbox );
frame_horz = gtk_frame_new( "frame1" );
gtk_box_pack_start( GTK_BOX( main_vbox ), frame_horz, TRUE, TRUE, 10 );
frame_horz = gtk_frame_new( "frame2" );
gtk_box_pack_start( GTK_BOX( main_vbox ), frame_horz, TRUE, TRUE, 10 );
g_signal_connect( G_OBJECT( frame_horz ), "size-allocate", G_CALLBACK( gtkVLCEvent ), frame_horz );
vbox = gtk_hbox_new( FALSE, 0 );
gtk_box_pack_start( GTK_BOX( main_vbox ), vbox, TRUE, TRUE, 0 );
button = gtk_button_new_with_label("click");
gtk_box_pack_start( GTK_BOX( vbox ), button, TRUE, FALSE, 0);
gtk_widget_show_all( window );
// main handler and instance to window.
hWndMain = ( HWND )gdk_win32_drawable_get_handle( GTK_WIDGET( window )->window );
hInst = ( HINSTANCE )GetWindowLong( hWndMain, GWL_HINSTANCE );
RegisterVLCClass( hInst );
hWndVLC = CreateWindowEx( 0,
pszVLC,
"",
WS_CHILD | WS_VISIBLE | WS_BORDER | WS_CLIPSIBLINGS,
frame_horz->allocation.x,
frame_horz->allocation.y,
frame_horz->allocation.width,
frame_horz->allocation.height,
hWndMain,
NULL,
hInst,
NULL );
ShowWindow( hWndVLC, SW_SHOW );
UpdateWindow( hWndVLC );
gtk_main();
return 0;
}
and now we will follow the gtk "frame2" in all his actions with a hWndVLC windows, and this window will be set to libvlc player.