void simple_thread_worker::threadProc() { pfc::tickcount_t last_tick = pfc::getTickCount(); while (WaitForSingleObject(simple_thread_pool::instance().exiting_, 0) == WAIT_TIMEOUT) { if (WaitForSingleObject(simple_thread_pool::instance().have_task_, 1000) == WAIT_OBJECT_0) { simple_thread_task* task = simple_thread_pool::instance().acquire_task(); if (task) { task->run(); simple_thread_pool::instance().untrack(task); last_tick = pfc::getTickCount(); continue; } } if (pfc::getTickCount() - last_tick >= 10000) { insync(simple_thread_pool::instance().cs_); if (simple_thread_pool::instance().is_queue_empty()) { simple_thread_pool::instance().remove_worker_(this); return; } } } simple_thread_pool::instance().remove_worker_(this); }
void threaded_process_v2_t::resize() { t_size height = 11 + 11; if (m_flags & flag_show_text) height += m_titlefont_height + 7; if (1) height += 15; if (m_flags & flag_show_button) height += m_textfont_height + 10 + 11 + 11;//23; { insync(m_sync); if (m_detail_entries.get_count()) height += m_textfont_height*m_detail_entries.get_count() + 5; } RECT rc = { 0, 0, 450, height }; AdjustWindowRectEx(&rc, WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE | WS_CAPTION | WS_SYSMENU, false, NULL); int cx = progress_width + 11 * 2 + 11 * 2 + RECT_CX(rc) - 450; int cy = RECT_CY(rc); RECT rc_current = { 0 }; GetWindowRect(get_wnd(), &rc_current); if (RECT_CX(rc_current) != cx || RECT_CY(rc_current) != cy) { m_window_cx = cx; m_window_cy = cy; //SendMessage(get_wnd(), WM_CANCELMODE, NULL, NULL); SetWindowPos(get_wnd(), NULL, NULL, NULL, cx, cy, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE); } }
void console_receiver_impl::print(const char * p_message, unsigned p_message_length) { console_entry entry; entry.init(p_message, p_message_length); insync(g_lock); g_message_list.add_item(entry); g_entry_added_locked(); }
void simple_thread_pool::untrack(simple_thread_task* task) { insync(cs_); task_list_.remove_item(task); delete task; if (is_queue_empty()) ResetEvent(have_task_); }
void simple_thread_pool::track(simple_thread_task* task) { insync(cs_); bool empty = is_queue_empty(); task_list_.add_item(task); if (empty) SetEvent(have_task_); }
create_object_func_t get_func () { static critical_section m_section; static library g_dll; static create_object_func_t g_proc = nullptr; insync (m_section); if (g_dll.is_loaded ()) { if (g_proc) return g_proc; else if (!g_dll.free ()) throw exception_dll_unload (); g_proc = nullptr; } pfc::string8 path, triedPaths; auto try_folder = [&] (const char *folder) { path = folder; if (!path.ends_with ('\\')) path.add_char ('\\'); path += "7z.dll"; triedPaths += path; triedPaths.add_char ('\n'); g_dll.load (path); }; // 1. look in component's installation folder try_folder (pfc::string_directory (core_api::get_my_full_path ())); // 2. search for 7-zip installation folder HKEY key; if (RegOpenKeyEx (HKEY_CURRENT_USER, L"Software\\7-Zip", 0, KEY_READ, &key) == ERROR_SUCCESS) { DWORD value_size = 0, dummy = 0; LONG res = RegQueryValueEx (key, TEXT ("Path"), nullptr, &dummy, nullptr, &value_size); if (res == ERROR_SUCCESS || res == ERROR_MORE_DATA) { pfc::array_t<TCHAR> tmp; tmp.set_size (value_size + 1); res = RegQueryValueEx (key, TEXT ("Path"), nullptr, &dummy, (LPBYTE)tmp.get_ptr (), &value_size); if (res == ERROR_SUCCESS) try_folder (pfc::stringcvt::string_ansi_from_wide (tmp.get_ptr ())); } RegCloseKey (key); } if (g_dll.is_loaded ()) { debug_log () << "Loaded \"" << path << "\""; g_proc = g_dll.get_proc (); if (g_proc == nullptr) throw exception_dll_func_not_found (); else return g_proc; } else { error_log () << "Couldn't load 7z.dll. Tried:\n" << triedPaths; throw exception_dll_not_loaded (); } }
void simple_thread_pool::remove_worker_(simple_thread_worker* worker) { InterlockedDecrement(&num_workers_); insync(cs_); if (num_workers_ == 0) SetEvent(empty_worker_); static_api_ptr_t<main_thread_callback_manager>()->add_callback( new service_impl_t<simple_thread_worker_remover>(worker)); }
void simple_thread_pool::untrack_all() { insync(cs_); for (t_task_list::iterator iter = task_list_.first(); iter.is_valid(); ++iter) { task_list_.remove(iter); delete *iter; } ResetEvent(have_task_); }
void monitor_stop( const DUH_SIGRENDERER * p_sigrenderer ) { insync( lock ); if ( song_renderer == p_sigrenderer ) { song_data = 0; song_renderer = 0; changed_info = true; path = ""; channels_allowed = 0; } }
simple_thread_task* simple_thread_pool::acquire_task() { insync(cs_); t_task_list::iterator iter = task_list_.first(); if (iter.is_valid()) { task_list_.remove(iter); } if (is_queue_empty()) ResetEvent(have_task_); return iter.is_valid() ? *iter : NULL; }
void monitor_update( DUH_SIGRENDERER * p_sigrenderer ) { insync( lock ); if ( song_renderer == p_sigrenderer ) { if ( changed_controls ) { changed_controls = false; bool enabled = !!cfg_control_override; t_uint64 mask = enabled ? mute_mask : 0; mute_channels( mask ); } } }
void threaded_process_v2_t::on_size(t_size cx, t_size cy) { RedrawWindow(get_wnd(), NULL, NULL, RDW_INVALIDATE); HDWP dwp = BeginDeferWindowPos(2); t_size y_progress = 11; if (m_flags & flag_show_text) y_progress += 7 + m_titlefont_height; { insync(m_sync); if (m_detail_entries.get_count()) y_progress += m_textfont_height*m_detail_entries.get_count() + 5; } dwp = DeferWindowPos(dwp, m_wnd_progress, NULL, 11 * 2, y_progress, cx - 11 * 2 - 11 * 2, 15, SWP_NOZORDER); if (m_wnd_button) dwp = DeferWindowPos(dwp, m_wnd_button, NULL, cx - 11 * 2 - 73, y_progress + 15 + 11 + 11, 73, m_textfont_height + 10, SWP_NOZORDER); EndDeferWindowPos(dwp); }
bool simple_thread_pool::enqueue(simple_thread_task* task) { if (WaitForSingleObject(exiting_, 0) == WAIT_OBJECT_0) return false; insync(cs_); int max_count = pfc::getOptimalWorkerThreadCount(); track(task); if (num_workers_ < max_count) { simple_thread_worker* worker = new simple_thread_worker; add_worker_(worker); worker->start(); } return true; }
void artwork_reader_manager_ng_t::request_nocover_image (pfc::rcptr_t< gdi_object_t<HBITMAP>::ptr_t > &p_out, t_size cx, t_size cy, COLORREF cr_back, bool b_reflection, abort_callback & p_abort) { insync (m_nocover_sync); if (m_nocover_bitmap.is_valid() && m_nocover_bitmap->is_valid() && m_nocover_cx == cx && m_nocover_cy == cy) p_out = m_nocover_bitmap; else { HBITMAP bm = g_get_nocover_bitmap(cx, cy, cr_back, b_reflection, p_abort); if (bm) { m_nocover_bitmap = pfc::rcnew_t< gdi_object_t<HBITMAP>::ptr_t >(bm); p_out = m_nocover_bitmap; m_nocover_cx = cx; m_nocover_cy = cy; } } }
void monitor_start( DUMB_IT_SIGDATA * p_sigdata, DUH_SIGRENDERER * p_sigrenderer, const char * p_path, bool playback ) { insync( lock ); if ( playback ) { changed_info = true; song_data = p_sigdata; song_renderer = p_sigrenderer; path = p_path; initialize_channels(); } if ( cfg_control_override ) { mute_channels( mute_mask ); } }
static void g_on_message_received(const char * ptr, t_size len) //from any thread { insync(sync); pfc::string8 buffer; /** Sort out line break messes */ { const char * start = ptr; const char * pos = ptr; while (t_size(pos-ptr)<len && *pos) { while (t_size(pos-ptr+1)<len && pos[1] && pos[0] != '\n') pos++; { if (pos[0] == '\n') buffer.add_string(start, pos-start-( (pos>ptr && (pos[-1]) == '\r') ?1:0)); else buffer.add_string(start, pos+1-start); buffer.add_byte('\r'); buffer.add_byte('\n'); //if ((pos-ptr)<len && *pos) { start=pos+1; pos++; } } } } if (g_messages.add_item(t_message(buffer.get_ptr(), buffer.get_length())) == maximum_messages) /** Inefficient, yes. Fix one day */ g_messages.remove_by_idx(0); /** Post a notification to all instances of the panel to update their display */ unsigned n , count = g_notify_list.get_count(); for (n=0;n<count;n++) { HWND wnd = g_notify_list[n]; if (wnd) PostMessage(wnd, MSG_UPDATE, 0, 0); } };
void config_object_impl::set_data(stream_reader * p_stream,abort_callback & p_abort,bool p_notify) { core_api::ensure_main_thread(); { insync(m_sync); m_data.set_size(0); enum {delta = 1024}; t_uint8 buffer[delta]; for(;;) { t_size delta_done = p_stream->read(buffer,delta,p_abort); if (delta_done > 0) { m_data.append_fromptr(buffer,delta_done); } if (delta_done != delta) break; } } if (p_notify) config_object_notify_manager::g_on_changed(this); }
LRESULT console_window::on_message(HWND wnd,UINT msg,WPARAM wp,LPARAM lp) { switch(msg) { case WM_CREATE: { /** * Store a pointer to ourselve in this list, used for global notifications (in the main thread) * which updates instances of our panel. */ list_wnd.add_item(this); { insync(sync); /** Store a window handle in this list, used in global notifications (in any thread) which * updates the panels */ g_notify_list.add_item(wnd); } long flags = 0; if (cfg_frame == 1) flags |= WS_EX_CLIENTEDGE; else if (cfg_frame == 2) flags |= WS_EX_STATICEDGE; /** Create our edit window */ wnd_edit = CreateWindowEx(flags, WC_EDIT, _T(""), WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOVSCROLL | WS_VSCROLL | ES_READONLY | ES_MULTILINE, 0, 0, 0, 0, wnd, HMENU(IDC_EDIT), core_api::get_my_instance(), NULL); if (wnd_edit) { if (g_font) { /** Nth, n>1, instance; use exisiting font handle */ SendMessage(wnd_edit,WM_SETFONT,(WPARAM)g_font,MAKELPARAM(0,0)); } else /** First window - create the font handle */ g_update_all_fonts(); /** Store a pointer to ourself in the user data field of the edit window */ SetWindowLongPtr(wnd_edit,GWL_USERDATA,(LPARAM)(this)); /** Subclass the edit window */ m_editproc = (WNDPROC)SetWindowLongPtr(wnd_edit,GWL_WNDPROC,(LPARAM)(hook_proc)); SendMessage(wnd, MSG_UPDATE, 0, 0); } } break; /** Update the edit window's text */ case MSG_UPDATE: { insync(sync); pfc::string8_fastalloc buffer; buffer.prealloc(1024); unsigned n, count = g_messages.get_count(); for (n=0; n<count; n++) { buffer << "[" << pfc::format_int(g_messages[n].m_time.wHour, 2) << ":" << pfc::format_int(g_messages[n].m_time.wMinute, 2) << ":" << pfc::format_int(g_messages[n].m_time.wSecond, 2) << "] " << g_messages[n].m_message; #if 0 buffer.add_string(pfc::string_printf("[%02u:%02u:%02u] ",(unsigned)g_messages[n].m_time.wHour ,(unsigned)g_messages[n].m_time.wMinute ,(unsigned)g_messages[n].m_time.wSecond)); buffer.add_string(g_messages[n].m_message); //if (n != count-1) // buffer.add_string("\r\n",2); #endif } uSetWindowText(wnd_edit, buffer); LONG_PTR len = SendMessage(wnd_edit, EM_GETLINECOUNT , 0, 0); SendMessage(wnd_edit, EM_LINESCROLL , 0, len); } break; case WM_GETMINMAXINFO: break; case WM_SIZE: /** Reposition the edit window. */ SetWindowPos(wnd_edit, 0, 0, 0, LOWORD(lp), HIWORD(lp), SWP_NOZORDER); break; case WM_ERASEBKGND: return FALSE; case WM_DESTROY: { wnd_edit=0; list_wnd.remove_item(this); SendMessage(wnd_edit,WM_SETFONT,NULL,MAKELPARAM(0,0)); if (list_wnd.get_count() == 0) { DeleteFont(g_font); g_font = 0; } { insync(sync); g_notify_list.remove_item(wnd); } } break; } return DefWindowProc(wnd, msg, wp, lp); }
BOOL dialog_proc( HWND wnd, UINT msg, WPARAM wp, LPARAM lp ) { switch ( msg ) { case WM_INITDIALOG: { this->wnd = wnd; uSendDlgItemMessage( wnd, IDC_OVERRIDE, BM_SETCHECK, cfg_control_override, 0 ); { insync( lock ); changed_info = false; changed_controls = false; update(); } SetTimer( wnd, 0, 100, 0 ); cfg_placement.on_window_creation(wnd); } return 1; case WM_TIMER: { insync( lock ); if ( changed_info ) { changed_info = false; update(); } } break; case WM_DESTROY: { cfg_placement.on_window_destruction( wnd ); KillTimer( wnd, 0 ); uSetWindowLong( wnd, DWL_USER, 0 ); delete this; dialog = 0; } break; case WM_COMMAND: if ( wp == IDCANCEL ) { DestroyWindow( wnd ); } else if ( wp == IDC_OVERRIDE ) { insync( lock ); cfg_control_override = uSendMessage((HWND)lp,BM_GETCHECK,0,0); BOOL enable = song_renderer != 0 && cfg_control_override; for ( unsigned i = 0, j = DUMB_IT_N_CHANNELS; i < j; ++i ) { EnableWindow( GetDlgItem( wnd, IDC_VOICE1 + i ), enable ); } changed_controls = true; } else if ( wp == IDC_RESET ) { insync( lock ); changed_controls = mute_mask != 0; mute_mask = 0; if ( changed_controls ) { update(); } } else if ( wp - IDC_VOICE1 < DUMB_IT_N_CHANNELS ) { unsigned voice = wp - IDC_VOICE1; t_uint64 mask = ~(1 << voice); t_uint64 bit = uSendMessage((HWND)lp,BM_GETCHECK,0,0) ? 0 : ( 1 << voice ); insync( lock ); changed_controls = true; mute_mask = ( mute_mask & mask ) | bit; } break; } return 0; }
BOOL t_config_tab3::DialogProc(HWND wnd, UINT msg, WPARAM wp, LPARAM lp) { switch (msg) { case WM_INITDIALOG: { m_initialising = true; m_wnd_enabled = GetDlgItem(wnd, IDC_ENABLED); Button_SetCheck(m_wnd_enabled, settings::mobile_devices_enabled ? BST_CHECKED : BST_UNCHECKED); m_initialising = false; } break; case WM_COMMAND: switch (wp) { case IDC_ENABLED | (BN_CLICKED << 16) : settings::mobile_devices_enabled = Button_GetCheck(m_wnd_enabled) == BST_CHECKED; break; #if 0 case IDC_DIR: { string_utf8_from_window dir(wnd, IDC_PATH); pfc::string8 dir_can, output; try { filesystem::g_get_canonical_path(dir, dir_can); directory_callback_full_impl list(false); filesystem::g_list_directory(dir_can, list, abort_callback_dummy()); t_size i, count = list.get_count(); for (i = 0; i<count; i++) { if (list[i].m_subdir) output << "<dir> "; output << list[i].m_path; //output << " " << list[i].m_stats.m_size; //if (list[i].m_stats.m_timestamp != filetimestamp_invalid) // output << " " << format_filetimestamp(list[i].m_stats.m_timestamp); output << "\r\n"; } } catch (const pfc::exception & ex) { output << "\r\nError: " << ex.what(); } uSendDlgItemMessageText(wnd, IDC_OUTPUT, WM_SETTEXT, NULL, output.get_ptr()); } break; case IDC_STATS: { pfc::string8 output; try { pfc::list_t<stats_t> stats; g_get_stats_list(string_utf8_from_window(wnd, IDC_PATH), stats); t_size i, count = stats.get_count(); for (i = 0; i<count; i++) output << stats[i].name << "=" << stats[i].value << "\r\n"; } catch (const pfc::exception & ex) { output << "\r\nError: " << ex.what(); } uSendDlgItemMessageText(wnd, IDC_OUTPUT, WM_SETTEXT, NULL, output.get_ptr()); } break; case IDC_TEST: { //console::formatter() << pfc::format_hex(IOCTL_SCSI_PASS_THROUGH); mobile_device_api_t::ptr api = g_get_mobile_device_api(); mobile_device_api_t::device_handle_t::ptr handle; if (api.is_valid() && api->is_initialised()) { { insync(api->m_devices_sync); if (api->m_devices.get_count()) handle = api->m_devices[0]; } if (handle.is_valid()) { try { pfc::string8 msg; CFTypeRef ref = NULL; msg << "\r\n1:\r\n"; ref = api->AMDeviceCopyValue(api->m_devices[0]->m_device, api->_CFSTR("com.apple.mobile.iTunes"), NULL); msg << "Ref: " << pfc::format_hex((t_uint64)ref, 8) << "\r\n"; if (ref) { g_print_CFTypeRef(api, ref, msg); api->CFRelease(ref); ref = NULL; } msg << "\r\n2:\r\n"; ref = api->AMDeviceCopyValue(api->m_devices[0]->m_device, NULL, NULL); msg << "Ref: " << pfc::format_hex((t_uint64)ref, 8) << "\r\n"; if (ref) { g_print_CFTypeRef(api, ref, msg); api->CFRelease(ref); ref = NULL; } msg << "\r\n3:\r\n"; ref = api->AMDeviceCopyValue(api->m_devices[0]->m_device, api->_CFSTR("com.apple.mobile.battery"), NULL); msg << "Ref: " << pfc::format_hex((t_uint64)ref, 8) << "\r\n"; if (ref) { g_print_CFTypeRef(api, ref, msg); api->CFRelease(ref); ref = NULL; } msg << "\r\n4:\r\n"; ref = api->AMDeviceCopyValue(api->m_devices[0]->m_device, api->_CFSTR("com.apple.disk_usage"), NULL); msg << "Ref: " << pfc::format_hex((t_uint64)ref, 8) << "\r\n"; if (ref) { g_print_CFTypeRef(api, ref, msg); api->CFRelease(ref); ref = NULL; } msg << "\r\n5:\r\n"; ref = api->AMDeviceCopyValue(api->m_devices[0]->m_device, api->_CFSTR("com.apple.mobile.sync_data_class"), NULL); msg << "Ref: " << pfc::format_hex((t_uint64)ref, 8) << "\r\n"; if (ref) { g_print_CFTypeRef(api, ref, msg); api->CFRelease(ref); ref = NULL; } msg << "\r\n6:\r\n"; ref = api->AMDeviceCopyValue(api->m_devices[0]->m_device, NULL, api->_CFSTR("DeviceClass")); msg << "Ref: " << pfc::format_hex((t_uint64)ref, 8) << "\r\n"; if (ref) { g_print_CFTypeRef(api, ref, msg); api->CFRelease(ref); ref = NULL; } msg << "\r\n7:\r\n"; ref = api->AMDeviceCopyValue(api->m_devices[0]->m_device, NULL, api->_CFSTR("DeviceName")); msg << "Ref: " << pfc::format_hex((t_uint64)ref, 8) << "\r\n"; if (ref) { g_print_CFTypeRef(api, ref, msg); api->CFRelease(ref); ref = NULL; } popup_message::g_show(msg, "Test Results"); //NULL //com.apple.mobile.iTunes //com.apple.mobile.battery //com.apple.disk_usage //com.apple.mobile.sync_data_class //DeviceClass //DeviceName } catch (const pfc::exception & ex) { popup_message::g_show(ex.what(), "Test Error"); } } } } break; #endif } break; case WM_DESTROY: m_wnd_enabled = NULL; break; } return FALSE; }
void config_object_impl::get_data(stream_writer * p_stream,abort_callback & p_abort) const { insync(m_sync); p_stream->write_object(m_data.get_ptr(),m_data.get_size(),p_abort); }
void simple_thread_pool::add_worker_(simple_thread_worker* worker) { insync(cs_); InterlockedIncrement(&num_workers_); ResetEvent(empty_worker_); }
void execute () { try { sock_.join (addr_); auto_ptr<LinkListener> ll (new LinkListener (sock_, in_link_data_)); { AutoLock lock (mutex_); // Loop // // while (true) { cond_.wait (&sync_schedule); // "Loop of Fairness" bool done = false; do { // control message // // if (!in_control_.empty ()) { done = true; break; } // outsync // // if (sync_schedule < ACE_OS::gettimeofday ()) { // OUTSYNC outsync (); // schedule next outsync sync_schedule = ACE_OS::gettimeofday () + ACE_Time_Value (0, Protocol::SYNC_PERIOD); } // link message // // if (!in_link_data_.empty ()) { MessagePtr m (in_link_data_.front ()); in_link_data_.pop (); std::type_info const* exp = &typeid (*m); if (exp == typeid (LinkFailure)) { // cerr << "link failure" << endl; throw false; } else if (exp == typeid (LinkData)) { LinkData* data = dynamic_cast<LinkData*> (m.get ()); // INSYNC, TL, CT // Filter out loopback. // if (ACE_OS::strcmp (data->header().member_id.id, id_) != 0) { insync (); transaction_list (); current_transaction (data->header().current, data->payload (), data->size ()); } } else { // cerr << "unknown message type from link listener: " // << typeid (*m).name () << endl; ACE_OS::abort (); } } // api message // // if (!in_data_.empty ()) { // API api (); } } while (!in_link_data_.empty() || sync_schedule < ACE_OS::gettimeofday ()); if (done) break; } } } catch (...) { // cerr << "Exception in scheduler loop." << endl; MessageQueueAutoLock lock (out_control_); out_control_.push (MessagePtr (new Failure)); } }
void ipod_action_manager::suspend_all() { insync (m_sync); for (t_size i = 0, count = m_actions.get_count(); i<count; i++) m_actions[i]->m_process.get_suspend().suspend(); }
bool simple_thread_pool::is_queue_empty() { insync(cs_); return task_list_.get_count() == 0; }
LRESULT threaded_process_v2_t::on_message(HWND wnd, UINT msg, WPARAM wp, LPARAM lp) { switch (msg) { case WM_TIMER: if (wp == 1) { ShowWindow(wnd, SW_SHOWNORMAL); KillTimer(wnd, 1); return 0; } else if (wp == 667) { KillTimer(wnd, 667); m_timer_active = false; RedrawWindow(wnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW); return 0; } break; case WM_NCCREATE: modeless_dialog_manager::g_add(wnd); break; case WM_SYSCOLORCHANGE: case WM_THEMECHANGED: refresh_title_font(); resize(); break; case WM_CREATE: { if (m_flags & flag_show_button) { m_textfont = uCreateIconFont(); m_textfont_height = uGetFontHeight(m_titlefont); } if (m_flags & flag_show_text) refresh_title_font(); uSetWindowText(wnd, m_title); //t_size y_progress = 11; //if (m_flags & flag_show_text) // y_progress+=5+uGetFontHeight(m_titlefont); //RECT rc; //GetClientRect(wnd, &rc); //m_wnd_caption = CreateWindowEx(0, WC_STATIC, L"STATIC", WS_CHILD|WS_VISIBLE, 0, 0, 0, 0, wnd, (HMENU)1001, core_api::get_my_instance(), NULL); m_wnd_progress = CreateWindowEx(0, PROGRESS_CLASS, L"PROGRESS", WS_SYSMENU | WS_CHILD | WS_VISIBLE | ((m_flags & flag_progress_marquee) ? 0x08 : 0) | PBS_SMOOTH | WS_GROUP, 0, 0, 0, 0, wnd, (HMENU)1002, core_api::get_my_instance(), NULL); if (0 == (m_flags & flag_progress_marquee)) SendMessage(m_wnd_progress, PBM_SETRANGE32, 0, progress_width/*m_range*/); else SendMessage(m_wnd_progress, WM_USER + 10, TRUE, 20); if (m_flags & flag_show_button) { m_wnd_button = CreateWindowEx(0, WC_BUTTON, L"Stop", WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_DEFPUSHBUTTON | WS_GROUP, 0, 0, 0, 0, wnd, (HMENU)IDCANCEL, core_api::get_my_instance(), NULL); SendMessage(m_wnd_button, WM_SETFONT, (WPARAM)m_textfont.get(), MAKELPARAM(1, 0)); //SetFocus(m_wnd_button); } else { HMENU menu = GetSystemMenu(wnd, FALSE); EnableMenuItem(menu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED); } resize(); if (m_flags & flag_no_delay) { ShowWindow(wnd, SW_SHOWNORMAL); } else { SetTimer(wnd, 1, 300, NULL); } on_init(); } return 0; case WM_SHOWWINDOW: if (wp == TRUE && lp == 0 && m_wnd_button) SetFocus(m_wnd_button); break; case WM_MOVING: { LPRECT lprc = (LPRECT)lp; lprc->right = lprc->left + m_window_cx; lprc->bottom = lprc->top + m_window_cy; } return TRUE; case DM_GETDEFID: if (m_flags & flag_show_button) return IDCANCEL | (DC_HASDEFID << 16); return 0; case WM_DESTROY: on_destroy_thread(); m_textfont.release(); m_titlefont.release(); return 0; case WM_NCDESTROY: modeless_dialog_manager::g_remove(wnd); break; case WM_CLOSE: m_abort.abort(); return 0; case WM_SETFOCUS: break; case WM_COMMAND: switch (wp) { case IDCANCEL: if (m_wnd_button) EnableWindow(m_wnd_button, FALSE); m_abort.abort(); return 0; } break; case WM_PAINT: { pfc::string8 p_text; pfc::array_t<detail_entry> p_detail_entries; { insync(m_sync); p_text = m_text; p_detail_entries = m_detail_entries; } PAINTSTRUCT ps; HDC dc = BeginPaint(wnd, &ps); if (dc) { RECT rc_client, rc_button; GetClientRect(wnd, &rc_client); RECT rc_fill = rc_client; if (m_wnd_button) { GetWindowRect(m_wnd_button, &rc_button); rc_fill.bottom -= RECT_CY(rc_button) + 9; rc_fill.bottom -= 11; } FillRect(dc, &rc_fill, GetSysColorBrush(COLOR_WINDOW)); if (m_wnd_button) { rc_fill.top = rc_fill.bottom; rc_fill.bottom += 1; FillRect(dc, &rc_fill, GetSysColorBrush(COLOR_3DLIGHT)); } rc_fill.top = rc_fill.bottom; rc_fill.bottom = rc_client.bottom; if (rc_fill.top < rc_fill.bottom) FillRect(dc, &rc_fill, GetSysColorBrush(COLOR_3DFACE)); if (m_flags & flag_show_text) { SetTextAlign(dc, TA_LEFT); SetBkMode(dc, TRANSPARENT); //SetTextColor(dc, m_titlecolour); RECT rc; GetClientRect(wnd, &rc); RECT rc2 = { 11 * 2, 11, RECT_CX(rc) - 11 * 2, m_titlefont_height + 11 }; //FillRect(dc, &rc2, GetSysColorBrush(COLOR_BTNFACE)); HFONT fnt_old = SelectFont(dc, m_titlefont); ui_helpers::text_out_colours_ellipsis(dc, p_text, p_text.get_length(), 0, 11, &rc2, false, false, m_titlecolour, ui_helpers::ALIGN_LEFT); //uExtTextOut(dc, 11*2, 11, ETO_CLIPPED, &rc2, m_text, m_text.get_length(), NULL); t_size detail_entry_count = 0; if (detail_entry_count = p_detail_entries.get_count()) { RECT rc3 = rc2; rc3.top = rc2.bottom + 7; rc3.bottom = rc3.top + m_textfont_height; //SetTextColor(dc, GetSysColor(COLOR_BTNTEXT)); SelectFont(dc, m_textfont); unsigned max_x = 0; for (t_size i = 0; i<detail_entry_count; i++) { unsigned last_x = 0; ui_helpers::text_out_colours_ellipsis(dc, p_detail_entries[i].m_label, p_detail_entries[i].m_label.get_length(), 0, rc3.top, &rc3, false, false, GetSysColor(COLOR_WINDOWTEXT), ui_helpers::ALIGN_LEFT, NULL, true, &last_x); max_x = max(last_x, max_x); rc3.top = rc3.bottom; rc3.bottom = rc3.top + m_textfont_height; //uExtTextOut(dc, 11*2, rc3.top, ETO_CLIPPED, &rc3, m_detail_entries[i].m_label, m_detail_entries[i].m_label.get_length(), NULL); } rc3.top = rc2.bottom + 7; rc3.bottom = rc3.top + m_textfont_height; rc3.left = max_x + 5; for (t_size i = 0; i<detail_entry_count; i++) { ui_helpers::text_out_colours_ellipsis(dc, p_detail_entries[i].m_value, p_detail_entries[i].m_value.get_length(), 0, rc3.top, &rc3, false, true, GetSysColor(COLOR_WINDOWTEXT), ui_helpers::ALIGN_LEFT); rc3.top = rc3.bottom; rc3.bottom = rc3.top + m_textfont_height; } } SelectFont(dc, fnt_old); } EndPaint(wnd, &ps); } } return 0; case MSG_REDRAW: resize(); if (!m_timer_active) { LARGE_INTEGER current = { 0 }, freq = { 0 }; QueryPerformanceCounter(¤t); QueryPerformanceFrequency(&freq); t_uint64 tenth = 5; if (m_time_last_redraw.QuadPart) { tenth = (current.QuadPart - m_time_last_redraw.QuadPart) / (freq.QuadPart / 100); } if (tenth < 10) { SetTimer(get_wnd(), 667, 100 - t_uint32(tenth) * 10, NULL); m_timer_active = true; } else RedrawWindow(wnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW); } return 0; case MSG_UPDATE_PROGRESS: if (abs((int)(wp - SendMessage(m_wnd_progress, PBM_GETPOS, 0, 0))) > 0) SendMessage(m_wnd_progress, PBM_SETPOS, wp, 0); return 0; case MSG_END: destroy(); on_exit(); return 0; } return DefWindowProc(wnd, msg, wp, lp); }
void ipod_action_manager::abort_all() { insync (m_sync); for (t_size i = 0, count = m_actions.get_count(); i<count; i++) m_actions[i]->m_process.get_abort_impl().abort(); }