Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Communication between preferences page and thread's on_done() (Read 2480 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Communication between preferences page and thread's on_done()

Hello

I have a problem with preference page and thread, which should "on_done" post a message to preference dialog.

Let's assume, that I have typical preference page with edit control and two buttons - one with PostMessage and SetDlgItemTextW in his function (and this proves, that message is processed - console will show "It's working!", edit control is changed) and second, which creating a thread with preferences dialog as parent window. In "on_done" are executed identical PostMessage and SetDlgItemTextW functions (with parent window as HWND parameter), but those messages are not processed by preferences window.

What I don't know, where I'm making an error?

Code: [Select]
class PreferencesMain: public CDialogImpl<PreferencesMain>, public preferences_page_instance
{
public:
enum {IDD = IDD_MAINPREFS};

BEGIN_MSG_MAP(PreferencesMain)
MSG_WM_INITDIALOG(OnInitDialog)
COMMAND_HANDLER(IDC_B_CATGETINFO, BN_CLICKED, GetCatalogInfo)
COMMAND_HANDLER(IDC_B_TESTPOST, BN_CLICKED, TestPostMessage)
MESSAGE_HANDLER_EX(WUM_SHOW,OnUserMessageShow)
END_MSG_MAP()

  LRESULT GetCatalogInfo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
service_ptr_t<threaded_process_callback> catInfo = new service_impl_t<Catalog_info>();
//Catalog_info it's implemented threaded_process_callback
static_api_ptr_t<threaded_process>()->run_modeless( catInfo,
threaded_process::flag_show_abort,
this->m_hWnd,//Maybe there is error...?
"Checking...");
return 0;
}

  LRESULT TestPostMessage(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/){
//when I press IDC_B_TESTPOST message is posted and processed, and IDC_EDIT1 is changed
::SetDlgItemTextW(  this->m_hWnd, IDC_EDIT1, L"Local SetDlg");
::PostMessage(this->m_hWnd, WUM_SHOW, (WPARAM)0, (LPARAM)0);
    return 0;
    }

  LRESULT OnUserMessageShow(UINT, WPARAM, LPARAM){
console::formatter()<<"It's working!";//but only with one button
    return 0;
    }
....


//Most important - in my problem - part of Catalog_info

void Catalog_info::on_done(HWND p_wnd,bool p_was_aborted) {//This not working
    ::SetDlgItemTextW(p_wnd, IDC_EDIT1, L"SetDlg from on_done");//on_done is in main thread, so this should be safe... Right?
    ::PostMessage(p_wnd ,WUM_SHOW,(WPARAM)0, (LPARAM)0);
}

Communication between preferences page and thread's on_done()

Reply #1
I can think of two possible causes for this problem:
  • Your on_done is never actually called. You can verify this by putting a logging statement directly into this method.
  • The p_wnd you get in on_done is not the p_parent you passed to run_modeless. If you check the documentation of threaded_process and threaded_process__callback you'll notice there is no description about what the p_wnd in on_done is.
    So to be on the safe side you should store the window handle of your preferences page in your Catalog_info instance and pass a suitable parent window to run_modless. Even better, you could store a reference to the PreferencesMain instance in Catalog_info and add a method in PreferencesMain which will be called in on_done. This avoids exposing the internals of PreferencesMain to Catalog_info.

Communication between preferences page and thread's on_done()

Reply #2
The p_wnd you get in on_done is not the p_parent you passed to run_modeless. If you check the documentation of threaded_process and threaded_process__callback you'll notice there is no description about what the p_wnd in on_done is.

You are right, but this is very confusing...

Quote
So to be on the safe side you should store the window handle of your preferences page in your Catalog_info instance and pass a suitable parent window to run_modless.(..)

That worked, I was too focused on p_wnd to notice this solution. Thanks.