📄 dialog.cpp
字号:
SW_SHOWNORMAL);
return 1;
case ID_HELP_ABOUT:
m_context->target->AcceptEvent(new ShowPreferencesEvent(9));
return 1;
}
}
case WM_DRAWITEM:
{
return DrawItem(wParam, (DRAWITEMSTRUCT*) lParam);
break;
}
case WM_MEASUREITEM:
{
MEASUREITEMSTRUCT* mis = (MEASUREITEMSTRUCT*) lParam;
TEXTMETRIC tm;
HDC hdc;
HFONT hFont;
HWND hwndLV;
// Make sure the control is the listview control
if (mis->CtlType != ODT_LISTVIEW || mis->CtlID != IDC_PLAYLISTBOX)
return FALSE;
// Get the handle of the ListView control we're using
hwndLV = GetDlgItem(hwnd, mis->CtlID);
// Get the font the control is currently using
hFont = (HFONT)(DWORD) SendMessage(hwndLV, WM_GETFONT, 0, 0L);
// Set the font of the DC to the same font the control is using
hdc = GetDC(hwndLV);
SelectObject(hdc, hFont);
// Get the height of the font used by the control
if (!GetTextMetrics(hdc, &tm))
return FALSE;
// Add a little extra space between items
mis->itemHeight = tm.tmHeight + 1;
// Make sure there is enough room for the images which are CY_SMICON high
if (mis->itemHeight < 17)
mis->itemHeight = 17;
// Clean up
ReleaseDC(hwndLV, hdc);
return TRUE;
break;
}
case WM_INITMENU:
{
UpdateMenuStates();
break;
}
case WM_DEVICECHANGE:
{
DeviceChanged(wParam, (PDEV_BROADCAST_HDR)lParam);
break;
}
}
return 0;
}
bool MusicBrowserUI::CreateMainDialog()
{
MSG msg;
m_hWnd = CreateDialogParam( g_hinst,
MAKEINTRESOURCE(IDD_MUSICBROWSER),
NULL,
(DLGPROC)MainDlgProc,
(LPARAM)this);
if(m_hWnd)
{
if(m_pParent)
{
RECT sRect;
GetWindowRect(m_hParent, &sRect);
SetWindowPos(m_hWnd, NULL, sRect.left + 20, sRect.top + 20,
0, 0, SWP_NOZORDER|SWP_NOSIZE);
ShowWindow(m_hWnd, SW_NORMAL);
UpdateWindow(m_hWnd);
}
while(GetMessage(&msg,NULL,0,0))
{
if(!IsDialogMessage(m_hWnd, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
DestroyWindow(m_hWnd);
m_hWnd = NULL;
return false;
}
void MusicBrowserUI::UIThreadFunc(void* arg)
{
MusicBrowserUI* ui = (MusicBrowserUI*)arg;
if (ui->CreateMainDialog())
delete ui;
}
Error MusicBrowserUI::CloseMainDialog()
{
if(m_pParent)
{
if(m_bListChanged)
{
ShowWindow(m_hWnd, SW_RESTORE);
SetForegroundWindow(m_hWnd);
if (MessageBox(m_hWnd, "Would you like to save this playlist?",
BRANDING, MB_YESNO) == IDYES)
{
if(!m_portableDevice)
SavePlaylist();
else
SavePortablePlaylist();
}
}
}
m_bListChanged = false;
PostMessage(m_hWnd, WM_QUIT, 0, 0);
return kError_NoErr;
}
void MusicBrowserUI::ShowBrowser(bool bShowExpanded)
{
ShowWindow(m_hWnd, SW_RESTORE);
ShowWindow(m_hWnd, SW_SHOW);
SetForegroundWindow(m_hWnd);
PostMessage(m_hWnd, UWM_EMPTYDBCHECK, 0, 0);
isVisible = true;
}
void MusicBrowserUI::HideBrowser()
{
isVisible = false;
ShowWindow(m_hWnd, SW_HIDE);
}
void MusicBrowserUI::Close()
{
if(m_pParent == NULL)
HideBrowser();
else
CloseMainDialog();
}
void MusicBrowserUI::Destroy()
{
RECT controlRect;
char buf[256];
int32 h,w, s;
int32 screenX, screenY;
WINDOWPLACEMENT wp;
screenX = GetSystemMetrics(SM_CXSCREEN);
screenY = GetSystemMetrics(SM_CYSCREEN);
wp.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(m_hWnd, &wp);
//GetWindowRect(m_hWnd, &rect);
GetWindowRect(m_hMusicView, &controlRect);
h = wp.rcNormalPosition.bottom - wp.rcNormalPosition.top;
w = wp.rcNormalPosition.right - wp.rcNormalPosition.left;
s = controlRect.right - controlRect.left;
// some sanity checking
if(wp.rcNormalPosition.left < 0)
wp.rcNormalPosition.left = 0;
if(wp.rcNormalPosition.top < 0)
wp.rcNormalPosition.top = 0;
if(s >= w)
s = w/3;
sprintf(buf, "%d,%d,%d,%d,%d", wp.rcNormalPosition.left, wp.rcNormalPosition.top, w, h, s);
m_context->prefs->SetPrefString(kMusicBrowserPositionPref, buf);
int a,b,c,d,e,f,g,i;
a = ListView_GetColumnWidth(m_hPlaylistView, 1);
b = ListView_GetColumnWidth(m_hPlaylistView, 2);
c = ListView_GetColumnWidth(m_hPlaylistView, 3);
d = ListView_GetColumnWidth(m_hPlaylistView, 4);
e = ListView_GetColumnWidth(m_hPlaylistView, 5);
f = ListView_GetColumnWidth(m_hPlaylistView, 6);
g = ListView_GetColumnWidth(m_hPlaylistView, 7);
i = ListView_GetColumnWidth(m_hPlaylistView, 8);
sprintf(buf, "%d,%d,%d,%d,%d,%d,%d,%d", a,b,c,d,e,f,g,i);
m_context->prefs->SetPrefString(kMusicBrowserHeaderWidthsPref, buf);
RevokeDragDrop(m_hPlaylistView);
OleUninitialize();
ImageList_Destroy(TreeView_SetImageList(
m_hMusicView,
NULL, TVSIL_NORMAL));
ImageList_Destroy(ListView_SetImageList(
m_hPlaylistView,
NULL, LVSIL_SMALL));
m_playlistDropTarget->Release();
if(m_pParent)
{
m_pParent->RemoveMusicBrowserWindow(this);
delete this;
}
}
void MusicBrowserUI::ExpandCollapseEvent()
{
HMENU hMenu;
MENUITEMINFO sItem;
RECT catalogRect, playlistRect, titleRect;
GetWindowRect(m_hMusicView, &catalogRect);
GetWindowRect(m_hPlaylistView, &playlistRect);
GetWindowRect(m_hPlaylistTitle, &titleRect);
MapWindowPoints(NULL, m_hWnd, (LPPOINT)&catalogRect, 2);
MapWindowPoints(NULL, m_hWnd, (LPPOINT)&playlistRect, 2);
MapWindowPoints(NULL, m_hWnd, (LPPOINT)&titleRect, 2);
if (m_state == STATE_COLLAPSED)
{
m_state = STATE_EXPANDED;
SetWindowText(m_hWnd, "My Music - " BRANDING);
sItem.dwTypeData = "View &Playlist Only";
ShowWindow(m_hMusicView, SW_SHOW);
ShowWindow(m_hMusicViewTitle, SW_SHOW);
MoveWindow(m_hPlaylistView,
catalogRect.left + m_iCollapseMoveAmount,
catalogRect.top,
(playlistRect.right - playlistRect.left) - m_iCollapseMoveAmount,
playlistRect.bottom - playlistRect.top,
TRUE);
MoveWindow(m_hPlaylistTitle,
titleRect.left + m_iCollapseMoveAmount,
titleRect.top,
(titleRect.right - titleRect.left) - m_iCollapseMoveAmount,
titleRect.bottom - titleRect.top,
TRUE);
}
else
{
m_state = STATE_COLLAPSED;
SetWindowText(m_hWnd, "Playlist - " BRANDING);
sItem.dwTypeData = "View &My Music";
ShowWindow(m_hMusicView, SW_HIDE);
ShowWindow(m_hMusicViewTitle, SW_HIDE);
m_iCollapseMoveAmount = playlistRect.left - catalogRect.left;
MoveWindow(m_hPlaylistView,
catalogRect.left,
catalogRect.top,
(playlistRect.right - playlistRect.left) + m_iCollapseMoveAmount,
playlistRect.bottom - playlistRect.top,
TRUE);
MoveWindow(m_hPlaylistTitle,
titleRect.left - m_iCollapseMoveAmount,
titleRect.top,
(titleRect.right - titleRect.left) + m_iCollapseMoveAmount,
titleRect.bottom - titleRect.top,
TRUE);
}
hMenu = GetMenu(m_hWnd);
hMenu = GetSubMenu(hMenu, 2);
sItem.cbSize = sizeof(MENUITEMINFO);
sItem.fMask = MIIM_TYPE;
sItem.fType = MFT_STRING;
sItem.cch = strlen(sItem.dwTypeData);
SetMenuItemInfo(hMenu, ID_VIEW_MUSICCATALOG, false, &sItem);
SendMessage(m_hStatus, SB_SETTEXT, 0, (LPARAM)"");
InvalidateRect(m_hWnd, NULL, true);
UpdateWindow(m_hWnd);
}
void MusicBrowserUI::SizeWindow(int iType, int iWidth, int iHeight)
{
RECT windowRect;
RECT clientRect;
RECT controlRect;
uint32 windowHeight, windowWidth;
uint32 clientHeight, clientWidth;
uint32 controlHeight, controlWidth;
uint32 statusbarHeight;
RECT oldListViewRect;
GetWindowRect(m_hWnd, &windowRect);
windowHeight = windowRect.bottom - windowRect.top;
windowWidth = windowRect.right - windowRect.left;
GetClientRect(m_hWnd, &clientRect);
clientHeight = clientRect.bottom - clientRect.top;
clientWidth = clientRect.right - clientRect.left;
HDWP hdwp = BeginDeferWindowPos(5);
// Status Bar
GetWindowRect(m_hStatus, &controlRect);
controlHeight = controlRect.bottom - controlRect.top;
controlWidth = controlRect.right - controlRect.left;
statusbarHeight = controlHeight;
hdwp = DeferWindowPos(hdwp, m_hStatus, NULL,
windowRect.left,
windowRect.bottom - controlHeight,
windowWidth,
controlHeight,
SWP_NOZORDER);
panes[0] = clientRect.right - clientRect.left /*- kControlsWidth*/ - kTimeWidth;
//panes[1] = panes[0] + kControlsWidth;
SendMessage(m_hStatus, SB_SETPARTS, kNumPanes, (LPARAM) panes);
// Tool Bar
GetWindowRect(m_hRebar, &controlRect);
controlHeight = controlRect.bottom - controlRect.top;
controlWidth = controlRect.right - controlRect.left;
hdwp = DeferWindowPos(hdwp, m_hRebar, NULL,
0,
0,
clientWidth,
controlHeight,
SWP_NOZORDER);
// Music Catalog View
GetWindowRect(m_hMusicView, &controlRect);
MapWindowPoints(NULL, m_hWnd, (LPPOINT)&controlRect, 2);
controlHeight = controlRect.bottom - controlRect.top;
controlWidth = controlRect.right - controlRect.left;
hdwp = DeferWindowPos(hdwp, m_hMusicView, NULL,
controlRect.left,
controlRect.top,
controlWidth,
clientRect.bottom - controlRect.top - statusbarHeight,
SWP_NOZORDER);
// Current Playlist Title
GetWindowRect(m_hPlaylistTitle, &controlRect);
MapWindowPoints(NULL, m_hWnd, (LPPOINT)&controlRect, 2);
controlHeight = controlRect.bottom - controlRect.top;
controlWidth = clientRect.right - controlRect.left;
hdwp = DeferWindowPos(hdwp, m_hPlaylistTitle, NULL,
controlRect.left,
controlRect.top,
controlWidth,
controlHeight,
SWP_NOZORDER);
// Playlist View
GetClientRect(m_hPlaylistView, &oldListViewRect);
GetWindowRect(m_hPlaylistView, &controlRect);
MapWindowPoints(NULL, m_hWnd, (LPPOINT)&controlRect, 2);
controlHeight = clientRect.bottom - controlRect.top;
controlWidth = clientRect.right - controlRect.left;
hdwp = DeferWindowPos(hdwp, m_hPlaylistView, NULL,
controlRect.left,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -