WM_QUERYCENTERWND and detecting creation of modal window.

I found that, the parent window is receivinig WM_QUERYCENTERWND when new 
modal window is started under that parent.

I can capture that message in method CDialog::WindowProc.

Capturing WM_QUERYCENTERWND is better then capturing WM_ENABLE, because 
when UI is multithreaded, it is possible to have two or more modal 
windows simultaneously connected to one parent (each modal window on 
separate thread).

When second modal window is connected to parent window, I don't receive 
WM_ENABLE, but I receiving WM_QUERYCENTERWND each time when new modal 
window is shown.

I need to count how many modal windows are connected to CDialog.


But there is one problem - I don't receive WM_QUERYCENTERWND when 
MessageBox is called from other thread then parent window thread.

It works when MessageBox is called from parent window thread, and it 
works when CDialog doing DoModal() from parent, or other thread.



My test program looks like:

class CthrmfcDlg : public CDialog  // this is my main parent window of 
whole apllication

I overrided method:
LRESULT CthrmfcDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
	if (message==0x036B)
		TRACE("WM_QUERYCENTERWND\n");

}



I have also static method:
int CthrmfcDlg::thr(void* data)
{
	CthrmfcDlg* p = (CthrmfcDlg*) data;

	CModalDlg dlg;
	dlg.DoModal();

	return 0;
}

As you see it starts new modal window (CModalDlg deriving from CDialog).

I can use it inside CthrmfcDlg clas in two ways:
- in same thread by:
	thr(this);
- in other thread:
	CreateThread(0, 0, (LPTHREAD_START_ROUTINE) thr, this, 0, 0 );

In both cases, when DoModal starts, I am recevinig WM_QUERYCENTERWND 
inside my CthrmfcDlg::WindowProc.

So it is just that what I want.

But there is a problem...
When I change my thr() method to:
int CthrmfcDlg::thr(void* data)
{
	CthrmfcDlg* p = (CthrmfcDlg*) data;
	::MessageBox(p->m_hWnd, "messagebox", "test", MB_OK);
	return 0;
}

I am receiving WM_QUERYCENTERWND only when I call it by: thr(this).
When I call it using CreateThread() I don't receive WM_QUERYCENTERWND.

No matter how I create that MessageBox - i tried:
::MessageBox(p->m_hWnd, "messagebox", "test", MB_OK);
p->MessageBox("messagebox", "test", MB_OK);

effect was same...



I know that I should not build multithreaded UI.
I need to do this that way, because I providing plugin system in my 
application.
I need to start each plugin on separate thread to avoid problems with 
message loop blocking by "not very good" written plugins, and plugins 
can show own windows.

Main user interface of my progam is two separate MFC windows.

So I need to count modal windows connected from all plugins threads 
(many plugins, each plugin on separate thread) to my "hub window" (with 
hWnd I passed to plugins, and plugins set it as parent for all they 
windows), and when there is more then one modal window at time, I am 
disabling my main user interface until the last modal window is closed.

Maybe there is better methot to count modal windows, or maybe you can 
give me other idea how to resolve my problem?
0
hellfire (30)
1/17/2006 4:25:36 PM
vc.mfc 33608 articles. 0 followers. Follow

1 Replies
588 Views

Similar Articles

[PageSpeed] 6

You should not run two modal dialogs for the same parent (ESPECIALLY in 
different threads!). It leads to difficult synchronization issues.

"Tomasz Pyra" <hellfire@spam.spam.spam> wrote in message 
news:dqj69c$5o4$2@news.task.gda.pl...
>I found that, the parent window is receivinig WM_QUERYCENTERWND when new 
>modal window is started under that parent.
>
> I can capture that message in method CDialog::WindowProc.
>
> Capturing WM_QUERYCENTERWND is better then capturing WM_ENABLE, because 
> when UI is multithreaded, it is possible to have two or more modal windows 
> simultaneously connected to one parent (each modal window on separate 
> thread).
>
> When second modal window is connected to parent window, I don't receive 
> WM_ENABLE, but I receiving WM_QUERYCENTERWND each time when new modal 
> window is shown.
>
> I need to count how many modal windows are connected to CDialog.
>
>
> But there is one problem - I don't receive WM_QUERYCENTERWND when 
> MessageBox is called from other thread then parent window thread.
>
> It works when MessageBox is called from parent window thread, and it works 
> when CDialog doing DoModal() from parent, or other thread.
>
>
>
> My test program looks like:
>
> class CthrmfcDlg : public CDialog  // this is my main parent window of 
> whole apllication
>
> I overrided method:
> LRESULT CthrmfcDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
> {
> if (message==0x036B)
> TRACE("WM_QUERYCENTERWND\n");
>
> }
>
>
>
> I have also static method:
> int CthrmfcDlg::thr(void* data)
> {
> CthrmfcDlg* p = (CthrmfcDlg*) data;
>
> CModalDlg dlg;
> dlg.DoModal();
>
> return 0;
> }
>
> As you see it starts new modal window (CModalDlg deriving from CDialog).
>
> I can use it inside CthrmfcDlg clas in two ways:
> - in same thread by:
> thr(this);
> - in other thread:
> CreateThread(0, 0, (LPTHREAD_START_ROUTINE) thr, this, 0, 0 );
>
> In both cases, when DoModal starts, I am recevinig WM_QUERYCENTERWND 
> inside my CthrmfcDlg::WindowProc.
>
> So it is just that what I want.
>
> But there is a problem...
> When I change my thr() method to:
> int CthrmfcDlg::thr(void* data)
> {
> CthrmfcDlg* p = (CthrmfcDlg*) data;
> ::MessageBox(p->m_hWnd, "messagebox", "test", MB_OK);
> return 0;
> }
>
> I am receiving WM_QUERYCENTERWND only when I call it by: thr(this).
> When I call it using CreateThread() I don't receive WM_QUERYCENTERWND.
>
> No matter how I create that MessageBox - i tried:
> ::MessageBox(p->m_hWnd, "messagebox", "test", MB_OK);
> p->MessageBox("messagebox", "test", MB_OK);
>
> effect was same...
>
>
>
> I know that I should not build multithreaded UI.
> I need to do this that way, because I providing plugin system in my 
> application.
> I need to start each plugin on separate thread to avoid problems with 
> message loop blocking by "not very good" written plugins, and plugins can 
> show own windows.
>
> Main user interface of my progam is two separate MFC windows.
>
> So I need to count modal windows connected from all plugins threads (many 
> plugins, each plugin on separate thread) to my "hub window" (with hWnd I 
> passed to plugins, and plugins set it as parent for all they windows), and 
> when there is more then one modal window at time, I am disabling my main 
> user interface until the last modal window is closed.
>
> Maybe there is better methot to count modal windows, or maybe you can give 
> me other idea how to resolve my problem? 


0
alegr (1131)
1/18/2006 4:16:02 AM
Reply:

Similar Artilces:

Splitter window does not work
Can I create a splitter inbetween two controls without Having two view classes for both ? I have a SDI MFC application in which I have only one view class. I need to create a splitter between the tree cotrols which is at the left side and other text control I want to situate a splitter exactly betwee them. How should I set it ? --Bansidhar "Bansidhar" <anonymous@discussions.microsoft.com> wrote in message news:E36DDCE4-F9DD-49FE-A12C-0314985DA770@microsoft.com... > Can I create a splitter inbetween two controls without Having two view classes for both ? > I have a SDI M...

Errors Detected
When I open a .pst file in Outlook 2002 from any computer on my network, I get the following error: Errors have been detected in the file \\path\folder\archive.pst. Quit all mail enabled applications, and then use the Inbox Repair Tool. Since I get this on multiple computers, and the pst isn't my Inbox, I was wondering if there was a way to repair the pst file? Any help would be greatly appreciated. Thanks! Doreen PERFECT!!! Worked like a charm! Thanks! Doreen "Patrick Reed [MVP - Outlook]" <patrickareed@mchsi.com> wrote in message news:OQX8idHUDHA.2088@TK2MSFTN...

error windows update
hi.. i have a error Code 8024401F on windows vista home premium, and i don't know what i suppose to do, can someone help me please... For home users, no-charge support is available by calling 1-866-PCSAFETY and/or 1-866-234-6020 in the United States and in Canada or by contacting your local Microsoft subsidiary. There is no-charge for support calls that are associated with security updates. When you call, clearly state that your problem is related to a Security Updates. Or you can... Start a free Windows Update support incident request: https://support.microsoft.co...

virus being detected in bad mail folder
I just recently upgraded to SAV9.0 and Mail security 4.5 on my Exchange 2003/Server 2003 system. It is now finding virus' in the C:\Program Files\Exchsrvr\Mailroot\vsi 1 \BadMail\ is this normal or do I have somehting configured wrong? I am also getting them in C:\Program Files\Symantec\SMSMSE\4.5\Server\Temp\VAP18E0.tmp >-----Original Message----- >I just recently upgraded to SAV9.0 and Mail security 4.5 >on my Exchange 2003/Server 2003 system. It is now finding >virus' in the C:\Program Files\Exchsrvr\Mailroot\vsi 1 >\BadMail\ is this normal or do I have ...

Change Window Background Color
Hi, My question is how to change window background color on the fly, if I have the window HWND. I need a method like void ChangeColorToBlack(HWND hwnd) { // code to change the window background color to black. ....... } What I would like to do is to enumerate all child windows of a given window by calling EnumChildWindows, then change the window background color of each child window Thank you You did not specify if window you have a handle for is created in the same thread. I assume that it is a case. 1. Use SetClassLong and specify GCL_HBRBACKGROUND to assign different backgrou...

how do I set an automatic signature for windows live mail
I've been trying to set up an automatic signature for my email, I use windows live mail - but can't find any direction on how to do this. Not a Word question. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA http://word.mvps.org "SusanAndre1954" <SusanAndre1954@discussions.microsoft.com> wrote in message news:8D29D57A-6F5F-424E-99E3-B08C86306759@microsoft.com... > I've been trying to set up an automatic signature for my email, I use > windows > live mail - but can't find any direction on how to do t...

FWD: Check this security update for MS Windows
--kzbaidhjuwdobcs Content-Type: multipart/related; boundary="dqvmlbzfxgvp"; type="multipart/alternative" --dqvmlbzfxgvp Content-Type: multipart/alternative; boundary="tmncypgpudslj" --tmncypgpudslj Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Microsoft Consumer this is the latest version of security update, the "October 2003, Cumulative Patch" update which resolves all known security vulnerabilities affecting MS Internet Explorer, MS Outlook and MS Outlook Express as well as three newly discovered vulnerabilities. Install now...

Outlook/Windows Mail Woes
I've seen that the import/export issue has been addressed often, but I'm now in a bit of a quandry thanks to my beta expiring last week, and I can't find a solution anywhere. So I've been running the Office 2007 beta, which expired last week. Unable to afford Office software (and quite frankly wanting to give Windows Mail a whirl ANYway...) it's now time to move my e-mail over. Sadly, Windows Mail won't let me import from Outlook 07 (gives me a MAPI error) even though Outlook 2007 is still installed. Furthermore, my Outlook beta has expired and now is in "limi...

Reading XML from a Windows service #2
Using the function below, I'm importing configuration parameters, from an xml file, into a Windows service. This code works as expected in a regular Windows application, but when used in a Windows service (written in vb.net), it produces unintended side effects. The most notable being multiple (and simultaneous) firings of timer events. Is there a better way? Thank you. Private Function MyNodeValue(ByVal strPath As String) 'This function reads a value from an XML file. Dim xmlDoc As New System.Xml.XmlDocument xmlDoc.Load(strPathToXMLfile) Try ...

Printing Crystal report from SOP transaction window
Hello I have create reports by Crystal Report Version 10 , this report retrieve all invoices records , and I need to pass invoice number from SOP transaction window to that report via VBA code . i try to write this command , but error number 424 with message: Object required is appear and the secound line o code below is highlited With CrystalReport1 ..ReportFileName = App.Path & "invoice.rpt" '.GroupSelectionFormula = "{SalesLineItems.SOP Number} = '" & Trim (DocumentNo.Value) & "'" 'StrSelFormula = "{Personal.PolicyNo} = " ...

Migrating off of SBS 2000 to Windows 2008 standard /Exchange 2010
We have outgrown the SBS environment and are moving to an environment with Windows 2008 std server running exchange 2010. What is the best/easiest way to get 2000SBS out of the way? As I understand it, I would bring in the 2008 server and configure as a member DC then seize the FSMO roles and then shut down the SBS 2000 server. Is that about it (excluding what I will have to do to migrate my exchange data - which I am assuming I will have to do BEFORE I seize the FSMO roles... What other gotcha'ya's might I expect?? Thanks, Brad ...

creation date unchanged delete and recreate a file (in all windows versions)
Hi everyone,I just need an explanation for a problem observed in every Windows Version (2000 server, XP and Vista).If I delete a file and create an new one with the same name and in the same folder, the "Creation date" is the same as the one deleted just before... It seems incredible !Can you tell me a way to create a new file with a creation date different event if the name of file is the same.Thanks you. This is an Access newsgroup. We are here to help with questions about the database application - Microsoft Access - that is part of MS Office professional.I'd suggest posting...

Possible to detect changes to an XmlDocument object?
If I instantiate an XmlDocument object, the load a file through the Load method, is there a way, later on in execution, to easily determine if the XmlDocument object has changed from the original version loaded? I'd like to be able to check a condition to see if the document in memory has been editted (i.e., nodes added, attributes changed, etc.) so that my user can decide whether or not to commit changes to the disk file before moving to another file. Will I have to resort to re-loading the file, and comparing OuterXml properties? Gabe Gabe Covert wrote: > I'd like t...

ATI TV Wonder 600 USB-IR Hardware not detected
ok, so I just bought 'this tuner' (http://www.newegg.com/Product/Product.aspx?Item=N82E16815306011) and I'm having problems getting it to work. So, heres my setup. Cable (direct tv) running in from the wall, going to the cable box. Then S-video and white/red composite running to the USB tuner. USB tuner plugged into the PC. simple setup. So I open WMC (windows media center) and go to set up TV signal. Set zip, pick cable, set manually, select S-video video. I get a preview video with sound. YAY ALLS WORKING! I hit next, and get "IR hardware not detected" an...

Excel VB Windows XP and 2000 problem
Hi, i have writen some macros using office 2000 on windows XP and they wor well. Then i changed my Operating system to windows 2000 and installe the same office 2000. When i try to open my excel sheet with both macros enabled and disable Visiual Basic gives me the "file not found" error in a message box an nothing more and didnt open the file. what could be the reason? any idea? i didnt intentially use any dl from XP but dont know if VB uses them by default! thanks in advance.. i can provide the excel sheet if anyone want to review... please let m know. Emr -- Message posted f...

Incompatibility with Office for Windows
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel This presentation is protected by a password or Digital Rights Management (DRM). To access the presentation, you must have a version that is not protected by a password or DRM. This is unacceptable. Why do you continue to produce incompatibilities in office products. Office for mac should be able to Open any file created by Office for Windows and display it correctly. If the windows version can display animated GIF files then the mac version should be able to or Neither. THe same goes for encryption or DRM. If th...

Home for WINDOWS 7 Questions
Can't find a place to ask WINDOWS 7 Questions on this forum. Can some-one create a place please? Jay alt.os.windows-7 "jay garland" <jaygarland@discussions.microsoft.com> wrote in message news:543A6B94-849D-4A83-B19C-FD256D49C932@microsoft.com... > Can't find a place to ask WINDOWS 7 Questions on this forum. Can some-one > create a place please? > Jay If your question is related to 64-bit Windows 7 you may ask here. :) Carlos "jay garland" wrote: > Can't find a place to ask WINDOWS 7 Questions on this forum. Can some-...

Detect Excel minimize and restore?
I need to be able to detect the event when someone minimizes or restores the Excel application. How can I do this?? (if it's even possible) Thanks folks! Looks you can't detect the Excel main window resize, only the workbook window resize. I would think it is possible. Maybe with a VB6 ActiveX exe. You could ask in the classic VB (VB6) group: microsoft.public.vb.general.discussion RBS "Robert Crandal" <nobody@gmail.com> wrote in message news:KToTm.76787$W77.11624@newsfe11.iad... >I need to be able to detect the event when someone > mi...

Windows Easy Transfer... will merge files?
Hi there, I am transferring via Windows Easy transfer the set of files from a tower to my laptop on which I already have some existing files like pix, favorites, and a few documents. Now, when I run Easy Transfer into the laptop, will it merge files with the already existing files? I don't want to lose the already existing files in My Pictures, Favorites, etc.... Thanks, Gordon On 1/14/10, Gordon J. Rattray posted: > Hi there, > I am transferring via Windows Easy transfer the set of files from a tower to > my laptop on which I already have some ex...

I'm confused about SBS2008 and Windows Server 2008 std
I've installed SBS2008 and I've joined Windows Server 2008 std to the SBS2008 computer. Do the users in SBS2008 transfer over to Windows Server 2008? I guess what I'm asking is this. Can I login to Windows Server 2008 with a username and password from a user in SBS2008? Please advise and thanks. john doe wrote: > I've installed SBS2008 and I've joined Windows Server 2008 std to the > SBS2008 computer. Do the users in SBS2008 transfer over to Windows > Server 2008? I guess what I'm asking is this. Can I login to Windows > Server 2008 with a ...

BUG: Outlook treats new message window as a dialog box
Applies to: Outlook 2000/2002/2003 (possibly also earlier versions, but not tested) Tested with: OL 2000 on Windows 98 SE OL 2003 on Windows XP Pro SP2 SYMPTOMS When Outlook is called externally to create a new message, it will treat the new message window as a dialog box. This has the consequence that the whole application is locked until one disposes of the "dialog box" either by sending the message or closing it. An alternative scenario is such that Outlook is not running, and the call is made to create a new message. In such case, if one attempts to start Outlook, one gets the...

Color output to ListBox windows
A simple question with a very low likelihood of an affirmative answer: Can data output be done in color to the list box window ? Thank you, Andrew. "Andrew K." <Andrew K.@discussions.microsoft.com> wrote in message news:67BD3632-E897-4555-8B41-D93991912DD2@microsoft.com... > A simple question with a very low likelihood of an affirmative answer: > > Can data output be done in color to the list box window ? Yes. Use WM_CTLCOLORLISTBOX or ownerdraw it depending on your needs. -- Jeff Partch [VC++ MVP] "Jeff Partch" wrote: > "Andrew K." ...

Case creation 12-07-04
Hello, I just finished to setup my CRM server and clients, for testing purpose. Mail system is ok, try to play with the workflow manager, all seems to be ok. Now i'm currently setting up case system. I successfully create cases on the CRM server. The rules I create in the workflow are working, i get emails on events "case open" and "close". But I've created this case from the CRM web interface. How can my customers open cases with a simple mail ? I've created a queue, but how can I associate it with a case creation ? Thanks for your help, Fabrice. ...

Windows forums
http://social.answers.microsoft.com/Forums/en-US/category/windowsxp I can see where I'm going to hate the forums. The first thing I saw at the top of the page was "Bing". I guess there's no way of getting rid of that. Then I studied the list of catgories. I didn't see "Other" on the list. If you post in the newsgroup, everyone sees it, not just the ones who frequent certain categories. Someone posted a link to a Microsoft site that tells you why they're doing it and how wonderful it will be. Bull crap. -- --- Long liv...

MDICLIENT window without WS_EX_CLIENTEDGE style
Hi, how can I create MDICLIENT window without WS_EX_CLIENTEDGE style? I tried to modify ex style after window creation, but the style reappears... I need a MDICLIENT window without a sunken border. Thanks! ED I found a way: I slightly changed OnWindowPosChanging in my class derived from CMDIChildWnd. There was the string dwNewStyle |= WS_EX_CLIENTEDGE; persisting the unwanted style. ED ...