]> git.sesse.net Git - vlc/blob - evc/vlc.c
* extras/contrib/src/ dvdnav packages
[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.6 2004/01/24 21:06:52 hartman 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 = 4;
56     char * ppsz_argv[] = { lpCmdLine, "-vv", "--intf", "dummy", NULL, 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     i_argc = 5;
67     ppsz_argv[4] = "washington.mpeg";
68     ppsz_argv[4] = "shovel.mpeg";
69     ppsz_argv[4] = "11h50.wav";
70     ppsz_argv[4] = "apple_promouse.mpeg";
71
72     /* Store our instance for future reference */
73     hInst = hInstance;
74
75     /* Register window class */
76     memset( &wc, 0, sizeof(wc) );
77     wc.style          = CS_HREDRAW | CS_VREDRAW;
78     wc.lpfnWndProc    = (WNDPROC) WndProc;
79     wc.cbClsExtra     = 0;
80     wc.cbWndExtra     = 0;
81     wc.hInstance      = hInst;
82     wc.hIcon          = 0;
83     wc.hCursor        = 0;
84     wc.hbrBackground  = (HBRUSH) GetStockObject(WHITE_BRUSH);
85     wc.lpszMenuName   = 0;
86     wc.lpszClassName  = L"VLC";
87
88     RegisterClass(&wc);
89
90     /* Print the version information */
91     sprintf( psz_title, "VLC media player %s", VLC_Version() );
92     MultiByteToWideChar( CP_ACP, 0, psz_title, -1, pwz_title, 100 );
93
94     /* Create our nice window */
95     window = CreateWindow( L"VLC", pwz_title,
96                            WS_VISIBLE /*| WS_SIZEBOX | WS_CAPTION*/,
97                            CW_USEDEFAULT, CW_USEDEFAULT,
98                            //CW_USEDEFAULT, CW_USEDEFAULT, 
99                            200,200,
100                            NULL, NULL, hInst, NULL );
101
102     ShowWindow( window, nCmdShow );
103     UpdateWindow( window );
104
105     hAccelTable = LoadAccelerators( hInst, (LPCTSTR)IDC_NIOUP );
106
107     /* Create a libvlc structure */
108     i_ret = VLC_Create();
109     if( i_ret < 0 )
110     {
111         DestroyWindow( window );
112         return i_ret;
113     }
114
115     /* Initialize libvlc */
116     i_ret = VLC_Init( 0, i_argc, ppsz_argv );
117     if( i_ret < 0 )
118     {
119         VLC_Destroy( 0 );
120         DestroyWindow( window );
121         return i_ret;
122     }
123
124     /* Run libvlc, in non-blocking mode */
125     i_ret = VLC_Play( 0 );
126
127     /* Add a non-blocking interface and keep the return value */
128     i_ret = VLC_AddIntf( 0, NULL, VLC_FALSE );
129
130     while( GetMessage( &message, NULL, 0, 0 ) )
131     {
132         if( !TranslateAccelerator(message.hwnd, hAccelTable, &message) )
133         {
134             TranslateMessage( &message );
135             DispatchMessage( &message );
136         }
137     }
138
139     /* Kill the threads */
140     VLC_Die( 0 );
141
142     /* Finish the threads */
143     VLC_Stop( 0 );
144
145     /* Destroy the libvlc structure */
146     VLC_Destroy( 0 );
147
148     DestroyWindow( window );
149
150     return i_ret;
151 }
152
153 /*****************************************************************************
154  * Message handler for the About box.
155  *****************************************************************************/
156 static LRESULT CALLBACK About ( HWND hDlg, UINT message,
157                                 WPARAM wParam, LPARAM lParam)
158 {
159     RECT rt, rt1;
160     int DlgWidth, DlgHeight;    // dialog width and height in pixel units
161     int NewPosX, NewPosY;
162
163     switch( message )
164     {
165         case WM_INITDIALOG:
166             /* trying to center the About dialog */
167             if( GetWindowRect( hDlg, &rt1 ) )
168             {
169                 GetClientRect( GetParent(hDlg), &rt );
170                 DlgWidth    = rt1.right - rt1.left;
171                 DlgHeight   = rt1.bottom - rt1.top ;
172                 NewPosX     = ( rt.right - rt.left - DlgWidth ) / 2;
173                 NewPosY     = ( rt.bottom - rt.top - DlgHeight ) / 2;
174
175                 /* if the About box is larger than the physical screen */
176                 if( NewPosX < 0 ) NewPosX = 0;
177                 if( NewPosY < 0 ) NewPosY = 0;
178                 SetWindowPos( hDlg, 0, NewPosX, NewPosY,
179                               0, 0, SWP_NOZORDER | SWP_NOSIZE );
180             }
181             return TRUE;
182
183         case WM_COMMAND:
184             if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL))
185             {
186                 EndDialog(hDlg, LOWORD(wParam));
187                 return TRUE;
188             }
189             break;
190     }
191     return FALSE;
192 }
193
194 /*****************************************************************************
195  * Message handler for the main window
196  *****************************************************************************/
197 static long FAR PASCAL WndProc ( HWND hWnd, UINT message,
198                                  WPARAM wParam, LPARAM lParam )
199 {
200     HDC hdc;
201     int wmId, wmEvent;
202     int x, y;
203     PAINTSTRUCT ps;
204
205     switch( message )
206     {
207         case WM_LBUTTONDOWN:
208             x = LOWORD(lParam);
209             y = HIWORD(lParam);
210             hdc = GetDC(hWnd);
211             Rectangle(hdc, x-4, y-4, x+4, y+4);
212             ReleaseDC(hWnd, hdc);
213             break;
214         case WM_COMMAND:
215             wmId    = LOWORD(wParam);
216             wmEvent = HIWORD(wParam);
217             // Parse the menu selections:
218             switch( wmId )
219             {
220                 case IDM_HELP_ABOUT:
221                    DialogBox( hInst, (LPCTSTR)IDD_ABOUTBOX,
222                               hWnd, (DLGPROC)About );
223                    break;
224                 case IDM_PLOP:
225                    /* Do random stuff */
226                    break;
227                 case IDM_FILE_EXIT:
228                    DestroyWindow(hWnd);
229                    break;
230                 default:
231                    return DefWindowProc( hWnd, message, wParam, lParam );
232             }
233             break;
234         case WM_CREATE:
235             hwndCB = CommandBar_Create(hInst, hWnd, 1);
236             CommandBar_InsertMenubar(hwndCB, hInst, IDM_MENU, 0);
237             //CommandBar_AddAdornments(hwndCB, 0, 0);
238             break;
239         case WM_PAINT:
240         {
241             RECT rt;
242             hdc = BeginPaint(hWnd, &ps);
243             GetClientRect(hWnd, &rt);
244             DrawText( hdc, L"VLC roulaize!", _tcslen(L"VLC roulaize!"), &rt,
245                       DT_SINGLELINE | DT_VCENTER | DT_CENTER );
246             EndPaint(hWnd, &ps);
247             break;
248         }
249         case WM_DESTROY:
250             CommandBar_Destroy(hwndCB);
251             PostQuitMessage(0);
252             break;
253         default:
254             return DefWindowProc(hWnd, message, wParam, lParam);
255    }
256    return 0;
257 }
258