2 * MPlayer GUI for Win32
3 * Copyright (C) 2003 Sascha Sommer <saschasommer@freenet.de>
4 * Copyright (C) 2006 Erik Augustson <erik_27can@yahoo.com>
5 * Copyright (C) 2006 Gianluigi Tiesi <sherpya@netfarm.it>
7 * This file is part of MPlayer.
9 * MPlayer 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.
14 * MPlayer 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.
19 * You should have received a copy of the GNU General Public License along
20 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
37 #include "input/input.h"
38 #include "input/mouse.h"
39 #include "osdep/keycodes.h"
40 #include "stream/stream.h"
41 #include "libvo/video_out.h"
42 #include "gui/interface.h"
46 // HACK around bug in old mingw
47 #undef INVALID_FILE_ATTRIBUTES
48 #define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
50 #ifndef WM_XBUTTONDOWN
51 # define WM_XBUTTONDOWN 0x020B
52 # define WM_XBUTTONUP 0x020C
53 # define WM_XBUTTONDBLCLK 0x020D
56 /* Globals / Externs */
57 void renderinfobox(skin_t
*skin
, window_priv_t
*priv
);
58 void renderwidget(skin_t
*skin
, image
*dest
, widget
*item
, int state
);
59 void print_version(void);
64 int console_state
= 0;
65 play_tree_t
*playtree
= NULL
;
67 static HBRUSH colorbrush
= NULL
; //Handle to colorkey brush
68 static COLORREF windowcolor
= RGB(255,0,255); //Windowcolor == colorkey
70 void console_toggle(void)
80 /* This code comes from: http://dslweb.nwnexus.com/~ast/dload/guicon.htm */
81 CONSOLE_SCREEN_BUFFER_INFO coninfo
;
86 SetConsoleTitle(MP_TITLE
);
88 /* disable the close button for now */
91 hwnd
= FindWindow(NULL
, MP_TITLE
);
94 DeleteMenu(GetSystemMenu(hwnd
, 0), SC_CLOSE
, MF_BYCOMMAND
);
96 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE
), &coninfo
);
97 coninfo
.dwSize
.Y
= 1000;
98 SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE
), coninfo
.dwSize
);
99 fp
= freopen("con", "w", stdout
);
101 setvbuf(stdout
, NULL
, _IONBF
, 0);
102 fp
= freopen("con", "r", stdin
);
104 setvbuf(stdin
, NULL
, _IONBF
, 0);
105 fp
= freopen("con", "w", stdout
);
107 setvbuf(stderr
, NULL
, _IONBF
, 0);
113 void capitalize(char *filename
)
117 for (i
=0; i
< strlen(filename
); i
++)
122 filename
[i
] = toupper(filename
[i
]);
124 else if (filename
[i
] == ' ')
127 filename
[i
] = tolower(filename
[i
]);
131 static image
*get_drawground(HWND hwnd
)
133 gui_t
* gui
= (gui_t
*) GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
135 if(!gui
) return NULL
;
136 for(i
=0; i
<gui
->window_priv_count
; i
++)
137 if(gui
->window_priv
[i
]->hwnd
==hwnd
)
138 return &gui
->window_priv
[i
]->img
;
142 static HBITMAP
get_bitmap(HWND hwnd
)
144 gui_t
*gui
= (gui_t
*) GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
146 if(!gui
) return NULL
;
147 for(i
=0; i
<gui
->window_priv_count
; i
++)
148 if(gui
->window_priv
[i
]->hwnd
== hwnd
)
149 return gui
->window_priv
[i
]->bitmap
;
153 static int get_windowtype(HWND hwnd
)
155 gui_t
*gui
= (gui_t
*) GetWindowLongPtr(hwnd
, GWLP_USERDATA
);
158 for(i
=0; i
<gui
->window_priv_count
; i
++)
159 if(gui
->window_priv
[i
]->hwnd
== hwnd
)
160 return gui
->window_priv
[i
]->type
;
164 static void uninit(gui_t
*gui
)
166 if(gui
->skin
) destroy_window(gui
);
167 if(gui
->playlist
) gui
->playlist
->free_playlist(gui
->playlist
);
168 gui
->playlist
= NULL
;
172 the gui message handler
173 tries to handle the incoming messages
174 and passes them to the player's message handler if it can't handle them
176 static void handlemsg(HWND hWnd
, int msg
)
178 gui_t
*gui
= (gui_t
*) GetWindowLongPtr(hWnd
, GWLP_USERDATA
);
179 if(msg
== evNone
) return;
185 if(display_openfilewindow(gui
, 0) && (msg
== evLoadPlay
))
186 handlemsg(hWnd
, evDropFile
);
189 display_opensubtitlewindow(gui
);
192 display_prefswindow(gui
);
195 display_playlistwindow(gui
);
198 display_skinbrowser(gui
);
201 display_eqwindow(gui
);
204 MessageBox(hWnd
, COPYRIGHT
, "About", MB_OK
);
207 ShowWindow(hWnd
, SW_MINIMIZE
);
210 mplayer_put_key(KEY_VOLUME_UP
);
213 mplayer_put_key(KEY_VOLUME_DOWN
);
216 mp_msg(MSGT_GPLAYER
, MSGL_V
, "[GUI] received msg %s (%i)\n", gui
->skin
->geteventname(msg
), msg
);
219 gui
->playercontrol(msg
);
222 static widget
*clickedinsidewidget(gui_t
*gui
, int window
, int x
, int y
)
226 for(i
=0; i
<gui
->skin
->widgetcount
; i
++)
228 item
= gui
->skin
->widgets
[i
];
229 if((item
->window
== window
) && (item
->x
<= x
) && (item
->x
+ item
->width
>= x
) &&
230 (item
->y
<= y
) && (item
->y
+ item
->height
>= y
))
236 /* updates sliders and the display */
237 static void updatedisplay(gui_t
*gui
, HWND hwnd
)
240 window_priv_t
*priv
= NULL
;
241 DWORD time
= timeGetTime();
245 /* load all potmeters hpotmeters */
246 for(i
=0; i
<gui
->skin
->widgetcount
; i
++)
248 if(gui
->skin
->widgets
[i
]->type
== tyHpotmeter
|| gui
->skin
->widgets
[i
]->type
== tyPotmeter
)
250 if(gui
->skin
->widgets
[i
]->msg
== evSetVolume
)
251 gui
->skin
->widgets
[i
]->value
= guiIntfStruct
.Volume
;
252 else if(gui
->skin
->widgets
[i
]->msg
== evSetMoviePosition
)
253 gui
->skin
->widgets
[i
]->value
= guiIntfStruct
.Position
;
254 else if(gui
->skin
->widgets
[i
]->msg
== evSetBalance
)
255 gui
->skin
->widgets
[i
]->value
= guiIntfStruct
.Balance
;
256 if(gui
->skin
->widgets
[i
]->window
== get_windowtype(hwnd
))
257 renderwidget(gui
->skin
, get_drawground(hwnd
), gui
->skin
->widgets
[i
],
258 gui
->skin
->widgets
[i
]->pressed
? 0 : 1);
260 /* update some buttons */
261 if(gui
->skin
->widgets
[i
]->type
== tyButton
&& gui
->skin
->widgets
[i
]->window
== get_windowtype(hwnd
))
263 if(gui
->skin
->widgets
[i
]->msg
== evPlaySwitchToPause
)
265 gui
->skin
->widgets
[i
]->value
= guiIntfStruct
.Playing
;
266 renderwidget(gui
->skin
, get_drawground(hwnd
), gui
->skin
->widgets
[i
],
267 guiIntfStruct
.Playing
== 1 ? 0 : 1);
269 if(gui
->skin
->widgets
[i
]->msg
== evMute
)
271 gui
->skin
->widgets
[i
]->value
= guiIntfStruct
.Volume
;
272 renderwidget(gui
->skin
, get_drawground(hwnd
), gui
->skin
->widgets
[i
],
273 guiIntfStruct
.Volume
== 0.0f
? 0 : 1);
278 /* updating the display once a 100.second is enough imo */
279 if((time
- oldtime
) < 100) return;
282 /* suppress directx's fullscreen window when using the sub window */
283 if(sub_window
&& &video_driver_list
[0] && strstr("directx", video_driver_list
[0]))
285 HWND hWndFS
= NULL
; //handle to directx's fullscreen window
288 hWndFS
= FindWindow(NULL
, "MPlayer Fullscreen");
289 if(hWndFS
!= NULL
) DestroyWindow(hWndFS
); //sub window handles fullscreen
293 for (i
=0; i
<gui
->window_priv_count
; i
++)
295 if(gui
->window_priv
[i
]->hwnd
== hwnd
)
296 priv
=gui
->window_priv
[i
];
298 /* display the status msgs */
299 renderinfobox(gui
->skin
, priv
);
300 RedrawWindow(hwnd
, NULL
, NULL
, RDW_INVALIDATE
);
303 static LRESULT CALLBACK
SubProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
305 gui_t
*gui
= (gui_t
*) GetWindowLongPtr(hWnd
, GWLP_USERDATA
);
306 if (gui
&& (gui
->subwindow
!= hWnd
)) return FALSE
;
311 handlemsg(hWnd
, evExit
);
321 mplayer_put_key(KEY_LEFT
);
324 mplayer_put_key(KEY_UP
);
327 mplayer_put_key(KEY_RIGHT
);
330 mplayer_put_key(KEY_DOWN
);
333 mplayer_put_key(KEY_TAB
);
336 mplayer_put_key(KEY_BS
);
339 mplayer_put_key(KEY_DELETE
);
342 mplayer_put_key(KEY_INSERT
);
345 mplayer_put_key(KEY_HOME
);
348 mplayer_put_key(KEY_END
);
351 mplayer_put_key(KEY_PAGE_UP
);
354 mplayer_put_key(KEY_PAGE_DOWN
);
357 mplayer_put_key(KEY_ESC
);
364 switch(LOWORD(wParam
))
368 handlemsg(hWnd
, evExit
);
371 handlemsg(hWnd
, evLoadPlay
);
374 display_openurlwindow(gui
, 0);
378 static char path
[MAX_PATH
];
381 memset(&bi
, 0, sizeof(BROWSEINFO
));
382 bi
.lpszTitle
= "Choose a Directory...";
383 pidl
= SHBrowseForFolder(&bi
);
384 if (SHGetPathFromIDList(pidl
, path
))
386 gui
->playlist
->clear_playlist(gui
->playlist
);
387 adddirtoplaylist(gui
->playlist
, path
, TRUE
);
393 handlemsg(hWnd
, evPrev
);
396 handlemsg(hWnd
, evBackward10sec
);
399 handlemsg(hWnd
, evPlaySwitchToPause
);
402 handlemsg(hWnd
, evStop
);
405 handlemsg(hWnd
, evForward10sec
);
408 handlemsg(hWnd
, evNext
);
410 #ifdef CONFIG_DVDREAD
412 display_chapterselwindow(gui
);
416 mp_input_queue_cmd(mp_input_parse_cmd("vo_fullscreen"));
419 mp_input_queue_cmd(mp_input_parse_cmd("mute"));
422 mp_input_queue_cmd(mp_input_parse_cmd("switch_ratio 1.777777"));
425 mp_input_queue_cmd(mp_input_parse_cmd("switch_ratio 1.333333"));
428 mp_input_queue_cmd(mp_input_parse_cmd("switch_ratio 2.35"));
431 mp_input_queue_cmd(mp_input_parse_cmd("switch_ratio 0"));
434 mp_input_queue_cmd(mp_input_parse_cmd("sub_visibility"));
437 mp_input_queue_cmd(mp_input_parse_cmd("sub_select"));
443 mplayer_put_key(wParam
);
450 int filecount
= DragQueryFile((HDROP
) wParam
, -1, file
, MAX_PATH
);
452 for(i
=0; i
<filecount
; i
++)
454 DragQueryFile((HDROP
) wParam
, i
, file
, MAX_PATH
);
455 mplSetFileName(NULL
, file
, STREAMTYPE_FILE
);
456 if(!parse_filename(file
, playtree
, mconfig
, 1))
457 gui
->playlist
->add_track(gui
->playlist
, file
, NULL
, NULL
, 0);
459 DragFinish((HDROP
) wParam
);
460 handlemsg(hWnd
, evDropFile
);
464 gui
->playlist
->clear_playlist(gui
->playlist
);
465 gui
->playlist
->add_track(gui
->playlist
, (const char *) wParam
, NULL
, NULL
, 0);
466 handlemsg(hWnd
, evDropFile
);
468 SetForegroundWindow(gui
->subwindow
);
473 if(!vo_nomouse_input
)
474 mplayer_put_key(MOUSE_BTN0
);
479 if(!vo_nomouse_input
)
480 mplayer_put_key(MOUSE_BTN1
);
486 point
.x
= GET_X_LPARAM(lParam
);
487 point
.y
= GET_Y_LPARAM(lParam
);
488 ClientToScreen(hWnd
, &point
);
489 if(guiIntfStruct
.StreamType
== STREAMTYPE_DVD
)
490 EnableMenuItem(gui
->dvdmenu
, ID_CHAPTERSEL
, MF_BYCOMMAND
| MF_ENABLED
);
491 TrackPopupMenu(gui
->submenu
, 0, point
.x
, point
.y
, 0, hWnd
, NULL
);
494 case WM_LBUTTONDBLCLK
:
496 if(!vo_nomouse_input
)
497 mplayer_put_key(MOUSE_BTN0_DBL
);
500 case WM_MBUTTONDBLCLK
:
502 if(!vo_nomouse_input
)
503 mplayer_put_key(MOUSE_BTN1_DBL
);
506 case WM_RBUTTONDBLCLK
:
508 if(!vo_nomouse_input
)
509 mplayer_put_key(MOUSE_BTN2_DBL
);
514 int x
= GET_WHEEL_DELTA_WPARAM(wParam
);
518 mplayer_put_key(MOUSE_BTN3
);
520 mplayer_put_key(MOUSE_BTN4
);
527 if(HIWORD(wParam
) == 1)
528 mplayer_put_key(MOUSE_BTN5
);
530 mplayer_put_key(MOUSE_BTN6
);
533 case WM_XBUTTONDBLCLK
:
537 if(HIWORD(wParam
) == 1)
538 mplayer_put_key(MOUSE_BTN5_DBL
);
540 mplayer_put_key(MOUSE_BTN6_DBL
);
545 if(fullscreen
) while(ShowCursor(FALSE
) >= 0){}
546 KillTimer(hWnd
, ID_TIMER
);
552 SetTimer(hWnd
, ID_TIMER
, 3000, (TIMERPROC
) NULL
);
555 case WM_WINDOWPOSCHANGED
:
558 static uint32_t rect_width
;
559 static uint32_t rect_height
;
564 GetClientRect(hWnd
, &rd
);
565 ClientToScreen(hWnd
, &pt
);
567 rect_width
= rd
.right
- rd
.left
;
568 rect_height
= rd
.bottom
- rd
.top
;
570 /* maintain our aspect ratio */
571 tmpheight
= ((float)rect_width
/sub_aspect
);
572 tmpheight
+= tmpheight
% 2;
573 if(tmpheight
> rect_height
)
575 rect_width
= ((float)rect_height
*sub_aspect
);
576 rect_width
+= rect_width
% 2;
578 else rect_height
= tmpheight
;
580 rd
.right
= rd
.left
+ rect_width
;
581 rd
.bottom
= rd
.top
+ rect_height
;
583 AdjustWindowRect(&rd
, WS_OVERLAPPEDWINDOW
| WS_SIZEBOX
, 0);
584 SetWindowPos(hWnd
, 0, fullscreen
?0:pt
.x
+rd
.left
, fullscreen
?0:pt
.y
+rd
.top
,
585 fullscreen
?vo_screenwidth
:rd
.right
-rd
.left
, fullscreen
?vo_screenheight
:rd
.bottom
-rd
.top
, SWP_NOOWNERZORDER
);
586 SetForegroundWindow(hWnd
);
594 case SC_MONITORPOWER
:
595 mp_msg(MSGT_VO
, MSGL_V
,"<vo_directx><INFO>killing screensaver\n" );
604 HDC hdc
= BeginPaint(hWnd
, &ps
);
605 HDC hMemDC
= CreateCompatibleDC(hdc
);
606 HBRUSH blackbrush
= (HBRUSH
)GetStockObject(BLACK_BRUSH
);
608 GetClientRect(hWnd
, &rect
);
609 width
= rect
.right
- rect
.left
;
610 height
= rect
.bottom
- rect
.top
;
611 if(guiIntfStruct
.Playing
== 0)
616 for (i
=0; i
<gui
->skin
->windowcount
; i
++)
617 if(gui
->skin
->windows
[i
]->type
== wiSub
)
618 desc
= gui
->skin
->windows
[i
];
620 SelectObject(hMemDC
, get_bitmap(hWnd
));
621 StretchBlt(hdc
, 0, 0, width
, height
, hMemDC
, 0, 0, desc
->base
->bitmap
[0]->width
,
622 desc
->base
->bitmap
[0]->height
, SRCCOPY
);
624 FillRect(GetDC(hWnd
), &rect
, fullscreen
?blackbrush
:colorbrush
);
631 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
634 /* Window Proc for the gui Window */
635 static LRESULT CALLBACK
EventProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
637 gui_t
*gui
= (gui_t
*) GetWindowLongPtr(hWnd
, GWLP_USERDATA
);
639 /* Avoid processing when then window doesn't match gui mainwindow */
640 if (gui
&& (gui
->mainwindow
!= hWnd
)) return FALSE
;
645 handlemsg(hWnd
, evExit
);
657 GetCursorPos(&cursor
);
658 SetForegroundWindow(hWnd
);
659 TrackPopupMenu(gui
->traymenu
, 0, cursor
.x
, cursor
.y
, 0, hWnd
, NULL
);
662 case WM_MBUTTONDBLCLK
:
663 case WM_LBUTTONDBLCLK
:
665 if(IsWindowVisible(hWnd
)) ShowWindow(hWnd
, SW_HIDE
);
666 else { ShowWindow(hWnd
, SW_SHOW
); SetForegroundWindow(hWnd
); }
677 mplayer_put_key(KEY_LEFT
);
680 mplayer_put_key(KEY_UP
);
683 mplayer_put_key(KEY_RIGHT
);
686 mplayer_put_key(KEY_DOWN
);
689 mplayer_put_key(KEY_TAB
);
692 mplayer_put_key(KEY_BS
);
695 mplayer_put_key(KEY_DELETE
);
698 mplayer_put_key(KEY_INSERT
);
701 mplayer_put_key(KEY_HOME
);
704 mplayer_put_key(KEY_END
);
707 mplayer_put_key(KEY_PAGE_UP
);
710 mplayer_put_key(KEY_PAGE_DOWN
);
713 mplayer_put_key(KEY_ESC
);
719 mplayer_put_key(wParam
);
725 PCOPYDATASTRUCT cdData
;
726 cdData
= (PCOPYDATASTRUCT
) lParam
;
727 mplSetFileName(NULL
, cdData
->lpData
, STREAMTYPE_FILE
);
728 if(!parse_filename(cdData
->lpData
, playtree
, mconfig
, 1))
729 gui
->playlist
->add_track(gui
->playlist
, cdData
->lpData
, NULL
, NULL
, 0);
739 int filecount
= DragQueryFile((HDROP
) wParam
, -1, file
, MAX_PATH
);
741 for(i
=0; i
<filecount
; i
++)
743 DragQueryFile((HDROP
) wParam
, i
, file
, MAX_PATH
);
744 mplSetFileName(NULL
, file
, STREAMTYPE_FILE
);
745 if(!parse_filename(file
, playtree
, mconfig
, 1))
746 gui
->playlist
->add_track(gui
->playlist
, file
, NULL
, NULL
, 0);
748 DragFinish((HDROP
) wParam
);
749 handlemsg(hWnd
, evDropFile
);
753 gui
->playlist
->clear_playlist(gui
->playlist
);
754 gui
->playlist
->add_track(gui
->playlist
, (const char *) wParam
, NULL
, NULL
, 0);
755 handlemsg(hWnd
, evDropFile
);
757 SetForegroundWindow(gui
->mainwindow
);
763 gui
->mousex
= GET_X_LPARAM(lParam
);
764 gui
->mousey
= GET_Y_LPARAM(lParam
);
765 /* inside a widget */
766 gui
->activewidget
= clickedinsidewidget(gui
, get_windowtype(hWnd
), gui
->mousex
, gui
->mousey
);
767 if(gui
->activewidget
)
769 gui
->activewidget
->pressed
= 1;
770 gui
->mousewx
= gui
->mousex
- gui
->activewidget
->x
;
771 gui
->mousewy
= gui
->mousey
- gui
->activewidget
->y
;
772 renderwidget(gui
->skin
, get_drawground(hWnd
), gui
->activewidget
, 0);
773 RedrawWindow(hWnd
, NULL
, NULL
, RDW_INVALIDATE
);
774 handlemsg(hWnd
, gui
->activewidget
->msg
);
778 case WM_CAPTURECHANGED
:
780 if(gui
->activewidget
)
782 gui
->activewidget
->pressed
= 0;
783 renderwidget(gui
->skin
, get_drawground(hWnd
), gui
->activewidget
, 1);
784 RedrawWindow(hWnd
, NULL
, NULL
, RDW_INVALIDATE
);
785 gui
->activewidget
= NULL
;
792 if(gui
->activewidget
)
794 gui
->activewidget
->pressed
= 0;
795 renderwidget(gui
->skin
, get_drawground(hWnd
), gui
->activewidget
, 1);
796 RedrawWindow(hWnd
, NULL
, NULL
, RDW_INVALIDATE
);
797 gui
->activewidget
= NULL
;
804 char device
[MAX_PATH
];
805 char searchpath
[MAX_PATH
];
806 char searchpath2
[MAX_PATH
];
807 #ifdef CONFIG_LIBCDIO
808 char searchpath3
[MAX_PATH
];
810 int len
, pos
= 0, cdromdrive
= 0;
812 point
.x
= GET_X_LPARAM(lParam
);
813 point
.y
= GET_Y_LPARAM(lParam
);
814 ClientToScreen(hWnd
, &point
);
815 errmode
= SetErrorMode(SEM_FAILCRITICALERRORS
| SEM_NOOPENFILEERRORBOX
);
816 while (GetMenuItemCount(gui
->diskmenu
) > 0)
817 DeleteMenu(gui
->diskmenu
, 0, MF_BYPOSITION
);
818 len
= GetLogicalDriveStrings(MAX_PATH
, device
);
821 if(GetDriveType(device
+ pos
) == DRIVE_CDROM
)
823 char volname
[MAX_PATH
];
824 char menuitem
[MAX_PATH
];
825 int flags
= MF_STRING
;
826 mp_msg(MSGT_GPLAYER
, MSGL_V
, "[GUI] checking %s for CD/VCD/SVCD/DVDs\n", device
+ pos
);
827 sprintf(searchpath
, "%sVIDEO_TS", device
+ pos
);
828 sprintf(searchpath2
, "%sMpegav", device
+ pos
);
829 #ifdef CONFIG_LIBCDIO
830 sprintf(searchpath3
, "%sTrack01.cda", device
+ pos
);
832 if(GetFileAttributes(searchpath
) != INVALID_FILE_ATTRIBUTES
)
834 else if(GetFileAttributes(searchpath2
) != INVALID_FILE_ATTRIBUTES
)
836 #ifdef CONFIG_LIBCDIO
837 else if(GetFileAttributes(searchpath3
) != INVALID_FILE_ATTRIBUTES
)
843 strcpy(menuitem
, device
+ pos
);
844 menuitem
[strlen(menuitem
) - 1]=0;
845 GetVolumeInformation(device
+ pos
, volname
, MAX_PATH
, NULL
, NULL
, NULL
, NULL
, 0);
849 strcat(menuitem
, " - ");
850 strcat(menuitem
, volname
);
852 AppendMenu(gui
->diskmenu
, flags
, IDPLAYDISK
+ cdromdrive
, menuitem
);
855 pos
+= strlen(device
+ pos
) + 1;
857 SetErrorMode(errmode
);
858 TrackPopupMenu(gui
->menu
, 0, point
.x
, point
.y
, 0, hWnd
, NULL
);
863 if(wParam
& MK_LBUTTON
)
867 if(gui
->activewidget
)
869 widget
*item
= gui
->activewidget
;
871 if(item
->type
== tyHpotmeter
)
873 item
->x
= GET_X_LPARAM(lParam
) - gui
->mousewx
;
874 item
->value
= (float)((float)((item
->x
- item
->wx
) * 100.0f
) / (float)(item
->wwidth
- item
->width
));
876 if(item
->type
== tyPotmeter
)
878 gui
->mousewx
= GET_X_LPARAM(lParam
) - gui
->activewidget
->x
;
879 item
->value
= (float) (gui
->mousewx
* 100.0f
) / (float) item
->wwidth
;
882 if((item
->type
== tyPotmeter
) || (item
->type
== tyHpotmeter
) || (item
->type
== tyVpotmeter
))
885 if(item
->value
> 100.0f
)
886 item
->value
= 100.0f
;
887 else if(item
->value
< 0.0f
)
890 if(item
->msg
== evSetVolume
)
891 guiIntfStruct
.Volume
= (float) item
->value
;
892 else if(item
->msg
== evSetMoviePosition
)
893 guiIntfStruct
.Position
= (float) item
->value
;
894 else if(item
->msg
== evSetBalance
)
896 /* make the range for 50% a bit bigger, because the sliders for balance usually suck */
897 if((item
->value
- 50.0f
< 1.5f
) && (item
->value
- 50.0f
> -1.5f
))
899 guiIntfStruct
.Balance
= (float) item
->value
;
901 updatedisplay(gui
, hWnd
);
902 handlemsg(hWnd
, item
->msg
);
906 point
.x
= GET_X_LPARAM(lParam
);
907 point
.y
= GET_Y_LPARAM(lParam
);
908 ClientToScreen(hWnd
, &point
);
909 GetWindowRect(hWnd
, &rect
);
910 MoveWindow(hWnd
, point
.x
- gui
->mousex
, point
.y
- gui
->mousey
,
911 rect
.right
-rect
.left
,rect
.bottom
-rect
.top
,TRUE
);
918 switch(LOWORD(wParam
))
922 handlemsg(hWnd
, evExit
);
925 handlemsg(hWnd
, evLoadPlay
);
929 static char path
[MAX_PATH
];
932 memset(&bi
, 0, sizeof(BROWSEINFO
));
933 bi
.lpszTitle
= "Choose a Directory...";
934 pidl
= SHBrowseForFolder(&bi
);
935 if (SHGetPathFromIDList(pidl
, path
))
937 gui
->playlist
->clear_playlist(gui
->playlist
);
938 adddirtoplaylist(gui
->playlist
, path
, TRUE
);
944 handlemsg(hWnd
, evSkinBrowser
);
947 display_openurlwindow(gui
, 0);
950 mp_input_queue_cmd(mp_input_parse_cmd("mute"));
952 case IDSUBTITLE_OPEN
:
953 display_opensubtitlewindow(gui
);
956 handlemsg(hWnd
, evPrev
);
959 handlemsg(hWnd
, evBackward10sec
);
962 handlemsg(hWnd
, evPlaySwitchToPause
);
965 handlemsg(hWnd
, evStop
);
968 handlemsg(hWnd
, evForward10sec
);
971 handlemsg(hWnd
, evNext
);
975 if(IsWindowVisible(hWnd
)) ShowWindow(hWnd
, SW_HIDE
);
976 else ShowWindow(hWnd
, SW_SHOW
);
980 handlemsg(hWnd
, evPlayList
);
983 handlemsg(hWnd
, evPreferences
);
989 ShellExecute(NULL
, "open", ONLINE_HELP_URL
, NULL
, NULL
, SW_SHOWNORMAL
);
992 if((IDPLAYDISK
<= LOWORD(wParam
)) && (LOWORD(wParam
) < (IDPLAYDISK
+ 100)))
994 char device
[MAX_PATH
];
995 char searchpath
[MAX_PATH
];
996 char filename
[MAX_PATH
];
997 int len
, pos
= 0, cdromdrive
= 0;
998 len
= GetLogicalDriveStrings(MAX_PATH
, device
);
1001 if(GetDriveType(device
+ pos
)==DRIVE_CDROM
)
1003 if(LOWORD(wParam
) - IDPLAYDISK
== cdromdrive
)
1005 sprintf(searchpath
, "%sVIDEO_TS", device
+ pos
);
1006 if(GetFileAttributes(searchpath
) != INVALID_FILE_ATTRIBUTES
)
1008 #ifdef CONFIG_DVDREAD
1009 if (dvd_device
) free(dvd_device
);
1010 dvd_device
= strdup(device
+ pos
);
1011 dvd_title
= dvd_chapter
= dvd_angle
= 1;
1012 handlemsg(hWnd
, evPlayDVD
);
1015 sprintf(searchpath
, "%sTrack01.cda", device
+ pos
);
1016 if(GetFileAttributes(searchpath
) != INVALID_FILE_ATTRIBUTES
)
1018 #ifdef CONFIG_LIBCDIO
1019 if (cdrom_device
) free(cdrom_device
);
1020 cdrom_device
= strdup(device
+ pos
);
1021 /* mplayer doesn't seem to like the trailing \ after the device name */
1023 handlemsg(hWnd
, evPlayCD
);
1027 WIN32_FIND_DATA finddata
;
1028 sprintf(searchpath
, "%smpegav\\*.dat", device
+ pos
);
1029 if((searchhndl
=FindFirstFile(searchpath
, &finddata
)) != INVALID_HANDLE_VALUE
)
1031 mp_msg(MSGT_GPLAYER
,MSGL_V
, "Opening VCD/SVCD\n");
1032 gui
->playlist
->clear_playlist(gui
->playlist
);
1035 sprintf(filename
, "%smpegav\\%s", device
+ pos
, finddata
.cFileName
);
1036 gui
->playlist
->add_track(gui
->playlist
, filename
, NULL
, NULL
, 0);
1038 while(FindNextFile(searchhndl
, &finddata
));
1039 FindClose(searchhndl
);
1041 gui
->startplay(gui
);
1046 pos
+= strlen(device
+ pos
) + 1;
1055 HDC hdc
= BeginPaint(hWnd
, &ps
);
1056 HDC hMemDC
= CreateCompatibleDC(hdc
);
1058 GetClientRect(hWnd
, &rd
);
1059 width
= rd
.right
- rd
.left
;
1060 height
= rd
.bottom
- rd
.top
;
1061 SelectObject(hMemDC
, get_bitmap(hWnd
));
1062 BitBlt(hdc
, 0, 0, width
, height
, hMemDC
, 0, 0, SRCCOPY
);
1064 EndPaint(hWnd
, &ps
);
1069 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
1072 static void startplay(gui_t
*gui
)
1074 handlemsg(gui
->mainwindow
, evDropFile
);
1077 /* returns the bits per pixel of the desktop */
1078 /* the format is always in BGR byte order */
1079 static int GetDesktopBitsPerPixel(void)
1081 HWND desktop
=GetDesktopWindow();
1082 HDC dc
=GetDC(desktop
);
1083 int bpp
=GetDeviceCaps(dc
, BITSPIXEL
);
1084 ReleaseDC(desktop
, dc
);
1088 /* unloads a skin and destroys its windows */
1089 int destroy_window(gui_t
*gui
)
1094 /* Save position: MSDN says don't pass workspace coordinates
1095 * to CreateWindow() or SetWindowPos(), as both of which expect
1096 * screen coordinates; resulting in the window appearing in the
1101 /* main window position */
1102 if(IsIconic(gui
->mainwindow
))
1103 ShowWindow(gui
->mainwindow
, SW_SHOWNORMAL
);
1104 GetWindowRect(gui
->mainwindow
, &rd
);
1105 gui_main_pos_x
= rd
.left
;
1106 gui_main_pos_y
= rd
.top
;
1108 /* sub window position */
1109 if(IsIconic(gui
->subwindow
))
1110 ShowWindow(gui
->subwindow
, SW_SHOWNORMAL
);
1111 GetWindowRect(gui
->subwindow
, &rd
);
1112 gui_sub_pos_x
= rd
.left
;
1113 gui_sub_pos_y
= rd
.top
;
1115 for(i
=0; i
<gui
->window_priv_count
; i
++)
1117 if(gui
->window_priv
[i
]->bitmap
)
1118 DeleteObject(gui
->window_priv
[i
]->bitmap
);
1119 free(gui
->window_priv
[i
]);
1121 free(gui
->window_priv
);
1122 gui
->window_priv
= NULL
;
1123 gui
->window_priv_count
= 0;
1125 /* destroy the main window */
1127 DestroyWindow(gui
->mainwindow
);
1128 gui
->mainwindow
= NULL
;
1130 /* destroy the sub window */
1132 DestroyWindow(gui
->subwindow
);
1133 gui
->subwindow
= NULL
;
1135 UnregisterClass(gui
->classname
, 0);
1136 DestroyIcon(gui
->icon
);
1138 gui
->skin
->freeskin(gui
->skin
);
1143 static void create_menu(gui_t
*gui
)
1145 gui
->diskmenu
= CreatePopupMenu();
1146 gui
->menu
=CreatePopupMenu();
1147 gui
->trayplaymenu
= CreatePopupMenu();
1148 AppendMenu(gui
->menu
, MF_STRING
| MF_POPUP
, (UINT
) gui
->trayplaymenu
, "Open...");
1149 AppendMenu(gui
->trayplaymenu
, MF_STRING
, IDFILE_OPEN
, "File...");
1150 AppendMenu(gui
->trayplaymenu
, MF_STRING
, IDURL_OPEN
, "Url...");
1151 AppendMenu(gui
->trayplaymenu
, MF_STRING
, IDDIR_OPEN
, "Directory...");
1152 AppendMenu(gui
->menu
, MF_SEPARATOR
, 0, 0);
1153 AppendMenu(gui
->menu
, MF_STRING
| MF_POPUP
, (UINT
) gui
->diskmenu
, "Play &CD/DVD/VCD/SVCD");
1154 AppendMenu(gui
->menu
, MF_SEPARATOR
, 0, 0);
1155 AppendMenu(gui
->menu
, MF_STRING
, IDSUBTITLE_OPEN
, "Open Subtitle");
1156 AppendMenu(gui
->menu
, MF_STRING
, ID_SKINBROWSER
, "Skin Browser");
1157 AppendMenu(gui
->menu
, MF_SEPARATOR
, 0, 0);
1158 AppendMenu(gui
->menu
, MF_STRING
, ID_PREFS
, "Preferences");
1159 AppendMenu(gui
->menu
, MF_STRING
, ID_CONSOLE
, "Debug Console");
1160 AppendMenu(gui
->menu
, MF_STRING
, ID_ONLINEHELP
, "Online Help");
1161 AppendMenu(gui
->menu
, MF_SEPARATOR
, 0, 0);
1162 AppendMenu(gui
->menu
, MF_STRING
, IDEXIT
, "&Exit");
1165 static void create_traymenu(gui_t
*gui
)
1167 gui
->traymenu
= CreatePopupMenu();
1168 gui
->trayplaybackmenu
= CreatePopupMenu();
1169 AppendMenu(gui
->traymenu
, MF_STRING
| MF_POPUP
, (UINT
) gui
->trayplaymenu
, "Open...");
1170 AppendMenu(gui
->traymenu
, MF_SEPARATOR
, 0, 0);
1171 AppendMenu(gui
->traymenu
, MF_STRING
| MF_POPUP
, (UINT
) gui
->trayplaybackmenu
, "Playback");
1172 AppendMenu(gui
->trayplaybackmenu
, MF_STRING
, ID_SEEKB
, "Seek Backwards");
1173 AppendMenu(gui
->trayplaybackmenu
, MF_STRING
, ID_PTRACK
, "Previous Track");
1174 AppendMenu(gui
->trayplaybackmenu
, MF_STRING
, ID_PLAY
, "Play/Pause");
1175 AppendMenu(gui
->trayplaybackmenu
, MF_STRING
, ID_STOP
, "Stop");
1176 AppendMenu(gui
->trayplaybackmenu
, MF_STRING
, ID_NTRACK
, "Next Track");
1177 AppendMenu(gui
->trayplaybackmenu
, MF_STRING
, ID_SEEKF
, "Seek Forwards");
1178 AppendMenu(gui
->traymenu
, MF_SEPARATOR
, 0, 0);
1179 AppendMenu(gui
->traymenu
, MF_STRING
, ID_MUTE
, "Toggle Mute");
1180 AppendMenu(gui
->traymenu
, MF_SEPARATOR
, 0, 0);
1181 AppendMenu(gui
->traymenu
, MF_STRING
, IDSUBTITLE_OPEN
, "Open Subtitle");
1182 AppendMenu(gui
->traymenu
, MF_STRING
, ID_PLAYLIST
, "Playlist");
1183 AppendMenu(gui
->traymenu
, MF_SEPARATOR
, 0, 0);
1184 AppendMenu(gui
->traymenu
, MF_STRING
, ID_SHOWHIDE
, "Show/Hide");
1185 AppendMenu(gui
->traymenu
, MF_SEPARATOR
, 0, 0);
1186 AppendMenu(gui
->traymenu
, MF_STRING
, ID_PREFS
, "Preferences");
1187 AppendMenu(gui
->traymenu
, MF_STRING
, ID_CONSOLE
, "Debug Console");
1188 AppendMenu(gui
->traymenu
, MF_STRING
, ID_ONLINEHELP
, "Online Help");
1189 AppendMenu(gui
->traymenu
, MF_SEPARATOR
, 0, 0);
1190 AppendMenu(gui
->traymenu
, MF_STRING
, IDEXIT
, "&Exit");
1193 static void create_submenu(gui_t
*gui
)
1195 gui
->submenu
= CreatePopupMenu();
1196 gui
->dvdmenu
= CreatePopupMenu();
1197 gui
->aspectmenu
= CreatePopupMenu();
1198 gui
->subtitlemenu
= CreatePopupMenu();
1199 AppendMenu(gui
->submenu
, MF_STRING
| MF_POPUP
, (UINT
) gui
->trayplaymenu
, "Open...");
1200 AppendMenu(gui
->submenu
, MF_SEPARATOR
, 0, 0);
1201 AppendMenu(gui
->submenu
, MF_STRING
, ID_SEEKB
, "Seek Backwards");
1202 AppendMenu(gui
->submenu
, MF_STRING
, ID_PTRACK
, "Previous Track");
1203 AppendMenu(gui
->submenu
, MF_STRING
, ID_PLAY
, "Play/Pause");
1204 AppendMenu(gui
->submenu
, MF_STRING
, ID_STOP
, "Stop");
1205 AppendMenu(gui
->submenu
, MF_STRING
, ID_NTRACK
, "Next Track");
1206 AppendMenu(gui
->submenu
, MF_STRING
, ID_SEEKF
, "Seek Forwards");
1207 AppendMenu(gui
->submenu
, MF_SEPARATOR
, 0, 0);
1208 AppendMenu(gui
->submenu
, MF_STRING
, ID_FULLSCREEN
, "Toggle Fullscreen");
1209 AppendMenu(gui
->submenu
, MF_STRING
, ID_MUTE
, "Toggle Mute");
1210 AppendMenu(gui
->submenu
, MF_SEPARATOR
, 0, 0);
1211 AppendMenu(gui
->submenu
, MF_STRING
| MF_POPUP
, (UINT
) gui
->aspectmenu
, "Aspect Ratio");
1212 AppendMenu(gui
->submenu
, MF_STRING
| MF_POPUP
, (UINT
) gui
->subtitlemenu
, "Subtitle Options");
1213 AppendMenu(gui
->submenu
, MF_STRING
| MF_POPUP
, (UINT
) gui
->dvdmenu
, "DVD Options");
1214 #ifdef CONFIG_DVDREAD
1215 AppendMenu(gui
->dvdmenu
, MF_STRING
| MF_GRAYED
, ID_CHAPTERSEL
, "Select Title/Chapter...");
1217 AppendMenu(gui
->subtitlemenu
, MF_STRING
, IDSUB_TOGGLE
, "Subtitle Visibility On/Off");
1218 AppendMenu(gui
->subtitlemenu
, MF_STRING
, IDSUB_CYCLE
, "Cycle Subtitle Languages");
1219 AppendMenu(gui
->aspectmenu
, MF_STRING
, ID_ASPECT1
, "Set 16:9");
1220 AppendMenu(gui
->aspectmenu
, MF_STRING
, ID_ASPECT2
, "Set 4:3");
1221 AppendMenu(gui
->aspectmenu
, MF_STRING
, ID_ASPECT3
, "Set 2.35");
1222 AppendMenu(gui
->aspectmenu
, MF_SEPARATOR
, 0, 0);
1223 AppendMenu(gui
->aspectmenu
, MF_STRING
, ID_ASPECT4
, "Original Aspect");
1224 AppendMenu(gui
->submenu
, MF_SEPARATOR
, 0, 0);
1225 AppendMenu(gui
->submenu
, MF_STRING
, IDEXIT
, "&Exit");
1228 static void maketransparent(HWND hwnd
, COLORREF crTransparent
)
1230 HDC mdc
= GetDC(hwnd
);
1232 HRGN crRgnres
, crRgn
, crRgnTmp
;
1233 int iX
= 0, iY
= 0, iLeftX
= 0;
1235 GetWindowRect(hwnd
, &rd
);
1236 width
= rd
.right
- rd
.left
;
1237 height
= rd
.bottom
- rd
.top
;
1239 /* create an empty region */
1240 crRgn
= CreateRectRgn(0, 0, 0, 0);
1242 /* Create a region from a bitmap with transparency colour of Purple */
1243 for (iY
= -1; iY
< height
; iY
++)
1247 /* skip over transparent pixels at start of lines */
1248 while (iX
<= width
&& GetPixel(mdc
,iX
, iY
) == crTransparent
) iX
++;
1250 /* remember this pixel */
1253 /* now find first non transparent pixel */
1254 while (iX
<= width
&& GetPixel(mdc
,iX
, iY
) != crTransparent
) ++iX
;
1256 /* create a temp region on this info */
1257 crRgnTmp
= CreateRectRgn(iLeftX
, iY
, iX
, iY
+1);
1259 /* combine into main region */
1261 CombineRgn(crRgnres
, crRgn
, crRgnTmp
, RGN_OR
);
1264 /* delete the temp region for next pass (otherwise you'll get an ASSERT) */
1265 DeleteObject(crRgnTmp
);
1266 } while (iX
< width
);
1269 SetWindowRgn(hwnd
, crRgn
, TRUE
);
1270 DeleteObject(crRgn
);
1271 ReleaseDC(hwnd
,mdc
);
1274 static int window_render(gui_t
*gui
, HWND hWnd
, HDC hdc
, window_priv_t
*priv
, window
*desc
, BITMAPINFO binfo
)
1277 SetWindowLongPtr(hWnd
, GWLP_USERDATA
, (DWORD
) gui
);
1278 (gui
->window_priv_count
)++;
1279 gui
->window_priv
= realloc(gui
->window_priv
, sizeof(window_priv_t
*) * gui
->window_priv_count
);
1280 priv
= gui
->window_priv
[gui
->window_priv_count
- 1] = calloc(1, sizeof(window_priv_t
));
1282 priv
->type
= desc
->type
;
1283 priv
->background
= desc
->base
->bitmap
[0];
1284 memcpy(&priv
->img
, desc
->base
->bitmap
[0], sizeof(image
));
1286 binfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1287 binfo
.bmiHeader
.biWidth
= priv
->img
.width
;
1288 binfo
.bmiHeader
.biHeight
= -priv
->img
.height
;
1289 binfo
.bmiHeader
.biPlanes
= 1;
1290 binfo
.bmiHeader
.biSizeImage
= priv
->img
.width
* priv
->img
.height
* (gui
->screenbpp
/ 8);
1291 binfo
.bmiHeader
.biXPelsPerMeter
= 0;
1292 binfo
.bmiHeader
.biYPelsPerMeter
= 0;
1293 binfo
.bmiHeader
.biClrUsed
= 0;
1294 binfo
.bmiHeader
.biClrImportant
= 0;
1295 binfo
.bmiHeader
.biBitCount
= gui
->screenbpp
;
1296 binfo
.bmiHeader
.biCompression
= BI_RGB
;
1297 priv
->bitmap
= CreateDIBSection(hdc
, &binfo
, DIB_RGB_COLORS
, (void **) &priv
->img
.data
, NULL
, 0);
1300 mp_msg(MSGT_GPLAYER
, MSGL_FATAL
, "[GUI] unable to create bitmap for skinned window\n");
1303 memcpy(priv
->img
.data
, desc
->base
->bitmap
[0]->data
, binfo
.bmiHeader
.biSizeImage
);
1304 ReleaseDC(hWnd
,hdc
);
1306 for (i
=0; i
<gui
->skin
->widgetcount
; i
++)
1307 if(gui
->skin
->widgets
[i
]->window
== desc
->type
)
1308 renderwidget(gui
->skin
, &priv
->img
, gui
->skin
->widgets
[i
], 1);
1313 /* creates the sub (AKA video) window,*/
1314 int create_subwindow(gui_t
*gui
, char *skindir
)
1316 HINSTANCE instance
= GetModuleHandle(NULL
);
1323 window_priv_t
*priv
= NULL
;
1324 window
*desc
= NULL
;
1325 int i
, x
= -1, y
= -1;
1326 vo_colorkey
= 0xff00ff;
1328 for (i
=0; i
<gui
->skin
->windowcount
; i
++)
1329 if(gui
->skin
->windows
[i
]->type
== wiSub
)
1330 desc
= gui
->skin
->windows
[i
];
1334 mp_msg(MSGT_GPLAYER
, MSGL_FATAL
, "[GUI] Invalid skin description\n");
1338 windowcolor
= vo_colorkey
;
1339 colorbrush
= CreateSolidBrush(windowcolor
);
1340 wc
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_DBLCLKS
;
1341 wc
.lpfnWndProc
= SubProc
;
1344 wc
.hInstance
= instance
;
1345 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
1346 wc
.hIcon
= gui
->icon
;
1347 wc
.hbrBackground
= NULL
; //WM_PAINT will handle background color switching;
1348 wc
.lpszClassName
= "MPlayer Sub for Windows";
1349 wc
.lpszMenuName
= NULL
;
1352 /* create the sub window menu */
1353 create_submenu(gui
);
1355 rect
.top
= rect
.left
= 100;
1356 rect
.bottom
= rect
.top
+desc
->base
->bitmap
[0]->height
;
1357 rect
.right
= rect
.left
+desc
->base
->bitmap
[0]->width
;
1359 /* our window aspect */
1360 sub_aspect
= (float)(rect
.right
-rect
.left
)/(rect
.bottom
-rect
.top
);
1362 style
= fullscreen
?WS_VISIBLE
| WS_POPUP
:WS_OVERLAPPEDWINDOW
| WS_SYSMENU
| WS_MINIMIZEBOX
;
1363 AdjustWindowRect(&rect
, style
, 0);
1365 if (gui_sub_pos_x
>= 0)
1367 if (gui_sub_pos_y
>= 0)
1370 /* out of bounds check */
1371 if (x
<= -1 || (x
+(rect
.right
-rect
.left
) > GetSystemMetrics(SM_CXSCREEN
)))
1373 if (y
<= -1 || (y
+(rect
.bottom
-rect
.top
) > GetSystemMetrics(SM_CYSCREEN
)))
1376 hWnd
= CreateWindowEx(0, "MPlayer Sub for Windows", "MPlayer for Windows", style
,
1377 x
, y
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
,
1378 gui
->subwindow
, NULL
, instance
, NULL
);
1380 /* load all the window images */
1381 window_render(gui
, hWnd
, hdc
, priv
, desc
, binfo
);
1383 /* enable drag and drop support */
1384 DragAcceptFiles(hWnd
, TRUE
);
1386 gui
->subwindow
= hWnd
;
1388 WinID
= gui
->subwindow
;
1389 ShowWindow(gui
->subwindow
, SW_SHOW
);
1390 UpdateWindow(gui
->subwindow
);
1394 /* loads/updates a skin and creates windows for it */
1395 int create_window(gui_t
*gui
, char *skindir
)
1397 HINSTANCE instance
= GetModuleHandle(NULL
);
1404 window_priv_t
*priv
= NULL
;
1405 window
*desc
= NULL
;
1410 /* destroy the current main window */
1411 if(gui
->skin
) destroy_window(gui
);
1413 /* get screenproperties */
1414 gui
->screenbpp
= GetDesktopBitsPerPixel();
1415 gui
->screenw
= GetSystemMetrics(SM_CXSCREEN
);
1416 gui
->screenh
= GetSystemMetrics(SM_CYSCREEN
);
1418 /* load the new skin */
1419 gui
->skin
= loadskin(skindir
, gui
->screenbpp
);
1422 mp_msg(MSGT_GPLAYER
, MSGL_FATAL
, "[GUI] fatal error during skinload\n");
1423 /* Set default Skin */
1424 if (skinName
) free(skinName
);
1425 skinName
= strdup("Blue");
1426 /* then force write conf */
1431 /* find the description of the mainwindow */
1432 for (i
=0; i
<gui
->skin
->windowcount
; i
++)
1433 if(gui
->skin
->windows
[i
]->type
== wiMain
)
1434 desc
= gui
->skin
->windows
[i
];
1438 mp_msg(MSGT_GPLAYER
, MSGL_FATAL
, "[GUI] Invalid skin description\n");
1442 /* load the icon from the executable */
1443 GetModuleFileName(NULL
, dir
, MAX_PATH
);
1444 gui
->icon
= ExtractIcon(instance
, dir
, 0);
1446 /* create the window class */
1447 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
1448 wc
.lpfnWndProc
= EventProc
;
1451 wc
.hInstance
= instance
;
1452 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
1453 wc
.hIcon
= gui
->icon
;
1454 wc
.hbrBackground
= CreateSolidBrush(RGB(0, 0, 0));
1455 wc
.lpszClassName
= gui
->classname
= "MPlayer GUI for Windows";
1456 wc
.lpszMenuName
= NULL
;
1459 /* create a context menu */
1461 /* create the systray menu */
1462 create_traymenu(gui
);
1464 /* create the mainwindow */
1465 /* TODO implement aligning as described in skin.html */
1466 rect
.top
= rect
.left
= 100;
1467 rect
.bottom
= rect
.top
+desc
->base
->bitmap
[0]->height
;
1468 rect
.right
= rect
.left
+desc
->base
->bitmap
[0]->width
;
1469 if(desc
->decoration
) style
= WS_OVERLAPPED
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
;
1470 else style
= WS_POPUP
| WS_SYSMENU
;
1472 AdjustWindowRect(&rect
, style
, 0);
1474 /* Check if out of screen */
1475 if (gui_main_pos_x
>= 0)
1477 if (gui_main_pos_y
>= 0)
1480 if (x
<= -1 || (x
+(rect
.right
-rect
.left
) > GetSystemMetrics(SM_CXFULLSCREEN
)))
1482 x
= (GetSystemMetrics(SM_CXSCREEN
) / 2) - ((rect
.right
-rect
.left
) / 2);
1485 if (y
<= -1 || (y
+(rect
.bottom
-rect
.top
) > GetSystemMetrics(SM_CYFULLSCREEN
)))
1487 y
= ((GetSystemMetrics(SM_CYSCREEN
)-40) - (rect
.bottom
-rect
.top
));
1491 hwnd
= CreateWindowEx(0, gui
->classname
, "MPlayer for Windows", style
,
1492 x
, y
, rect
.right
-rect
.left
, rect
.bottom
-rect
.top
,
1493 gui
->mainwindow
, NULL
, instance
, NULL
);
1495 /* set the systray icon properties */
1496 nid
.cbSize
= sizeof(NOTIFYICONDATA
);
1499 nid
.uFlags
= NIF_MESSAGE
| NIF_ICON
| NIF_TIP
;
1500 nid
.uCallbackMessage
= WM_SYSTRAY
;
1501 nid
.hIcon
= gui
->icon
;
1502 strcpy(nid
.szTip
, "MPlayer for Windows");
1504 /* register the systray icon */
1505 Shell_NotifyIcon(NIM_ADD
, &nid
);
1507 /* load all the window images */
1508 window_render(gui
, hwnd
, hdc
, priv
, desc
, binfo
);
1510 /* enable drag and drop support */
1511 DragAcceptFiles(hwnd
, TRUE
);
1513 updatedisplay(gui
, hwnd
);
1514 gui
->mainwindow
= hwnd
;
1517 ShowWindow(gui
->mainwindow
, SW_SHOW
);
1518 UpdateWindow(gui
->mainwindow
);
1519 maketransparent(gui
->mainwindow
, RGB(255, 0, 255));
1523 gui_t
*create_gui(char *skindir
, char *skinName
, void (*playercontrol
)(int event
))
1525 gui_t
*gui
= calloc(1, sizeof(gui_t
));
1526 char temp
[MAX_PATH
];
1527 HWND runningmplayer
= FindWindow("MPlayer GUI for Windows", "MPlayer for Windows");
1535 gui
->startplay
= startplay
;
1536 gui
->playercontrol
= playercontrol
;
1537 gui
->uninit
= uninit
;
1538 gui
->updatedisplay
= updatedisplay
;
1540 /* create playlist */
1541 gui
->playlist
= create_playlist();
1543 if(!skinName
) skinName
= strdup("Blue");
1544 sprintf(temp
, "%s\\%s", skindir
, skinName
);
1545 if(create_window(gui
, temp
)) return NULL
;
1546 if(create_subwindow(gui
, temp
)) return NULL
;
1547 if(console
) console_toggle();