Wt::WWidget *FormWidgets::comboBox() { Wt::WTemplate *result = new TopicTemplate("forms-comboBox"); result->bindWidget("ComboBox", ComboBox()); result->bindWidget("ComboBoxActivated", ComboBoxActivated()); result->bindWidget("ComboBoxModel", ComboBoxModel()); return result; }
MRESULT LoadWizard::DlgProc(ULONG msg, MPARAM mp1, MPARAM mp2) { switch (msg) {case WM_INITDLG: { MRESULT ret = IntrospectBase::DlgProc(msg, mp1, mp2); SetTitle(Title); if (Configuration.SourceServer) { ComboBox(+GetCtrl(CB_SERVER)).Text(Configuration.SourceServer); PostMsg(UM_CONNECT, 0, 0); } if (Configuration.Source) PMRASSERT(WinSetDlgItemText(GetHwnd(), CB_SINKSRC, Configuration.Source)); if (Configuration.SourcePort) PMRASSERT(WinSetDlgItemText(GetHwnd(), CB_PORT, Configuration.SourcePort)); // Init rate spin button { SpinButton sb(GetCtrl(SB_RATE)); sb.SetArray(SamplingRates, sizeof SamplingRates/sizeof *SamplingRates); size_t pos; if ( !binary_search<const char,const int>(Configuration.SourceRate, pos, &SamplingRates[0], sizeof SamplingRates/sizeof *SamplingRates, &SamplingRateCmp) && ( pos == sizeof SamplingRates/sizeof *SamplingRates || (pos && 2*Configuration.SourceRate < atoi(SamplingRates[pos]) + atoi(SamplingRates[pos-1])) )) --pos; sb.Value(pos); } WinCheckButton(GetHwnd(), Configuration.SourceChannels == 1 ? RB_MONO : RB_STEREO, TRUE); return ret; } case WM_COMMAND: DEBUGLOG(("LoadWizard::DlgProc:WM_COMMAND(%i,%i, %p)\n", SHORT1FROMMP(mp1), SHORT2FROMMP(mp1), mp2)); switch (SHORT1FROMMP(mp1)) {case DID_OK: { Configuration.SourceServer = WinQueryDlgItemXText(GetHwnd(), CB_SERVER); const xstring& source = WinQueryDlgItemXText(GetHwnd(), CB_SINKSRC); Configuration.Source = source.length() && !source.startsWithI("default") ? source : xstring(); const xstring& port = WinQueryDlgItemXText(GetHwnd(), CB_PORT); Configuration.SourcePort = port.length() && !port.startsWithI("default") ? port : xstring(); Configuration.SourceRate = atoi(SamplingRates[SpinButton(GetCtrl(SB_RATE)).Value()]); Configuration.SourceChannels = WinQueryButtonCheckstate(GetHwnd(), RB_MONO) ? 1 : 2; } break; } break; case UM_DISCOVER_SERVER: { DEBUGLOG(("LoadWizard::DlgProc:UM_DISCOVER_SERVER\n")); try { Context.GetServerInfo(ServerInfoOp); Sources.clear(); Context.GetSourceInfo(SourceInfoOp); } catch (const PAException& ex) { WinSetDlgItemText(GetHwnd(), ST_STATUS, ex.GetMessage()); } return 0; } case UM_UPDATE_SERVER: { int error = LONGFROMMP(mp1); DEBUGLOG(("LoadWizard::DlgProc:UM_UPDATE_SERVER %i\n", error)); if (error) { WinSetDlgItemText(GetHwnd(), ST_STATUS, PAConnectException(Context.GetContext(), error).GetMessage()); return 0; } WinSetDlgItemText(GetHwnd(), ST_STATUS, "Success"); ComboBox cb(GetCtrl(CB_SINKSRC)); // save old value const xstring& oldsink = cb.Text(); // delete old list cb.DeleteAll(); SelectedSource = -1; // insert new list and restore old value if reasonable. xstring def; def.sprintf("default (%s)", Server.default_sink_name.cdata()); cb.InsertItem(def); if (Sources.size() != 0) { int defsink = -1; for (unsigned i = 0; i < Sources.size(); ++i) { PASourceInfo& source = *Sources[i]; cb.InsertItem(source.name); if (SelectedSource < 0 && source.name.compareToI(oldsink) == 0) SelectedSource = i; if (defsink < 0 && source.name.compareToI(Server.default_sink_name) == 0) defsink = i; } cb.Select(SelectedSource+1); if (SelectedSource < 0) SelectedSource = defsink; } } case UM_UPDATE_PORT: { DEBUGLOG(("LoadWizard::DlgProc:UM_UPDATE_PORT %i\n", SelectedSource)); ComboBox cb(GetCtrl(CB_PORT)); // save old value const xstring& oldport = cb.Text(); // delete old list cb.DeleteAll(); // insert new list and restore old value if reasonable. xstring def; int selected = -1; if ((unsigned)SelectedSource < Sources.size()) { PASourceInfo& source = *Sources[SelectedSource]; if (source.active_port) def.sprintf("default (%s)", source.active_port->name.cdata()); for (unsigned i = 0; i < source.ports.size(); ++i) { PAPortInfo& port = source.ports[i]; cb.InsertItem(port.name); if (selected < 0 && port.name.compareToI(oldport) == 0) selected = i; } } cb.InsertItem(def ? def.cdata() : "default", 0); cb.Select(selected+1); return 0; } } return IntrospectBase::DlgProc(msg, mp1, mp2); }
MRESULT ConfigDialog::DlgProc(ULONG msg, MPARAM mp1, MPARAM mp2) { switch (msg) {case WM_INITDLG: { MRESULT ret = IntrospectBase::DlgProc(msg, mp1, mp2); if (Configuration.Sink) PMRASSERT(WinSetDlgItemText(GetHwnd(), CB_SINKSRC, Configuration.Sink)); if (Configuration.SinkPort) PMRASSERT(WinSetDlgItemText(GetHwnd(), CB_PORT, Configuration.SinkPort)); // Set current value if (Configuration.SinkServer) { ComboBox(+GetCtrl(CB_SERVER)).Text(Configuration.SinkServer); PostMsg(UM_CONNECT, 0, 0); } SpinButton sb(GetCtrl(SB_MINLATENCY)); sb.SetLimits(0, 5000, 4); sb.Value(Configuration.SinkMinLatency); sb = SpinButton(GetCtrl(SB_MAXLATENCY)); sb.SetLimits(100, 10000, 4); sb.Value(Configuration.SinkMaxLatency); return ret; } case WM_COMMAND: DEBUGLOG(("ConfigDialog::DlgProc:WM_COMMAND(%i,%i, %p)\n", SHORT1FROMMP(mp1), SHORT2FROMMP(mp1), mp2)); switch (SHORT1FROMMP(mp1)) {case DID_OK: { Configuration.SinkServer = WinQueryDlgItemXText(GetHwnd(), CB_SERVER); const xstring& sink = WinQueryDlgItemXText(GetHwnd(), CB_SINKSRC); Configuration.Sink = sink.length() && !sink.startsWithI("default") ? sink : xstring(); const xstring& port = WinQueryDlgItemXText(GetHwnd(), CB_PORT); Configuration.SinkPort = port.length() && !port.startsWithI("default") ? port : xstring(); Configuration.SinkMinLatency = SpinButton(GetCtrl(SB_MINLATENCY)).Value(); Configuration.SinkMaxLatency = SpinButton(GetCtrl(SB_MAXLATENCY)).Value(); } break; } break; case UM_DISCOVER_SERVER: { DEBUGLOG(("ConfigDialog::DlgProc:UM_DISCOVER_SERVER\n")); try { Context.GetServerInfo(ServerInfoOp); Sinks.clear(); Context.GetSinkInfo(SinkInfoOp); } catch (const PAException& ex) { WinSetDlgItemText(GetHwnd(), ST_STATUS, ex.GetMessage()); } return 0; } case UM_UPDATE_SERVER: { int error = LONGFROMMP(mp1); DEBUGLOG(("ConfigDialog::DlgProc:UM_UPDATE_SERVER %i\n", error)); if (error) { WinSetDlgItemText(GetHwnd(), ST_STATUS, PAConnectException(Context.GetContext(), error).GetMessage()); return 0; } WinSetDlgItemText(GetHwnd(), ST_STATUS, "Success"); ComboBox cb(GetCtrl(CB_SINKSRC)); // save old value const xstring& oldsink = cb.Text(); // delete old list cb.DeleteAll(); SelectedSink = -1; // insert new list and restore old value if reasonable. xstring def; def.sprintf("default (%s)", Server.default_sink_name.cdata()); cb.InsertItem(def); if (Sinks.size() != 0) { int defsink = -1; for (unsigned i = 0; i < Sinks.size(); ++i) { PASinkInfo& sink = *Sinks[i]; cb.InsertItem(sink.name); if (SelectedSink < 0 && sink.name.compareToI(oldsink) == 0) SelectedSink = i; if (defsink < 0 && sink.name.compareToI(Server.default_sink_name) == 0) defsink = i; } cb.Select(SelectedSink+1); if (SelectedSink < 0) SelectedSink = defsink; } } case UM_UPDATE_PORT: { DEBUGLOG(("ConfigDialog::DlgProc:UM_UPDATE_PORT %i\n", SelectedSink)); ComboBox cb(GetCtrl(CB_PORT)); // save old value const xstring& oldport = cb.Text(); // delete old list cb.DeleteAll(); // insert new list and restore old value if reasonable. xstring def; int selected = -1; if ((unsigned)SelectedSink < Sinks.size()) { PASinkInfo& sink = *Sinks[SelectedSink]; if (sink.active_port) def.sprintf("default (%s)", sink.active_port->name.cdata()); for (unsigned i = 0; i < sink.ports.size(); ++i) { PAPortInfo& port = sink.ports[i]; cb.InsertItem(port.name); if (selected < 0 && port.name.compareToI(oldport) == 0) selected = i; } } cb.InsertItem(def ? def.cdata() : "default", 0); cb.Select(selected+1); return 0; } } return IntrospectBase::DlgProc(msg, mp1, mp2); }
//Entry point of the program int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow) { //Create a window cWindow = Window(WindowProcedure, hThisInstance, "MealTrackApp", nCmdShow); cWindow.Create("MealTrack - Untitled", 462, 375); //Actually create the button with the window as its parent RECT rEditBox = {16, 280, 272, 24}; cEditBox = EditBox(cWindow, rEditBox, "Disconnected"); cEditBox.SetReadOnly(1); //Create the Button RECT rButton = {304, 280, 128, 24}; cButton = Button(cWindow, rButton, "Start Meal", IDR_START_BUTTON); cButton.SetEnabled(0); //Create the listbox RECT rListBox = {16, 16, 272, 272}; cListBox = ListBox(cWindow, rListBox, "MealListBox"); //Meal wait box RECT rLabelDelay = {304, 16, 128, 16}; RECT rEditDelay = {304, 32, 128, 24}; cLabelDelay = Label(cWindow, rLabelDelay, "Meal wait (seconds)"); cEditDelay = EditBox(cWindow, rEditDelay, "10"); //Create Date format box RECT rLabelDate = {304, 64, 128, 16}; RECT rComboDate = {304, 80, 128, 24}; cLabelDate = Label(cWindow, rLabelDate, "Date format"); cComboDate = ComboBox(cWindow, rComboDate, "ComboBoxDate"); cComboDate.AddItem("12 Hour AM/PM"); cComboDate.AddItem("24 Hour"); cComboDate.SetDefaultItem(1); //Record format box RECT rLabelRecord = {304, 112, 128, 16}; RECT rComboRecord = {304, 128, 128, 24}; cLabelRecord = Label(cWindow, rLabelRecord, "Record change type"); cComboRecord = ComboBox(cWindow, rComboRecord, "ComboBoxRecord"); cComboRecord.AddItem("Increases"); cComboRecord.AddItem("Decreases"); cComboRecord.AddItem("Both"); cComboRecord.SetDefaultItem(1); //Record format box RECT rLabelSensitivity = {304, 160, 128, 16}; RECT rComboSensitivity = {304, 176, 128, 24}; cLabelSensitivity = Label(cWindow, rLabelSensitivity, "Sensitivity"); cComboSensitivity = ComboBox(cWindow, rComboSensitivity, "ComboBoxSensitivity"); cComboSensitivity.AddItem("0.01 g"); cComboSensitivity.AddItem("0.02 g"); cComboSensitivity.AddItem("0.03 g"); cComboSensitivity.AddItem("0.04 g"); cComboSensitivity.AddItem("0.05 g"); cComboSensitivity.AddItem("0.06 g"); cComboSensitivity.AddItem("0.07 g"); cComboSensitivity.AddItem("0.08 g"); cComboSensitivity.AddItem("0.09 g"); cComboSensitivity.SetDefaultItem(2); //Custom function to creeate window CreateWindowMenu(cWindow); //Message loop MSG msg; while (cWindow.GetMessage(&msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } // The program return-value is 0 - The value that PostQuitMessage() gave return msg.wParam; }