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