36
36
ATOM MainWnd::wnd_class_ = 0 ;
37
37
const wchar_t MainWnd::kClassName [] = L" WebRTC_MainWnd" ;
38
38
39
+ using talk_base::sprintfn;
40
+
39
41
namespace {
40
42
41
43
const char kConnecting [] = " Connecting... " ;
@@ -79,10 +81,15 @@ void AddListBoxItem(HWND listbox, const std::string& str, LPARAM item_data) {
79
81
80
82
} // namespace
81
83
82
- MainWnd::MainWnd ()
84
+ MainWnd::MainWnd (const char * server, int port, bool auto_connect,
85
+ bool auto_call)
83
86
: ui_(CONNECT_TO_SERVER), wnd_(NULL ), edit1_(NULL ), edit2_(NULL ),
84
87
label1_(NULL ), label2_(NULL ), button_(NULL ), listbox_(NULL ),
85
- destroyed_(false ), callback_(NULL ), nested_msg_(NULL ) {
88
+ destroyed_(false ), callback_(NULL ), nested_msg_(NULL ),
89
+ server_(server), auto_connect_(auto_connect), auto_call_(auto_call) {
90
+ char buffer[10 ] = {0 };
91
+ sprintfn (buffer, sizeof (buffer), " %i" , port);
92
+ port_ = buffer;
86
93
}
87
94
88
95
MainWnd::~MainWnd () {
@@ -158,6 +165,9 @@ void MainWnd::SwitchToConnectUI() {
158
165
ui_ = CONNECT_TO_SERVER;
159
166
LayoutConnectUI (true );
160
167
::SetFocus (edit1_);
168
+
169
+ if (auto_connect_)
170
+ ::PostMessage (button_, BM_CLICK, 0 , 0 );
161
171
}
162
172
163
173
void MainWnd::SwitchToPeerList (const Peers& peers) {
@@ -173,6 +183,19 @@ void MainWnd::SwitchToPeerList(const Peers& peers) {
173
183
ui_ = LIST_PEERS;
174
184
LayoutPeerListUI (true );
175
185
::SetFocus (listbox_);
186
+
187
+ if (auto_call_ && peers.begin () != peers.end ()) {
188
+ // Get the number of items in the list
189
+ LRESULT count = ::SendMessage (listbox_, LB_GETCOUNT, 0 , 0 );
190
+ if (count != LB_ERR) {
191
+ // Select the last item in the list
192
+ LRESULT selection = ::SendMessage (listbox_, LB_SETCURSEL , count - 1 , 0 );
193
+ if (selection != LB_ERR)
194
+ ::PostMessage (wnd_, WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(listbox_),
195
+ LBN_DBLCLK),
196
+ reinterpret_cast<LPARAM>(listbox_));
197
+ }
198
+ }
176
199
}
177
200
178
201
void MainWnd::SwitchToStreamingUI () {
@@ -465,8 +488,8 @@ void MainWnd::CreateChildWindows() {
465
488
CreateChildWindow (&listbox_, LISTBOX_ID, L" ListBox" ,
466
489
LBS_HASSTRINGS | LBS_NOTIFY, WS_EX_CLIENTEDGE);
467
490
468
- ::SetWindowTextA (edit1_, GetDefaultServerName() .c_str());
469
- ::SetWindowTextA (edit2_, " 8888 " );
491
+ ::SetWindowTextA (edit1_, server_ .c_str());
492
+ ::SetWindowTextA (edit2_, port_.c_str() );
470
493
}
471
494
472
495
void MainWnd::LayoutConnectUI (bool show) {
0 commit comments