]> git.sesse.net Git - vlc/blob - evc/vlc.c
6ca4202736453fe4520a97f79bccf2b015180707
[vlc] / evc / vlc.c
1 /*****************************************************************************
2  * vlc.c: the vlc player, WinCE version
3  *****************************************************************************
4  * Copyright (C) 2002 VideoLAN
5  * $Id: vlc.c,v 1.1 2002/11/13 15:28:24 sam Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 #include "config.h"
25
26 #define WIN32_LEAN_AND_MEAN
27 #include <windows.h>
28 #include <commctrl.h>
29
30 #include "../share/resource.h"
31
32 #include <vlc/vlc.h>
33
34 /*****************************************************************************
35  * Local prototypes.
36  *****************************************************************************/
37 static LRESULT CALLBACK About ( HWND hDlg, UINT message,
38                                 WPARAM wParam, LPARAM lParam );
39 static long FAR PASCAL WndProc ( HWND hWnd, UINT message,
40                                  WPARAM wParam, LPARAM lParam );
41
42 /*****************************************************************************
43  * Global variables.
44  *****************************************************************************/
45 HINSTANCE hInst;
46 HWND      hwndCB;
47
48 /*****************************************************************************
49  * main: parse command line, start interface and spawn threads
50  *****************************************************************************/
51 int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
52                     LPTSTR lpCmdLine, int nCmdShow )
53 {
54     int    i_ret;
55     int    i_argc = 2;
56     char * ppsz_argv[] = { lpCmdLine, "-vv", NULL };
57     HWND   window;
58     MSG    message;
59
60     HACCEL   hAccelTable;
61     WNDCLASS wc;
62
63     char     psz_title[100];
64     wchar_t  pwz_title[100];
65
66     /* Store our instance for future reference */
67     hInst = hInstance;
68
69     /* Register window class */
70     wc.style          = CS_HREDRAW | CS_VREDRAW;
71     wc.lpfnWndProc    = (WNDPROC) WndProc;
72     wc.cbClsExtra     = 0;
73     wc.cbWndExtra     = 0;
74     wc.hInstance      = hInst;
75     wc.hIcon          = 0;
76     wc.hCursor        = 0;
77     wc.hbrBackground  = (HBRUSH) GetStockObject(WHITE_BRUSH);
78     wc.lpszMenuName   = 0;
79     wc.lpszClassName  = L"VLC";
80
81     RegisterClass(&wc);
82
83     /* Print the version information */
84     sprintf( psz_title, "VideoLAN Client %s", VLC_Version() );
85     MultiByteToWideChar( CP_ACP, 0, psz_title, -1, pwz_title, 100 );
86
87     /* Create our nice window */
88     window = CreateWindow( L"VLC", pwz_title,
89                            WS_VISIBLE | WS_SIZEBOX | WS_CAPTION,
90                            CW_USEDEFAULT, CW_USEDEFAULT,
91                            CW_USEDEFAULT, CW_USEDEFAULT, 
92                            NULL, NULL, hInst, NULL );
93
94     ShowWindow( window, nCmdShow );
95     UpdateWindow( window );
96
97     hAccelTable = LoadAccelerators( hInst, (LPCTSTR)IDC_NIOUP );
98
99     /* Create a libvlc structure */
100     i_ret = VLC_Create();
101     if( i_ret < 0 )
102     {
103         DestroyWindow( window );
104         return i_ret;
105     }
106
107     /* Initialize libvlc */
108     i_ret = VLC_Init( 0, i_argc, ppsz_argv );
109     if( i_ret < 0 )
110     {
111         VLC_Destroy( 0 );
112         DestroyWindow( window );
113         return i_ret;
114     }
115
116     /* Run libvlc, in non-blocking mode */
117     i_ret = VLC_Play( 0 );
118
119     /* Add a non-blocking interface and keep the return value */
120     i_ret = VLC_AddIntf( 0, NULL, VLC_FALSE );
121
122     while( GetMessage( &message, NULL, 0, 0 ) )
123     {
124         if( !TranslateAccelerator(message.hwnd, hAccelTable, &message) )
125         {
126             TranslateMessage( &message );
127             DispatchMessage( &message );
128         }
129     }
130
131     /* Kill the threads */
132     VLC_Die( 0 );
133
134     /* Finish the threads */
135     VLC_Stop( 0 );
136
137     /* Destroy the libvlc structure */
138     VLC_Destroy( 0 );
139
140     DestroyWindow( window );
141
142     return i_ret;
143 }
144
145 /*****************************************************************************
146  * Message handler for the About box.
147  *****************************************************************************/
148 static LRESULT CALLBACK About ( HWND hDlg, UINT message,
149                                 WPARAM wParam, LPARAM lParam)
150 {
151     RECT rt, rt1;
152     int DlgWidth, DlgHeight;    // dialog width and height in pixel units
153     int NewPosX, NewPosY;
154
155     switch( message )
156     {
157         case WM_INITDIALOG:
158             /* trying to center the About dialog */
159             if( GetWindowRect( hDlg, &rt1 ) )
160             {
161                 GetClientRect( GetParent(hDlg), &rt );
162                 DlgWidth    = rt1.right - rt1.left;
163                 DlgHeight   = rt1.bottom - rt1.top ;
164                 NewPosX     = ( rt.right - rt.left - DlgWidth ) / 2;
165                 NewPosY     = ( rt.bottom - rt.top - DlgHeight ) / 2;
166
167                 /* if the About box is larger than the physical screen */
168                 if( NewPosX < 0 ) NewPosX = 0;
169                 if( NewPosY < 0 ) NewPosY = 0;
170                 SetWindowPos( hDlg, 0, NewPosX, NewPosY,
171                               0, 0, SWP_NOZORDER | SWP_NOSIZE );
172             }
173             return TRUE;
174
175         case WM_COMMAND:
176             if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL))
177             {
178                 EndDialog(hDlg, LOWORD(wParam));
179                 return TRUE;
180             }
181             break;
182     }
183     return FALSE;
184 }
185
186 /*****************************************************************************
187  * Message handler for the main window
188  *****************************************************************************/
189 static long FAR PASCAL WndProc ( HWND hWnd, UINT message,
190                                  WPARAM wParam, LPARAM lParam )
191 {
192     HDC hdc;
193     int wmId, wmEvent;
194     PAINTSTRUCT ps;
195
196     switch( message )
197     {
198         case WM_COMMAND:
199             wmId    = LOWORD(wParam);
200             wmEvent = HIWORD(wParam);
201             // Parse the menu selections:
202             switch( wmId )
203             {
204                 case IDM_HELP_ABOUT:
205                    DialogBox( hInst, (LPCTSTR)IDD_ABOUTBOX,
206                               hWnd, (DLGPROC)About );
207                    break;
208                 case IDM_PLOP:
209                    /* Do random stuff */
210                    break;
211                 case IDM_FILE_EXIT:
212                    DestroyWindow(hWnd);
213                    break;
214                 default:
215                    return DefWindowProc( hWnd, message, wParam, lParam );
216             }
217             break;
218         case WM_CREATE:
219             hwndCB = CommandBar_Create(hInst, hWnd, 1);
220             CommandBar_InsertMenubar(hwndCB, hInst, IDM_MENU, 0);
221             CommandBar_AddAdornments(hwndCB, 0, 0);
222             break;
223         case WM_PAINT:
224         {
225             RECT rt;
226             hdc = BeginPaint(hWnd, &ps);
227             GetClientRect(hWnd, &rt);
228             DrawText( hdc, L"VLC roulaize!", _tcslen(L"VLC roulaize!"), &rt,
229                       DT_SINGLELINE | DT_VCENTER | DT_CENTER );
230             EndPaint(hWnd, &ps);
231             break;
232         }
233         case WM_DESTROY:
234             CommandBar_Destroy(hwndCB);
235             PostQuitMessage(0);
236             break;
237         default:
238             return DefWindowProc(hWnd, message, wParam, lParam);
239    }
240    return 0;
241 }
242