]> git.sesse.net Git - vlc/blob - evc/vlc.c
* ./modules/audio_output/waveout.c: audio output now works under WinCE
[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.4 2002/11/20 16:43:32 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 = 5;
56     char * ppsz_argv[] = { lpCmdLine, "-vv", "--intf", "dummy", "shovel.mpeg", /*"washington.mpeg",*/ 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                            200,100,
93                            NULL, NULL, hInst, NULL );
94
95     ShowWindow( window, nCmdShow );
96     UpdateWindow( window );
97
98     hAccelTable = LoadAccelerators( hInst, (LPCTSTR)IDC_NIOUP );
99
100     /* Create a libvlc structure */
101     i_ret = VLC_Create();
102     if( i_ret < 0 )
103     {
104         DestroyWindow( window );
105         return i_ret;
106     }
107
108     /* Initialize libvlc */
109     i_ret = VLC_Init( 0, i_argc, ppsz_argv );
110     if( i_ret < 0 )
111     {
112         VLC_Destroy( 0 );
113         DestroyWindow( window );
114         return i_ret;
115     }
116
117     /* Run libvlc, in non-blocking mode */
118     i_ret = VLC_Play( 0 );
119
120     /* Add a non-blocking interface and keep the return value */
121     i_ret = VLC_AddIntf( 0, NULL, VLC_FALSE );
122
123     while( GetMessage( &message, NULL, 0, 0 ) )
124     {
125         if( !TranslateAccelerator(message.hwnd, hAccelTable, &message) )
126         {
127             TranslateMessage( &message );
128             DispatchMessage( &message );
129         }
130     }
131
132     /* Kill the threads */
133     VLC_Die( 0 );
134
135     /* Finish the threads */
136     VLC_Stop( 0 );
137
138     /* Destroy the libvlc structure */
139     VLC_Destroy( 0 );
140
141     DestroyWindow( window );
142
143     return i_ret;
144 }
145
146 /*****************************************************************************
147  * Message handler for the About box.
148  *****************************************************************************/
149 static LRESULT CALLBACK About ( HWND hDlg, UINT message,
150                                 WPARAM wParam, LPARAM lParam)
151 {
152     RECT rt, rt1;
153     int DlgWidth, DlgHeight;    // dialog width and height in pixel units
154     int NewPosX, NewPosY;
155
156     switch( message )
157     {
158         case WM_INITDIALOG:
159             /* trying to center the About dialog */
160             if( GetWindowRect( hDlg, &rt1 ) )
161             {
162                 GetClientRect( GetParent(hDlg), &rt );
163                 DlgWidth    = rt1.right - rt1.left;
164                 DlgHeight   = rt1.bottom - rt1.top ;
165                 NewPosX     = ( rt.right - rt.left - DlgWidth ) / 2;
166                 NewPosY     = ( rt.bottom - rt.top - DlgHeight ) / 2;
167
168                 /* if the About box is larger than the physical screen */
169                 if( NewPosX < 0 ) NewPosX = 0;
170                 if( NewPosY < 0 ) NewPosY = 0;
171                 SetWindowPos( hDlg, 0, NewPosX, NewPosY,
172                               0, 0, SWP_NOZORDER | SWP_NOSIZE );
173             }
174             return TRUE;
175
176         case WM_COMMAND:
177             if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL))
178             {
179                 EndDialog(hDlg, LOWORD(wParam));
180                 return TRUE;
181             }
182             break;
183     }
184     return FALSE;
185 }
186
187 /*****************************************************************************
188  * Message handler for the main window
189  *****************************************************************************/
190 static long FAR PASCAL WndProc ( HWND hWnd, UINT message,
191                                  WPARAM wParam, LPARAM lParam )
192 {
193     HDC hdc;
194     int wmId, wmEvent;
195     PAINTSTRUCT ps;
196
197     switch( message )
198     {
199         case WM_COMMAND:
200             wmId    = LOWORD(wParam);
201             wmEvent = HIWORD(wParam);
202             // Parse the menu selections:
203             switch( wmId )
204             {
205                 case IDM_HELP_ABOUT:
206                    DialogBox( hInst, (LPCTSTR)IDD_ABOUTBOX,
207                               hWnd, (DLGPROC)About );
208                    break;
209                 case IDM_PLOP:
210                    /* Do random stuff */
211                    break;
212                 case IDM_FILE_EXIT:
213                    DestroyWindow(hWnd);
214                    break;
215                 default:
216                    return DefWindowProc( hWnd, message, wParam, lParam );
217             }
218             break;
219         case WM_CREATE:
220             hwndCB = CommandBar_Create(hInst, hWnd, 1);
221             CommandBar_InsertMenubar(hwndCB, hInst, IDM_MENU, 0);
222             //CommandBar_AddAdornments(hwndCB, 0, 0);
223             break;
224         case WM_PAINT:
225         {
226             RECT rt;
227             hdc = BeginPaint(hWnd, &ps);
228             GetClientRect(hWnd, &rt);
229             DrawText( hdc, L"VLC roulaize!", _tcslen(L"VLC roulaize!"), &rt,
230                       DT_SINGLELINE | DT_VCENTER | DT_CENTER );
231             EndPaint(hWnd, &ps);
232             break;
233         }
234         case WM_DESTROY:
235             CommandBar_Destroy(hwndCB);
236             PostQuitMessage(0);
237             break;
238         default:
239             return DefWindowProc(hWnd, message, wParam, lParam);
240    }
241    return 0;
242 }
243