コード例 #1
0
static LRESULT CALLBACK PlayListWndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
    HWND wdg;
    POINT cursor;
    gui_t *gui = (gui_t *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
    playlist_t *pl = gui ? gui->playlist : NULL;
    switch (iMsg)
    {
        case WM_CREATE:
        {
            wdg = CreateWindow("button", "Play",
                               WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                               4, 10, 80, 25, hwnd,
                               (HMENU) ID_PLAY,
                               ((LPCREATESTRUCT) lParam) -> hInstance,
                               NULL);
            SendMessage(wdg, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);

            wdg = CreateWindow ("button", "Up",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                                4, 37, 80, 25, hwnd,
                                (HMENU) ID_UP,
                                ((LPCREATESTRUCT) lParam) -> hInstance,
                                NULL);
            SendMessage(wdg, WM_SETFONT,(WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);

            wdg = CreateWindow ("button", "Down",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                                4, 64, 80, 25, hwnd,
                                (HMENU) ID_DOWN,
                                ((LPCREATESTRUCT) lParam) -> hInstance,
                                NULL);
            SendMessage(wdg, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT),0);

            wdg = CreateWindow ("button", "Remove",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                                4, 91, 80, 25, hwnd,
                                (HMENU) ID_REMOVE,
                                ((LPCREATESTRUCT) lParam) -> hInstance,
                                NULL);
            SendMessage(wdg, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT),0);

            wdg = CreateWindow ("button", "Load",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                                4, 118, 80, 25, hwnd,
                                (HMENU) ID_PLAYLISTLOAD,
                                ((LPCREATESTRUCT) lParam) -> hInstance,
                                NULL);
            SendMessage(wdg, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT),0);

            wdg = CreateWindow ("button", "Save",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                                4, 145, 80, 25, hwnd,
                                (HMENU) ID_PLAYLISTSAVE,
                                ((LPCREATESTRUCT) lParam) -> hInstance,
                                NULL);
            SendMessage(wdg, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT),0);

            wdg = CreateWindow ("button", "Close",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                                4, 193, 80, 25, hwnd,
                                (HMENU) ID_CLOSE,
                                ((LPCREATESTRUCT) lParam) -> hInstance,
                                NULL);
            SendMessage(wdg, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT),0);

            wdg = CreateWindow ("listbox", "tracklist", WS_CHILD | WS_VISIBLE | LBS_NOTIFY | WS_VSCROLL |
                               WS_HSCROLL | LBS_DISABLENOSCROLL, 92, 10, 300, 208, hwnd, (HMENU) ID_TRACKLIST,
                               ((LPCREATESTRUCT) lParam) -> hInstance, NULL);
            SendMessage(wdg, WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
            SendMessage(wdg, LB_SETHORIZONTALEXTENT, MAX_PATH*4, 0);
            break;
        }
        case WM_CONTEXTMENU:
        {
            GetCursorPos(&cursor);
            SetForegroundWindow(hwnd);
            TrackPopupMenu(gui->playlistmenu, 0, cursor.x, cursor.y, 0, hwnd, NULL);
            break;
        }
        case WM_COMMAND:
        {
            int selected = 0;
            int i;
            for (i=0; i<pl->trackcount; i++)
                if(0 < SendDlgItemMessage(hwnd, ID_TRACKLIST, LB_GETSEL, i, 0)) selected = i + 1;
            switch (LOWORD(wParam))
            {
                case ID_CLOSE:
                    DestroyWindow(hwnd);
                    return 0;
                case ID_TRACKLIST:
                    if(HIWORD(wParam) == LBN_DBLCLK)
                    {
                case ID_PLAY:
                        if(selected) pl->current = selected - 1;
                        mplSetFileName(NULL, pl->tracks[pl->current]->filename, STREAMTYPE_STREAM);
                        gui->startplay(gui);
                    }
                    return 0;
                case ID_UP:
                {
                    if(selected) pl->moveup_track(pl, selected);
                    selected--;
                    break;
                }
                case ID_DOWN:
                {
                    if(selected) pl->movedown_track(pl, selected);
                    selected++;
                    break;
                }
                case ID_REMOVE:
                    if(selected) pl->remove_track(pl, selected);
                    break;
                case ID_ADDFILE:
                {
                    if(guiIntfStruct.StreamType == STREAMTYPE_DVD ||
                       guiIntfStruct.StreamType == STREAMTYPE_DVDNAV) return 0;
                    display_openfilewindow(gui, 1);
                    break;
                }
                case ID_ADDURL:
                {
                    if(guiIntfStruct.StreamType == STREAMTYPE_DVD ||
                       guiIntfStruct.StreamType == STREAMTYPE_DVDNAV) return 0;
                    display_openurlwindow(gui, 1);
                    break;
                }
                case ID_CLEAR:
                {
                    if(!gui->playlist->trackcount) return 0;
                    gui->playlist->clear_playlist(gui->playlist);
                    break;
                }
                case ID_PLAYLISTLOAD:
                {
                    if(guiIntfStruct.StreamType == STREAMTYPE_DVD ||
                       guiIntfStruct.StreamType == STREAMTYPE_DVDNAV) return 0;
                    display_loadplaylistwindow(gui);
                    break;
                }
                case ID_PLAYLISTSAVE:
                {
                    /* no point saving an empty playlist */
                    if(!gui->playlist->trackcount ||
                        guiIntfStruct.StreamType == STREAMTYPE_DVD ||
                        guiIntfStruct.StreamType == STREAMTYPE_DVDNAV)
                        return 0;
                    display_saveplaylistwindow(gui);
                    break;
                }
            }
            updatetracklist(hwnd);
            if(selected < 1) selected = 1;
            else if(selected>pl->trackcount) selected = pl->trackcount;
            SendDlgItemMessage(hwnd, ID_TRACKLIST, LB_SETCURSEL, selected - 1, 0);
            return 0;
        }
        case WM_DROPFILES:
        {
            char file[MAX_PATH];
            int filecount = DragQueryFile((HDROP) wParam, -1, file, MAX_PATH);
            int i;
            for (i=0; i<filecount; i++)
            {
                DragQueryFile((HDROP) wParam, i, file, MAX_PATH);
                if(!parse_filename(file, playtree, mconfig, 0))
                    pl->add_track(pl, file, NULL, NULL, 0);
            }
            DragFinish((HDROP) wParam);
            updatetracklist(hwnd);
        }
            break;
    }
    return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
