Focus problem when using UI thread

Hi all-

I have an app that uses a separate ui thread for popping up a dialog box
when the app is doing something that takes awhile (like a big query). The
dialog box simply shows a "please wait" message, then when the query is
done, the dialog box and its thread are destroyed (this is done through a
separate class that spawns the thread which shows the dialog box).

The problem is that it seems sometimes when the dialog box is removed, and
I'm about to show *another* dialog box, that belongs to the main thread, the
focus gets screwed up...some other window will be pushed to the forefront.
The second dialog box is displayed, it's just that the focus suddenly shifts
to somewhere else.

I've tried doing AfxGetMain()->BringWindowToTop() (forgive me if that isn't
the right function...it's late and I don't have the code in front of me)
from the main thread, but that doesn't seem to help.

Everything works ok if I bring up a messagebox first, but unfortuantly that
really isn't a solution.

Any idea how to bring the focus back to the app when showing the second
dialog?

Thanks,

Wanda


0
wandazula (3)
5/3/2004 3:59:02 AM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
695 Views

Similar Articles

[PageSpeed] 42

You can try SetFocus() from the main thread.

I think you can achieve the same effect without an extra thread. you please create the instance of the dialog class and display it  using Create and ShowWindow functions before ur time consuming function, and disable the main window. After completing the query call CloseWindow function to close the dialog. Since it is not a modal dialog, displaying dialog will not block your code execution.

All the bes
Binu
0
anonymous (74721)
5/3/2004 8:06:04 AM
First, this is probably a design error. A separate thread popping up a dialog box is
BEGGING for disasters too numerous to detail. Don't Do That.

Do the big query in the separate thread, and not in the GUI thread. You've tried to solve
the wrong problem.

Basically, I wouldn't even try to figure out what is wrong. There are so many problems
with the basic design that this is just a superficial flaw which is disguising a deep
flaw.
				joe

On Sun, 2 May 2004 22:59:02 -0500, "Jenna Olson" <wandazula@comcast.net> wrote:

>Hi all-
>
>I have an app that uses a separate ui thread for popping up a dialog box
>when the app is doing something that takes awhile (like a big query). The
>dialog box simply shows a "please wait" message, then when the query is
>done, the dialog box and its thread are destroyed (this is done through a
>separate class that spawns the thread which shows the dialog box).
>
>The problem is that it seems sometimes when the dialog box is removed, and
>I'm about to show *another* dialog box, that belongs to the main thread, the
>focus gets screwed up...some other window will be pushed to the forefront.
>The second dialog box is displayed, it's just that the focus suddenly shifts
>to somewhere else.
>
>I've tried doing AfxGetMain()->BringWindowToTop() (forgive me if that isn't
>the right function...it's late and I don't have the code in front of me)
>from the main thread, but that doesn't seem to help.
>
>Everything works ok if I bring up a messagebox first, but unfortuantly that
>really isn't a solution.
>
>Any idea how to bring the focus back to the app when showing the second
>dialog?
>
>Thanks,
>
>Wanda
>

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15973)
5/4/2004 2:15:59 AM
Reply:

Similar Artilces:

Access XP to Access 97 Conversion Problems
Background Information: I developed a complex Access database system for tracking construction projects around our city. Several external agencies are required by city ordinance to enter their project information into this database so we can coordinate work efforts in the right of way. There are approximately 150 users of this system, two rather large agencies have not upgraded from Office 97. I need to make this resource available to them as soon as possible. The original design of this system took several months and I cannot invest any more time into development for Access 97. Step...

Product Key Problems
I purchased office Home addition and loaded it on both our home computers, but used the same Product Key for both (oops). So now when both computers are using office, the program quits. My CD came with 3, so I uninstalled one copy and reinstalled it, but it never gave me the option to reinput the Product key. I can't seem input the new key and my family is on my case...This seems like an easy fix....can you tell me what to do?<br> <br> Thanks On 2/10/08 4:47 PM, in article ee8ceeb.-1@webcrossing.caR9absDaxw, "mstarmer@officeformac.com" <mstarmer@officeformac.com&g...

Date problems again?
Hi, When I pay a bill through Suntrust Bank, it appears to go back a day. So if I target a bill for 11/3, it gets changed to 10/31. If I target the same bill for 11/4, it gets changed to 11/3. Anyone else experiencing a problem? DST is supposed to end that week, right? -- John JohnA wrote: > When I pay a bill through Suntrust Bank, it appears to go back a day. > So if I target a bill for 11/3, it gets changed to 10/31. If I > target the same bill for 11/4, it gets changed to 11/3. Anyone else > experiencing a problem? DST is supposed to end that week, right? Many on...

using a custon Avery 8876 template to create membership cards. I .
shI created a unique template in Publisher for Avery 8876 business cards, which I am using for Memberhsip cards instead. I am only able to see and edit a single "representative " card. How can I enter individual members names on each sheet before I print it? Do a mail merge. Please be aware that if you do a Print Preview, you will only see a single name, not all of the members. -- JoAnn Paules MVP Microsoft [Publisher] "HOT FLASH" <HOT FLASH@discussions.microsoft.com> wrote in message news:525B2114-7F9C-4C08-8A7D-45D7A5EF0F07@microsoft.com... > shI crea...

Problem with the Callouts
When I am creating or updating an account, a callout is getting triggered (POSTCREATE or POSTUPDATE) and data for some fields is fetched from some other Database, correctly. But when I refresh the Account then only fetched data from other database gets vanish. And if I refresh the same account again then that data comes into the fetched fields from other database Further refreshing the same account, data from other database gets vanish It’s a repetitive process. Any solutions for the above problem? Thanks You have to check if you do not created a loop. If you update your account in ...

money field on a Case problem
On 2 installations I'm getting the following error on a newly added money field: ERROR: A currency is required if a value exists in a money field. Select a currency and try again I checked the currency. Nothing wrong there. Money fields are working on other entities. Anyone seen this before, Is this a known Bug? Regards Patrick ...

Calendar appointments dissapearing (Auto Accept Agent problem?)
I'm having a wierd issue where a meeting organizer will not me able to see a meeting they booked on their calendar but the meeting will still show up on the attendee's calendars. If I look at the meeting from the attendee calendar the organizer still shows up. Sometimes the meeting will stay for the organizer but they can't modify the meeting (no tracking tab, acts like they are an attendee instead of the organizer). This doesn't happen every time, in fact it happens a small amout of the time. We have the auto accept agent running and the organizers list the conference room...

Form Problem 01-07-08
I have a form setup with several items bound to certain fields in the database. How do I stop my form from adding a new record each time the form opens. I only want the record saved when the user hits the save button. Hi, on the form's data tab on the property sheet, set the Data Entry property to No. Jeanette Cunningham "CribbsStyle" <cribbsstyle@gmail.com> wrote in message news:48c1d1e7-0e2f-4819-b30b-da5e4fe5cbc8@r60g2000hsc.googlegroups.com... >I have a form setup with several items bound to certain fields in the > database. How do I stop my form from adding...

Calender problem
Outlook xp professional Cannot figure out how to view my calender in different styles, all I have is one style. how do I restore/find the little tabs that alter the calender views. It is so frustrating Turn on the Advanced Toolbars - are you looking for the Current View window? Can you try to explain what you mean by "little tabs?" Which view are you in? Judy Gleeson [MVP Outlook] Acorn Training and Consulting www.acorntraining.com.au Everyone - turn on your Advanced Toolbars and learn how to use the Field Chooser and Group by Box!! "Timax45" <noanswer@hotm...

Complex Problem!!! MAYBE
Here is my dilema. I need to work out staff commission on a sale by sale basis. Easy. What i then want to do is for the sheet to automattically for each week calculate what each salesperson gets, number of sales etc. Data Entered Date Invoice# Customer Sale_Amount SalesPerson CostPrice Spreadsheet works out; Profit %GP Commission Then for each week I need total sales for each salesperson, total commission. I have been working on how to do this, but it would involve writting 52 formulas for each salesperson etc etc. What is the best way, Database???? List the salesman in A1:A...

Stan, here is your problem
A person who is psychotic is out of touch with reality. He may "hear voices" or have strange and untrue ideas (for example, thinking that others can hear his thoughts, or are trying to harm him, or that he is the President of the United States or some other famous person).* He may get excited or angry for no apparent reason, or spend a lot of time off by himself, or in bed,sleeping during the day and staying awake at night. He may neglect his appearance, not bathing or changing clothes, and may become difficult to communicate with saying things that make no sense, or ba...

Keep Focus
The code below alerts the user that some fields are blank. It works until the last line!!! How can I make it keep the form open an go to the first blank field, then the second etc..(I'll be adding more)??? Private Sub Form_Close() If (IsNull(Me.FirstName)) Or (IsNull(Me.LastName)) Then If MsgBox("Do you want to Edit Member Information now?", vbQuestion & vbYesNo, "Question") = vbYes Then (Me.???) ???.SetFocus On Thu, 31 Jan 2008 09:16:00 -0800, Dan @BCBS wrote: > The code below alerts the user that some fields are blank. > It works until t...

Fundamental Problem With CDs
I must be doing something fundamentally wrong with the way I work with my CDs in Money 2005, and I'd appreciate some advice. I opened a one month CD a couple of years ago and I have just let the bank renew it automatically. When I enter the renewal information from the bank, Money requires me to "redeem" the CD, then "buy" a new CD. This is counter-intuitive since the bank uses the same account number. For example, I have to "redeem" CD Account 123 and "buy" a new CD Account 123 #2. Then a month later I "redeem" CD Account 123 #2 and...

A WMP Problem?
This problem started a few days ago. I can't recall what I might have done. Up to that point if I cllicked on an internet link for a movie clip either Quick Time or WMP automatically opened and played the file. If I downloaded a WMV file and saved it WMP opened the file and played it whenever I clicked on the saved file. Now if I click on a file on a website Quick TIme works as usual but WMP will not automatically start and open/play the file. Instead, I get an empty page with a note in the bottom saying "done." No video. If I save the file it opens just fine wi...

How do I use advance filter correctly?
Good afternoon, I have a list of numbers (it's actually very long but for simplicity lets say it's not). The list is in column A and is 1-10 (A1=1, A2=2, ect...). I want to filter out all instances of 2 and 3 on my list. My thought was to put 2 and 3 into different cells (B1 and B1) and then use the advanced filter to filter out A1-A10 based on the information is cells B2 and B3. I am trying to do this by setting my list range as $A$1:$A$10 and my criteria range as $B$1:$B$3. I also set my copy to location as $C$1. When I do this I get an exact copy of A1-A10 i...

protection problem
When I protect a work sheet, the tab key and the left/right arrows only work within the same row and will not go to the next cell in the next row. The Enter and up/down arrows do not work at all. To input data on the sheet, you have to keep using the mouse to go to the needed cell in each row. On a sedcond worksheet that is almost identical, the keys work correctly. Why does one sheet work and the next doesn't? ...

Calender problems
For some reason when I download a bill that I have paid and reconciled, it does not update in the calender. So, for some bills they are crossed out and marked as paid, and others are saying that they are days overdue. But these particular bills do not show up in the bills section as paid? And when I go to "account details" it shows the payment as being paid?? Any advice would be helpfull...I'm not overly concerned as I tend to ignore the calender, but just a little confused. Thanks, Jennifer ...

Problems with Window in Dialog Owner Draw?
I Skin the CDialog based windows,in the window,the Minbox and MaxBox and CloseBox are exist,the title bar are Owner drawed of cause and the three "button",They show well,but the button in the task bar that stand for the Dialog ,does not work well, when the dialog is active,you click the button in task bar the dialog can not hide(Or as we say the dialog in min state.). thanks, Tylor ...

format "focus" characteristics
The cell on which the focus rests is indicated by a thick box outline. Is there a way to thin those lines? Are the other formating features that can indicate focus? I don't think so. But you may want to take a look at Chip Pearson's rowliner utility. http://www.cpearson.com/excel/RowLiner.htm Pa Maher wrote: > > The cell on which the focus rests is indicated by a thick box outline. > Is there a way to thin those lines? > Are the other formating features that can indicate focus? -- Dave Peterson Thanks Dave, The add-in allows for some efficient and attractive feature...

permissions problems on send
Since migrating a group of mailboxes to 2003, one of our users is having sporadic problems sending to some recipients. The messages bounce back with "Yo do not have permission to send to this recipient. For assistance, contact your system administrator." But the permissions structure in A.D. seems to be in order, and there are no restrictions on these recipients. Where to start looking? jerry. ...

How do i work out percentages using excel?
Could someone please tell me the formular to work out percentages using Excel? For example what 20% of £1.10 was. Hi Fern, Try "=1.10*.2" (remove quotes), and formatting the cell as percentage. You could also substitute the values above with cell references - if you enter the percentage value as a percentage, it will pick it up correctly. Hope this helps Sunil Jayakumar "Fern" <Fern@discussions.microsoft.com> wrote in message news:D5FF910D-948E-4239-98D1-325157DB5F15@microsoft.com... > Could someone please tell me the formular to work out percentages ...

Content library problem #2
Hi all - Publisher 2007. I write a newsletter twice a year. Since I use many of the same elements on the back page every time, I erased the volatile areas, then did a Save All on the page, and added it to the Content Library. But when I bring the page back in from the Content Library to a new, blank page, the paragraph spacing on the paragraphs has changed and left me with text boxes in an overflow condition. Am I doing something wrong? Craig ...

Problem reinstalling Money 2004
I had a problem that after running in a different XP configuration (docked vs not) Money claimed it needed to reinstall something and them when I got back home to run the reinstall, it would claim it didn't have write privileges to the Money/System directory. So, I figured I would uninstall and reinstall, and I keep having the same kind of problem. It gets about 25% done, and claims it can't write this one dll to the Money\system directory because of access privilges and aborts. Directory access can't be the problem - it just wrote some other files to that directory, and I've...

Publisher 2003 graphics problem
I have a problem printing some graphics in Publisher 2003. Basically the images are being clipped. If I use a specific one as an example which is 3 images grouped and locked together, it prints Ok from Publisher 2000 and Publisher 2002. If I copy the graphic to Word 2003 it prints OK. But in Publisher 2003 one of the elements moves and other parts get clipped I have tried two printers myself, both Epson inkjets, and I get identical results. Someone else has tried on 3 different printers, and gets the same problem but with varying degrees of clipping or different elemnets move. I hav...

control focus when form opens
Using access xp I have a form with a form header section, a detail section and a footer section. For some reason, when the form opens it opens with focus on a control in the detail section, but I want initial focus to be in the header section. When I go to view>tab order, the radio buttom of the detail section is selected. When I select the radio button of the header, the header control list is displayed, but when I close and reopen the tab order, detail is again selected. I can't see where to change this, how do I get the form to open with focus in the header, not the detail...