Code: Select all
#include "windows.bi"
#include "win\commctrl.bi"
#include "win\windowsx.bi"
Declare Function WndProc(hWnd As HWND, uMsg As UINT, wParam As WPARAM, lParam As LPARAM) As Integer
Const As Long iBgColor = &h606060
Const As Integer idComboBox = 2000
Dim Shared As HWND hWND_EQ, hCombobox_EQ, hCheckBox_EQ, aSlider_EQ(9)
Dim Shared As WndProc oldSliderProc
Dim Shared As Single aEQ_Freq(9) = {80, 120, 250, 500, 1000, 1800, 3500, 7000, 10000, 14000}
Dim Shared As Single aEQ_Bandwith(9) = {14, 12, 12, 12, 12, 12, 12, 12, 10, 10}
Dim Shared As Single aEQ_Pop(9) = {3, 2, 0, -2, -1, 0, 2, 3, 4, 3}
'Dim Shared As Single aEQ_Pop(9) = {9, 6, 0, -6, -3, 0, 6, 9, 12, 9}
Dim Shared As Single aEQ_Rock(9) = {4, 3, 2, 1, 2, 3, 4, 2, 2, 0}
'Dim Shared As Single aEQ_Rock(9) = {12, 9, 6, 3, 6, 9, 12, 6, 6, 0}
Dim Shared As Single aEQ_Jazz(9) = {3, 2, 1, 0, 1, 0, 2, 1, -1, -2}
'Dim Shared As Single aEQ_Jazz(9) = {9, 6, 3, 0, 3, 0, 6, 3, -3, -6}
Dim Shared As Single aEQ_Classical(9) = {2, 1, 0, -1, 1, 2, 3, 2, 1, 0}
'Dim Shared As Single aEQ_Classical(9) = {6, 3, 0, -3, 3, 6, 9, 6, 3, 0}
Dim Shared As Single aEQ_Bass(9) = {6, 5, 4, 0, -2, -2, -2, 0, 0, 0}
'Dim Shared As Single aEQ_Bass(9) = {15, 12, 9, 0, -6, -6, -6, 0, 0, 0}
Dim Shared As Single aEQ_VocalBoost(9) = {-3, -2, 0, 1, 3, 4, 5, 4, 2, 1}
'Dim Shared As Single aEQ_VocalBoost(9) = {-9, -6, 0, 3, 9, 12, 15, 12, 6, 3}
Dim Shared As Single aEQ_Electronic(9) = {5, 4, 3, -1, -2, 1, 2, 3, 5, 4}
'Dim Shared As Single aEQ_Electronic(9) = {15, 12, 9, -3, -6, 3, 6, 9, 15, 12}
Dim Shared As Single aEQ_Flat(9) = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Sub Equalizer()
Dim wc As WNDCLASSEX
Dim msg As MSG
Dim As Integer sW, sH
ScreenInfo(sW, sH)
Dim szAppName As ZString * 30 => "FB GUI"
Dim As String sTitle = "Equalizer GUI"
Dim As ULong iW, iH
iW = 640
iH = Int(iW * 9 / 16) + 50
Dim As String aLables(9) = {"80 ", "120", "250", "500", "1k ", "1.8k", "3.5k", "7k ", "10k", "14k"}
With wc
.style = CS_HREDRAW Or CS_VREDRAW
.lpfnWndProc = @WndProc
.cbClsExtra = NULL
.cbWndExtra = NULL
.hInstance = GetModuleHandle(NULL)
.hIcon = LoadIcon(NULL, IDI_APPLICATION)
.hCursor = LoadCursor(NULL, IDC_ARROW)
.hbrBackground = CreateSolidBrush(iBgColor)
.lpszMenuName = NULL
.lpszClassName = @szAppName
.cbSize = SizeOf(WNDCLASSEX)
End With
RegisterClassEx(@wc)
Dim As Long iStyle = WS_OVERLAPPEDWINDOW Or WS_VISIBLE Or WS_BORDER
iStyle Xor = (WS_SIZEBOX Or WS_MAXIMIZEBOX)
hWND_EQ = CreateWindowEx(WS_EX_WINDOWEDGE, wc.lpszClassName, sTitle, _
iStyle, _
(sW - iW) / 2, (sH - iH) / 2, _
iW, iH, _
NULL, NULL, wc.hInstance, NULL)
Dim As Any Ptr hDC = GetDC(NULL)
Dim As Integer iHeight = MulDiv(16, GetDeviceCaps(hDC, LOGPIXELSY), 72)
ReleaseDC(NULL, hDC)
Dim As HFONT hFont = CreateFont(iHeight, 0, 0, 0, 400, False, False, False, _
1, OUT_DEFAULT_PRECIS, _
CLIP_DEFAULT_PRECIS, _
DEFAULT_QUALITY, _
DEFAULT_PITCH, _
"Comic Sans MS")
hCheckBox_EQ = CreateWindowEx(0, "BUTTON", "On", _
WS_TABSTOP Or WS_VISIBLE Or WS_CHILD Or BS_AUTOCHECKBOX, _
35, 22, 50, 20, hWND_EQ, 0, 0, 0 )
CheckDlgButton(hWND_EQ, GetDlgCtrlID(hCheckBox_EQ), BST_CHECKED)
hCombobox_EQ = CreateWindowEx(WS_EX_CLIENTEDGE, WC_COMBOBOX, NULL, _
WS_CHILD Or WS_VISIBLE Or CBS_DROPDOWNLIST Or CBS_AUTOHSCROLL, _
(iW - 250) / 2, 20, 250, 512, hWND_EQ, Cast(HMENU, Cast(LONG_PTR, idComboBox)), GetModuleHandle(NULL), NULL)
SendMessage(hCombobox_EQ, WM_SETREDRAW, Cast(WPARAM, False), Cast(LPARAM, 0))
'https://docs.microsoft.com/en-us/windows/win32/controls/bumper-combobox-control-reference-macros
ComboBox_AddString(hCombobox_EQ, StrPtr(Str("Flat")))
ComboBox_AddString(hCombobox_EQ, StrPtr(Str("Pop")))
ComboBox_AddString(hCombobox_EQ, StrPtr(Str("Rock")))
ComboBox_AddString(hCombobox_EQ, StrPtr(Str("Jazz")))
ComboBox_AddString(hCombobox_EQ, StrPtr(Str("Classical")))
ComboBox_AddString(hCombobox_EQ, StrPtr(Str("Bass")))
ComboBox_AddString(hCombobox_EQ, StrPtr(Str("Vocal Boost")))
ComboBox_AddString(hCombobox_EQ, StrPtr(Str("Electronic")))
SendMessage(hCombobox_EQ, WM_SETREDRAW, Cast(WPARAM, True), Cast(LPARAM, 0))
SendMessage(hCombobox_EQ, CB_SETCURSEL, Cast(WPARAM, 0), Cast(LPARAM, 0))
SendMessage(hCombobox_EQ, WM_SETFONT, Cast(WPARAM, hFont), Cast(LPARAM, True))
Dim As Byte i, iGain_Min = -6, iGain_Max = 6
For i = 0 To 9
CreateWindowEx(0, "STATIC", aLables(i), SS_CENTER Or WS_VISIBLE Or WS_CHILD, 95 + i * 50, 270, 40, 20, hWND_EQ, 0, 0, 0)
aSlider_EQ(i) = CreateWindowEx(NULL, TRACKBAR_CLASS, "Trackbar Control", WS_VISIBLE Or WS_CHILD Or TBS_VERT Or TBS_BOTH Or TBS_AUTOTICKS Or TBS_ENABLESELRANGE Or TBS_TOP, _
95 + i * 50, 65, 40, 200, hWND_EQ, NULL, NULL, NULL)
SendMessage(aSlider_EQ(i), TBM_SETRANGE, Cast(WPARAM, True), MAKELONG(iGain_Min, iGain_Max))
SendMessage(aSlider_EQ(i), TBM_SETPOS, Cast(WPARAM, True), Cast(LPARAM, 0))
SendMessage(aSlider_EQ(i), TBM_SETTICFREQ, Cast(WPARAM, 1), Cast(LPARAM, 0))
SendMessage(aSlider_EQ(i), WM_CHANGEUISTATE, Cast(WPARAM, MAKELONG(UISF_HIDEFOCUS, UIS_SET)), Cast(LPARAM, 0)) 'remove focused lines
Next
CreateWindowEx(0, "STATIC", "+" & iGain_Max & " dB", SS_CENTER Or WS_VISIBLE Or WS_CHILD, 35, 70, 50, 15, hWND_EQ, 0, 0, 0)
CreateWindowEx(0, "STATIC", "0 dB", SS_CENTER Or WS_VISIBLE Or WS_CHILD, 35, 157, 50, 15, hWND_EQ, 0, 0, 0)
CreateWindowEx(0, "STATIC", iGain_Min & " dB", SS_CENTER Or WS_VISIBLE Or WS_CHILD, 35, 243, 50, 15, hWND_EQ, 0, 0, 0)
CreateWindowEx(0, "STATIC", "Hz", SS_CENTER Or WS_VISIBLE Or WS_CHILD, 47, 270, 25, 15, hWND_EQ, 0, 0, 0)
ShowWindow(hWND_EQ, SW_SHOW)
While GetMessage(@msg, 0, 0, 0)
TranslateMessage(@msg)
DispatchMessage(@msg)
Wend
End Sub
Sub UpdateSliders(aSettings() As Single)
For i As Byte = 0 To 9
SendMessage(aSlider_EQ(i), TBM_SETPOS, Cast(WPARAM, True), Cast(LPARAM, -aSettings(i)))
If IsDlgButtonChecked(hWND_EQ, GetDlgCtrlID(hCheckBox_EQ)) Then
End If
Next
End Sub
Sub UpdateEQ(b As Integer, v As Single = 0)
If (b < 10) Then
End If
End Sub
Function WndProc(hWnd As HWND, uMsg As UINT, wParam As WPARAM, lParam As LPARAM) As Integer
If hWnd = hWND_EQ Then
Select Case uMsg
Case WM_CLOSE
PostQuitMessage(0)
Case WM_CREATE
Case WM_CTLCOLORSTATIC
Dim As HDC hdcStatic = Cast(HDC, wParam)
SetTextColor(hdcStatic, &hF0F0F0)
SetBkColor(hdcStatic, iBgColor)
Static As HBRUSH hbrBkgnd
If hbrBkgnd = 0 Then hbrBkgnd = CreateSolidBrush(iBgColor)
Return Cast(INT_PTR, hbrBkgnd)
Case WM_COMMAND
Select Case LoWord (wParam)
Case idComboBox '...'
Select Case HiWord(wParam)
Case CBN_SELCHANGE
Dim As ZString * 512 sComboCurrSel
ComboBox_GetLBText(hCombobox_EQ, ComboBox_GetCurSel(hCombobox_EQ), @sComboCurrSel)
Select Case sComboCurrSel
Case "Flat"
UpdateSliders(aEQ_Flat())
Case "Pop"
UpdateSliders(aEQ_Pop())
Case "Rock"
UpdateSliders(aEQ_Rock())
Case "Jazz"
UpdateSliders(aEQ_Jazz())
Case "Classical"
UpdateSliders(aEQ_Classical())
Case "Bass"
UpdateSliders(aEQ_Bass())
Case "Vocal Boost"
UpdateSliders(aEQ_VocalBoost())
Case "Electronic"
UpdateSliders(aEQ_Electronic())
End Select
End Select
End Select
Case WM_VSCROLL '''TRACKBARS
Dim As Long iSliderPos
Select Case lParam '...'
Case aSlider_EQ(0)
iSliderPos = -SendMessage(aSlider_EQ(0), TBM_GETPOS, 0, 0)
If IsDlgButtonChecked(hWND_EQ, GetDlgCtrlID(hCheckBox_EQ)) Then
UpdateEQ(0, iSliderPos)
EndIf
Case aSlider_EQ(1)
iSliderPos = -SendMessage(aSlider_EQ(1), TBM_GETPOS, 0, 0)
If IsDlgButtonChecked(hWND_EQ, GetDlgCtrlID(hCheckBox_EQ)) Then
UpdateEQ(1, iSliderPos)
EndIf
Case aSlider_EQ(2)
iSliderPos = -SendMessage(aSlider_EQ(2), TBM_GETPOS, 0, 0)
If IsDlgButtonChecked(hWND_EQ, GetDlgCtrlID(hCheckBox_EQ)) Then
UpdateEQ(2, iSliderPos)
EndIf
Case aSlider_EQ(3)
iSliderPos = -SendMessage(aSlider_EQ(3), TBM_GETPOS, 0, 0)
If IsDlgButtonChecked(hWND_EQ, GetDlgCtrlID(hCheckBox_EQ)) Then
UpdateEQ(3, iSliderPos)
EndIf
Case aSlider_EQ(4)
iSliderPos = -SendMessage(aSlider_EQ(4), TBM_GETPOS, 0, 0)
If IsDlgButtonChecked(hWND_EQ, GetDlgCtrlID(hCheckBox_EQ)) Then
UpdateEQ(4, iSliderPos)
EndIf
Case aSlider_EQ(5)
iSliderPos = -SendMessage(aSlider_EQ(5), TBM_GETPOS, 0, 0)
If IsDlgButtonChecked(hWND_EQ, GetDlgCtrlID(hCheckBox_EQ)) Then
UpdateEQ(5, iSliderPos)
EndIf
Case aSlider_EQ(6)
iSliderPos = -SendMessage(aSlider_EQ(6), TBM_GETPOS, 0, 0)
If IsDlgButtonChecked(hWND_EQ, GetDlgCtrlID(hCheckBox_EQ)) Then
UpdateEQ(6, iSliderPos)
EndIf
Case aSlider_EQ(7)
iSliderPos = -SendMessage(aSlider_EQ(7), TBM_GETPOS, 0, 0)
If IsDlgButtonChecked(hWND_EQ, GetDlgCtrlID(hCheckBox_EQ)) Then
UpdateEQ(7, iSliderPos)
EndIf
Case aSlider_EQ(8)
iSliderPos = -SendMessage(aSlider_EQ(8), TBM_GETPOS, 0, 0)
If IsDlgButtonChecked(hWND_EQ, GetDlgCtrlID(hCheckBox_EQ)) Then
UpdateEQ(8, iSliderPos)
EndIf
Case aSlider_EQ(9)
iSliderPos = -SendMessage(aSlider_EQ(9), TBM_GETPOS, 0, 0)
If IsDlgButtonChecked(hWND_EQ, GetDlgCtrlID(hCheckBox_EQ)) Then
UpdateEQ(9, iSliderPos)
EndIf
End Select
End Select
End If
Return DefWindowProc(hWnd, uMsg, wParam, lParam)
End Function
Equalizer()
Because you get the address of a WString string using StrPtr, then the String string is: "F", Chr(0), "l", Chr(0), "a", Chr(0), "t", Chr(0). The String string runs up to the first Chr(0) and the resulting String string is "F".