コード例 #2
0
ファイル: playlist.c プロジェクト: WilliamRen/mplayer-ww
static LRESULT CALLBACK PlayListWndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
	HWND wdg;
	POINT cursor;
	playlist_t *pl = playlist;
	switch (iMsg)
	{
		case WM_CREATE:
		{
			RECT r;
			LOGFONT lf;
			memset(&lf,0, sizeof(LOGFONT));
			strcpy(lf.lfFaceName,"MS Shell Dlg");
			lf.lfHeight = -10;
			lf.lfWeight = FW_NORMAL;
			HFONT   hFont=CreateFontIndirect(&lf);
			wdg = CreateWindow("button", BottonPlayAll,
							   WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
							   4, 10, 80, 22, hwnd,
							   (HMENU) ID_PLAY,
							   ((LPCREATESTRUCT) lParam) -> hInstance,
							   NULL);
  			SendMessage(wdg,   WM_SETFONT,   (WPARAM)hFont,   0);

			wdg = CreateWindow ("button", BottonUp,
								WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
								4, 35, 80, 22, hwnd,
								(HMENU) ID_UP,
								((LPCREATESTRUCT) lParam) -> hInstance,
								NULL);
			SendMessage(wdg,   WM_SETFONT,   (WPARAM)hFont,   0);

			wdg = CreateWindow ("button",BottonDown,
								WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
								4, 60, 80, 22, hwnd,
								(HMENU) ID_DOWN,
								((LPCREATESTRUCT) lParam) -> hInstance,
								NULL);
  			SendMessage(wdg,   WM_SETFONT,   (WPARAM)hFont,   0);

			wdg = CreateWindow ("button", BottonRemove,
								WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
								4, 85, 80, 22, hwnd,
								(HMENU) ID_REMOVE,
								((LPCREATESTRUCT) lParam) -> hInstance,
								NULL);
  			SendMessage(wdg,   WM_SETFONT,   (WPARAM)hFont,   0);

			wdg = CreateWindow ("button", BottonAdd,
								WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
								4, 110, 80, 22, hwnd,
								(HMENU) ID_ADDFILE,
								((LPCREATESTRUCT) lParam) -> hInstance,
								NULL);
  			SendMessage(wdg,   WM_SETFONT,   (WPARAM)hFont,   0);

			wdg = CreateWindow ("button", BottonSave,
								WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
								4, 135, 80, 22, hwnd,
								(HMENU) ID_PLAYLISTSAVE,
								((LPCREATESTRUCT) lParam) -> hInstance,
								NULL);
  			SendMessage(wdg,   WM_SETFONT,   (WPARAM)hFont,   0);

			wdg = CreateWindow ("button", BottonClose,
								WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
								4, 185, 80, 22, hwnd,
								(HMENU) ID_CLOSE,
								((LPCREATESTRUCT) lParam) -> hInstance,
								NULL);
  			SendMessage(wdg,   WM_SETFONT,   (WPARAM)hFont,   0);

			GetClientRect(hwnd, &r);
			wdg = CreateWindowEx(WS_EX_CLIENTEDGE, "SysListView32", "tracklist",
					WS_CHILD | WS_VISIBLE | LVS_SINGLESEL | LVS_REPORT | LVS_SHOWSELALWAYS | LVS_NOSORTHEADER /*| LVS_NOCOLUMNHEADER*/,
					90, 7, r.right-90, r.bottom-7, hwnd, (HMENU) ID_TRACKLIST, ((LPCREATESTRUCT) lParam) -> hInstance, NULL);

  			SendMessage(wdg, WM_SETFONT, (WPARAM)hFont, 0);
			wdgProc = SetWindowLong(wdg, GWL_WNDPROC, (LONG)ListProc);
			LV_COLUMNA lvc, lvc1, lvc2;
			ZeroMemory(&lvc, sizeof(LV_COLUMNA));
			ZeroMemory(&lvc1, sizeof(LV_COLUMNA));
			ZeroMemory(&lvc2, sizeof(LV_COLUMNA));
			lvc.mask = LVCF_WIDTH;
			lvc.cx = 24;
			lvc1.mask = LVCF_WIDTH;
			lvc1.cx = 700;
			lvc2.mask = LVCF_WIDTH;
			lvc2.cx = 500;
			SendMessage(wdg, LVM_INSERTCOLUMN,0, &lvc);
			SendMessage(wdg, LVM_INSERTCOLUMN,1, &lvc1);
			SendMessage(wdg, LVM_INSERTCOLUMN,2, &lvc2);
			SendMessage(wdg, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
			break;
		}
		case WM_CONTEXTMENU:
		{
			GetCursorPos(&cursor);
			SetForegroundWindow(hwnd);
			TrackPopupMenu(playlistmenu, 0, cursor.x, cursor.y, 0, hwnd, NULL);
			break;
		}
		case WM_NOTIFY:
		{
			if(wParam == ID_TRACKLIST) {
				NMHDR *nmhdr = (NMHDR *)lParam;
				if(nmhdr && nmhdr->code == NM_DBLCLK) {
					int selected = SendDlgItemMessage(hwnd, ID_TRACKLIST, LVM_GETSELECTIONMARK, 0, 0);
					if(0 <= selected) {
						pl->current = selected;
						playtree_update_play(mpctx, pl->current);
						return 0;
					}
				} else if(nmhdr && nmhdr->code == NM_CLICK)
					button_down = FALSE;
			}
			break;
		}
		case WM_LBUTTONDOWN:
			PostMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(LOWORD(lParam), HIWORD(lParam)));
			break;
		case WM_NCLBUTTONUP:
		case WM_LBUTTONUP:
			button_down = FALSE;
			break;
		case WM_KEYDOWN:
			switch (wParam)
			{
				case VK_ESCAPE:
					ShowWindow(hwnd, SW_HIDE);
					break;
			}
			break;
		case WM_COMMAND:
		{
			int selected = 0;
			int i = SendDlgItemMessage(hwnd, ID_TRACKLIST, LVM_GETSELECTIONMARK, 0, 0);
			if(0 <= i) selected = i + 1;
			switch (LOWORD(wParam))
			{
				case ID_CLOSE:
					if(SetLayeredWinAttributes) {
						if(transparent) {
							transparent = 0;
							SetLayeredWinAttributes(hPlaylistWnd, 0, 255, 2);
						} else {
							transparent = 1;
							SetLayeredWinAttributes(hPlaylistWnd, 0, controlbar_alpha, 2);
						}
					}
					break;
				case ID_PLAY:
					if(selected) {
						pl->current = selected - 1;
						playtree_update_play(mpctx, pl->current);
					} else
						playtree_update_play(mpctx, 0);
					return 0;
				case ID_UP:
					if(selected) pl->moveup_track(pl, selected);
					selected--;
					up_list_item(hwnd, selected);
					need_update_playtree = 1;
					return 0;
				case ID_DOWN:
					if(selected) pl->movedown_track(pl, selected);
					down_list_item(hwnd, selected-1);
					selected++;
					need_update_playtree = 1;
					return 0;
				case ID_REMOVE:
					if(selected) pl->remove_track(pl, selected);
					delete_list_item(hwnd, selected-1);
					need_update_playtree = 1;
					return 0;
				case ID_ADDFILE:
					display_openfilewindow(1);
					break;
				case ID_CLEAR:
					if(!playlist->trackcount) return 0;
					playlist->clear_playlist(playlist);
					SendDlgItemMessage(hwnd, ID_TRACKLIST, LVM_DELETEALLITEMS, 0, 0);
					need_update_playtree = 1;
					return 0;
				case ID_PLAYLISTLOAD:
					display_loadplaylistwindow();
					break;
				case ID_PLAYLISTSAVE:
				{
					/* no point saving an empty playlist */
					display_saveplaylistwindow();
					break;
				}
			}
			updatetracklist(hwnd);
			if(selected < 1) selected = 1;
			else if(selected>pl->trackcount) selected = pl->trackcount;
			SendDlgItemMessage(hwnd, ID_TRACKLIST, LVM_SETSELECTIONMARK, 0, selected - 1);
			return 0;
		}
		case WM_DROPFILES:
		{
			DWORD t;
			char file[MAX_PATH];
			wchar_t tmpw[MAX_PATH], tmpshot[MAX_PATH];
			int filecount = DragQueryFile((HDROP) wParam, -1, file, MAX_PATH);
			int i;
			for (i=0; i<filecount; i++)
			{
				DragQueryFile((HDROP) wParam, i, file, MAX_PATH);
				t = GetFileAttributes(file);
				if (t & 0x10) {
					if(t == 0xFFFFFFFF) {
						DragQueryFileW((HDROP)wParam, i, tmpw, MAX_PATH);
						GetShortPathNameW(tmpw,tmpshot,MAX_PATH);
						wcstombs(file,tmpshot,MAX_PATH);
					}
					add_directory_to_playlist(file);
				} else {
					if(t == 0xFFFFFFFF) {
						DragQueryFileW((HDROP)wParam, i, tmpw, MAX_PATH);
						GetShortPathNameW(tmpw,tmpshot,MAX_PATH);
						wcstombs(file,tmpshot,MAX_PATH);
					}
					pl->add_track(pl, file, NULL, NULL, 0);
					playtree_add_file(mpctx->playtree, file);
				}
			}
			DragFinish((HDROP) wParam);
			updatetracklist(hwnd);
			break;
		}
		case WM_SIZING:
		{
			LPRECT rc = (LPRECT)lParam;
			if(rc->right - rc->left < WinWidth-100)
				rc->right = rc->left + WinWidth-100;
			if(rc->bottom - rc->top < WinHeight-30)
				rc->bottom = rc->top + WinHeight-30;
			break;
		}
		case WM_SIZE:
		{
			RECT r;
			GetClientRect(hwnd, &r);
			MoveWindow(GetDlgItem(hwnd, ID_TRACKLIST), 90, 7, r.right-90, r.bottom-7, TRUE);
			break;
		}
		case WM_SYSCOMMAND:
		{
			if (wParam == SC_MINIMIZE) {
				ShowWindow(hwnd, SW_HIDE);
				return 0;
			}
			break;
		}
		case WM_DESTROY:
			PostQuitMessage(0);
			return 0;
	}
	return DefWindowProc(hwnd, iMsg, wParam, lParam);
}