📄 optionsdlg.cpp
字号:
#include "stdafx.h"
#include "optionsdlg.h"
#include "resource.h"
#define IS_PAGE_ID(a) ((g_nCurID==a))
#define PAGE_WINDOW 0
#define PAGE_BARS 1
#define PAGE_PEAKS 2
#define PAGE_GRID 3
#define PAGE_ADV 4
#define PAGE_SKIN 5
// Callback functions for dialogs
BOOL CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK ChildDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
// Load/Save Setting functions
bool SetTabCurSel(HWND hDlg, int nID, bool bCallDestroy = true);
void OnDestroyTabSec(int nID);
void LoadPageSettings(HWND hDlg, int nID);
// Helper functions for windows controls
bool CheckCheckBox(HWND hDlg, int nID, bool bCheck);
bool SetEditNumber(HWND hDlg, int nID, int nNum);
bool SetSliderParms(HWND hDlg, int nID, int nMin, int nMax, int nPos);
bool GetCheckState(HWND hDlg, int nID);
int GetEditNum(HWND hDlg, int nID);
int GetSliderPos(HWND hDlg, int nID);
void tabAddPage(HWND hDlg, int nID, int nIndex, const char* lpText);
// Functions defined in vis_spectrum.cpp
void OnConfigRead(struct winampVisModule* mod);
void OnConfigWrite(struct winampVisModule* mod);
void UpdateRect(LPRECT lpRect, HWND hWnd);
void SaveSkin(char* szName);
void LoadSkin();
bool SetCurrentSkin(const char* lpszBitmap);
// Couple of other useful functions
bool StdOpenDialog(HWND hWndParent, const char* lpTitle, const char* lpExtensions, char* lpBuffer, int nBufferSize);
void PaintCurrentSkinToDialog(HWND hDlg);
// The plugin settings and plugin variables declared in vis_spectrum.cpp
extern VS_PLUGINVARS Plugin;
winampVisModule* g_pMod=NULL;
// The current tab page number
int g_nCurID=0;
// A copy of the settings that we can change without changing the
// real ones straight away.
VS_SAVEDATA g_Settings;
// This function invokes the options dialog if it is not already present
bool DoOptionsDialogThingy(winampVisModule* mod)
{
if(!Plugin.bInConfig) {
Plugin.bInConfig = true;
// read the config in case the plugin is not actually running
g_pMod = mod;
OnConfigRead(mod);
g_Settings = Plugin.Settings;
g_Settings.nDelayMS = mod->delayMs;
g_Settings.nLatency = mod->latencyMs;
DialogBoxParam(mod->hDllInstance,(LPCTSTR)IDD_CONFDLG,(Plugin.hWndMain ? Plugin.hWndMain : mod->hwndParent),DlgProc,0);
Plugin.bInConfig = false;
g_pMod = NULL;
return true;
}
return false;
}
BOOL CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg) {
case WM_INITDIALOG:
{
// Add the pages to the tab control
tabAddPage(hDlg, IDC_SELTAB, 0, "&Window");
tabAddPage(hDlg, IDC_SELTAB, 1, "&Bars");
tabAddPage(hDlg, IDC_SELTAB, 2, "&Peaks");
tabAddPage(hDlg, IDC_SELTAB, 3, "&Grid");
tabAddPage(hDlg, IDC_SELTAB, 4, "&Advanced");
tabAddPage(hDlg, IDC_SELTAB, 5, "&Skins");
// And set the selection to the first page
SetTabCurSel(hDlg,0,false);
return TRUE;
}
case WM_NOTIFY:
{
switch(wParam) {
case IDC_SELTAB:
{
NMHDR* idhdr = (NMHDR*)lParam;
if(idhdr->code==TCN_SELCHANGE) {
// Tab page was just changed
SetTabCurSel(hDlg,TabCtrl_GetCurSel(idhdr->hwndFrom));
}
break;
}
default:
break;
}
return FALSE;
}
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDC_DEFAULTS:
// want to reset to defaults
if(MessageBox(hDlg,"Are you sure that you want to reset to the default settings (changes will take effect immediately and be saved)?","Analyser Configuration",MB_ICONQUESTION|MB_YESNO)==IDYES) {
VS_SAVEDATA Settings = {
0, // left window pos
0, // top window pos
275, // width of window
116, // height of window
10, // window snap threshold
true, // snap windows
false,// double size
true, // dim title bar on inactive
true, // save window pos
true, // use winamp cursor
true, // show peaks
true, // show bars
true, // show grid
4, // bar width
1, // bar horizontal gap (shrinks width of bar)
0, // vertical bar gaps
20, // delay (in frames of 25 ms) of peaks to drop
4, // peak drop speed (per frame)
2, // default drop speed (when bars are below 16)
19, // maximum increase at one time
6, // maximum decrease at one time
4, // horizontal grid width
1, // vertical grid gap
1, // horz grid gap (not implemented)
false,// level filter
true, // level remap
25, // delayms
25, // latency ms
1, // bar style (fire)
};
g_Settings = Settings;
Plugin.Settings = g_Settings;
g_pMod->delayMs = Plugin.Settings.nDelayMS;
g_pMod->latencyMs = Plugin.Settings.nLatency;
// load the page settings again for the current page
LoadPageSettings(Plugin.hCurDlg,g_nCurID);
// and save the data
OnConfigWrite(g_pMod);
}
break;
case IDOK:
// OK this is really the apply button
OnDestroyTabSec(g_nCurID);
if(g_Settings.bDoubleSize != Plugin.Settings.bDoubleSize)
SetDoubleSize(Plugin.hWndMain, g_Settings.bDoubleSize);
if(g_Settings.bDimTitleBar != Plugin.Settings.bDimTitleBar) {
if(!Plugin.Settings.bDimTitleBar) {
BitmapBltEx(Plugin.hMemDC, Plugin.hBmpSkin, 0, 0, 275, 14, 0, 130);
}
else {
BitmapBltEx(Plugin.hMemDC, Plugin.hBmpSkin, 0, 0, 275, 14, 0, 116);
}
UpdateRect(&Plugin.rcTitleBar,Plugin.hWndMain);
}
Plugin.Settings = g_Settings;
g_pMod->delayMs = g_Settings.nDelayMS;
g_pMod->latencyMs = g_Settings.nLatency;
OnConfigWrite(g_pMod);
LoadPageSettings(Plugin.hCurDlg,g_nCurID);
break;
case IDCANCEL:
// really the close button
EndDialog(hDlg,LOWORD(wParam));
break;
default:
return FALSE;
}
default:
return FALSE;
}
return TRUE;
}
// Child dialog procedure used for all the dialogs that are displayed within the
// tab control.
BOOL CALLBACK ChildDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg) {
case WM_INITDIALOG:
LoadPageSettings(hDlg,g_nCurID);
break;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDC_BROWSE:
char szBuff[256];
if(StdOpenDialog(GetParent(hDlg),"Browse for Skin","Windows Bitmaps (*.bmp)\0*.BMP\0",szBuff,256)) {
// This saves the new skin filename
SaveSkin(szBuff);
// Then loads the skin
SetCurrentSkin(szBuff);
PaintCurrentSkinToDialog(hDlg);
}
break;
case IDC_BASE:
{
// Reset to the base skin
SaveSkin(NULL);
SetCurrentSkin(NULL);
PaintCurrentSkinToDialog(hDlg);
break;
}
case IDOK:
case IDCANCEL:
EndDialog(hDlg,LOWORD(wParam));
break;
default:
return FALSE;
}
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hDC = BeginPaint(hDlg,&ps);
if(hDC) {
if(IS_PAGE_ID(PAGE_SKIN)) {
// If it is the skins page, then paint the picture of the
// current skin bitmap
BitmapBltEx(hDC, Plugin.hBmpSkin,24,53,275, 153, 0, 0);
}
}
EndPaint(hDlg,&ps);
}
default:
return FALSE;
}
return TRUE;
}
bool SetTabCurSel(HWND hDlg, int nID, bool bCallDestroy)
{
if(bCallDestroy) OnDestroyTabSec(g_nCurID);
if(Plugin.hCurDlg) DestroyWindow(Plugin.hCurDlg);
HWND hTab = GetDlgItem(hDlg,IDC_SELTAB);
if(!hTab) return false;
g_nCurID = nID;
switch(nID) {
case 0:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -