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
735 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 (74722)
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 (15974)
5/4/2004 2:15:59 AM
Reply:

Similar Artilces:

Using Excel to input survey Information- How do I put checks against myself?
I need to make certain cells accept only "x" and nothing else. I have no idea why this is becoming such a difficulty. Also, I have data sets in there own colum. I need to mark an "x" under yes, no, or not sure. However, if I move too fast, I might put an "x" under yes and not sure. Is there any way to check for that? This sheet is going to get quite large, and manual rechecking will be a huge pain. Anyone have any idea's? Oh! I'm running Excel 2002. -- kinjour ------------------------------------------------------------------------ kinjour's Prof...

using third party defragmenting software
Good evening, I wanted to ask a simple question: when using a third-party defragmenting utility (such as DiskKeeper from Executive) on a Domain Controller that also runs Exchange (do not shoot me! I inherited this situation) it is a wise and prudent move to make sure that both the folder that contains ntds.dit (stored in the default location) as well as the folder that contains both priv1.edb and priv1.stm (not stored in the default location) are excluded from this utility's 'sight'. In fact, the argument could very easily be made that this utility should not be installed...

incoming emails problem after migration
As a process to migrate from ex5.5 to ex2k, I installed ex2k server as a site of ex5.5 within the same organization. I moved all the mailboxes from ex5.5 to ex2k server and configured a new SMTP connector in routing group. I also changed the pix configuration to point to new ex2k server. My outgoing emails are working fine but have problems in incoming emails. Senders get undeliverable message. When I see in the routing group i can see the Ex5.5 machine as a IMS connector. If the problem is due to this then how can I add new IMS connector for ex2k? I would appriciate if anybody have ...

how to disable/enable command button (ActiveX) using a macro
I have tried to create a macro using recorder to disable/enable command button (ActiveX) with the following code being created ActiveSheet.Shapes("CommandButton1").Select This only results in the command button being selected - with the procedure of enabling/disabling being "lost". So i tried the following code ActiveSheet.CommandButton1.Select CommandButton1.Enabled = False This presents runtime error message "object required" What is the "simplest" way to create this macro? (first time user) Any help much appreciated you can tr...

How do I use Publisher 98 to write a book?
I have written a short book, in Word 97, (150 pages), and would like to use Publisher 98 to insert pictures and fromat it printing. Can anyone help? Setup Publisher as a booklet, (special fold) arrange your margins, create a text box, copy the text from Word, paste into the text box, Publisher will ask about the overflow, click yes, Publisher will create pages and text boxes as needed. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "windpsalm" <windpsalm@discussions.microsoft.com> wrote in message news:14D47200-A6...

Outlook2000 problems with a larger disc drive
Everyone, I have just upgraded my computer from a 6gig drive to a WDC 160gig drive. I used the image copy software that comes with the Western Digital to copy my old XP professional system to the new drive. Everything works OK except OUTLOOK. I am getting errors when trying to download my e-mail from the POP3 server. It looks like the mail is coming in but never makes it to the inbox. Can any of you give me a start on this problem. Thanks, Greg Ennis ...

Should I use Winforms ?
Hi all, I'm programming windows applications using Win32 sometimes, and MFC most of the time. I know how to mix managed and unmanaged c++ in my applications, so I can use the framework .net in my apps. I've read many things about Winforms, but I'm asking myself a question : Should i create my future applications using winforms instead of using Win32 or MFC ? What are the benefits to use winforms ? Can we count on an futur "MFC for winforms" ? I'm very interested about using the new framework at all, but, wouldn't it be enough to call managed api when needed fr...

Aaarggh! Cache mode problems again!
I know there's a fix out there for this one, i just can't find it on MS's web site. For users who are running Outlook2k3 with cached exchange mode, new entries in the GAL do not appear. Users who don't use cached exchange mode or who use OWA can see the new addresses just fine. If cached exchange mode users temporarily turn this feature off, they can once again see all the new addresses. Does anyone know where Microsoft hid the hotfix for this one? I'm thinking that it must've been overwritten during a recent round of patching and updating. Thanks. There is no ...

Problem changing Business Unit for one user...
Hello; I created a "Sales" Business Unit and I'm trying to move our Sales Manager's account from the main Business Unit to this Sales Unit. However, whenever I try, I get this error: An error has occured. For more information, contact your system administrator. Well, I am the system admin, and I don't know what's wrong! :D There doesn't seem to be any errors in the event log on the CRM server. I've tried moving other users in the same way (from the main Unit to Sales) with no problem. Since I can't (or shouldn't) dink with the database, how am ...

Use correction patch which came from the MS Corporation
--fcmqkpucclr Content-Type: multipart/related; boundary="mbsrcrnaeiwles"; type="multipart/alternative" --mbsrcrnaeiwles Content-Type: multipart/alternative; boundary="brehaerg" --brehaerg Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Microsoft Client 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. Install now to protect your computer from these vulnerabilities, the most...

Why Outlook profermance is slow when using the old profile?
Our Company install a windows 2000 server and exchange server recently. And all computer use windows xp. But after set up the email system, some user's outlook profermance is very slow, need 5-10 seconds to preview mai. and this user's is using their old profile when enter the domain. Can anybody help? I'm not sure which Outlook version this started but if you have Instant Messaging enabled in Outlook you can get significant performance hits. In OL XP it's in Options - Other...at the bottom. HTH -- *************** No Email Replies "William Ho" <w.ho@dbln...

MSCRM 3.0 WebForm UI changes
For those of you who had a chance at looking into MSCRM 3.0, did you notice any major UI changes? We have customized our CRM (including the UI) to a large extent and we need to study the impact of changes in the upcoming version of CRM. Any info would help. Thanks Vimal You can take a look at my blog. The latest post has some links to webcasts of demos of v3. The UI is quite extensively changed. It resembles Outlook Web Access - very easy to navigate, but much different than current version. As the previous poster said, if your changes were of the "supported" variety you sho...

ol 2000 customised contact forms used on with ME server
please, please would some plain-speaking non-technical person help me with my probs? i have absolutely no development knowledge and am scared to play too much, however I have designed my own very specialised Contact Form which is published in the organisational library and is the default form for a Contact sub-folder called 1:1. 1. I would dearlylike to know a way for files/items to be inserted in to any field other than Notes. 2. When inserting the text only of an email into Notes, can I change the date to exclude the time?... and to be always inserted in a specific font, size and colour (...

e-mail problem
hello, after installing a linksys WRT54G Broadband Router, I can no longer send e-mails through Outlook Express. Any ideas? This newsgroup is for support of Outlook 97, 98, 2000, 2002 & 2003 from the Office family for Intel PCs. For Outlook Express (OE) support try posting in one of these newsgroups: microsoft.public.inetexplorer.ie4.outlookexpress for OE 4.x microsoft.public.windows.inetexplorer.ie5.outlookexpress for OE 5.x microsoft.public.windows.inetexplorer.ie55.outlookexpress for OE 5.5x microsoft.public.windows.inetexplorer.ie6_outlookexpress for OE 6.x microsoft.public.interne...

date format using dot / period
I have a user that did a custom format for a column to be mm.dd.yyyy. When I type the date using slashes - Excel recognizes the data as a date. However, my user typed the data using dots. I told her to find and replace the dots and make them slashes to make the information correctly sort. But I am curious, is there a way for excel to recognize numbers seperated with a dot as a date opposed to an integer or decimal number? thank you Only be either changing the windows settings for date delimiters (not recommended) or using a macro that will change the dots to date delimiters like / ...

How do I use my logo as a faded backdrop on business cards?
I have microsoft office 2003 and can't figure how to use my personal log as a backdrop on my business cards. Can someone help? Thank you, Christina Insert the logo on the Master Page, ctrl+m, on the drawing toolbar, select picture (looks like a bar chart), select wash out. If you don't want a wash out look, placing the logo on the Master Page will allow you to write text over the image on the publication page. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Christina" <Christina@discussions.microsoft.com...

#NA Problem using VLOOKUP
Hi All, Im currently having an issue using VLOOKUP in that Im trying to get a football league table to sort automatically. My problem is that when two teams have the same points value the table will only display the first team it recognizes will that point value and display any other teams with that value as #N/A Can anyone please advise on how to rectify this problem. (I am new to using formulas etc so please be gentle with me) Thanks in advance for any assistance :) -- kingrobbo ------------------------------------------------------------------------ kingrobbo's Profile: http...

Configuring the reply address used by Outlook?
I use a spam-filtering service that collects three of my email accounts onto its server, from which Outlook downloads email to my PC. The messages in Outlook retain the "To" address they were originally sent to (one of my three email addresses). But, because they're now being downloaded from a single account, when I reply to a message addressed to "brett2@isp.com" or "brett3@isp.com", Outlook sends the reply from the account "brett1@isp.com", which is the account I used to set up the spam-filter service. In other words, Outlook isn'...

word, excel, etc on XP try to install with each use
I work for a small non-profit with a bunch of hand me down computers. When I open Word, the system 'installs' it every time. It's a pain, but I can deal. Today is the first time I've tried to use Excel, it goes through the same process but dosen't open and gives Error 1706. I don't have the install disks, but I do have the product number. Help!!! ...

How do I use a Cell Value to link other sheets in a workbook
I am trying to link the data in a cell in another sheet by using a viable to determine the sheet link. =INDIRECT(A1&"!H10") where A1 holds the sheet name, and H10 is the cell on that sheet being referred to. -- HTH RP "KenK" <KenK@discussions.microsoft.com> wrote in message news:6CDDBB17-5B33-4B59-9FD1-05EA676800C1@microsoft.com... > I am trying to link the data in a cell in another sheet by using a viable to > determine the sheet link. Not too clear. What to try again using more ink? You know to use =Sheet2!A1 to gent the value form A1 in Shee...

Tab and Backspace key problem
I have one user that when he uses either the tab key or the backspace key while filling in forms gets a nonprintable character (thick vertical bar) echoed to the screen rather than the tab moving the cursor to the next field or backspace erasing characters. This only happens in Microsoft Dynamics GP ver 9.00, other applications on the pc work correctly. Any ideas on how to fix this problem would be greatly appreciated. Any chance this is caused by something in his Regional Settings? or his keyboard settings? (different language / keyboard layout) Just taking a guess here .. M. &q...

Autocomplete Problem
Have a new machine: HP, Windows 7 64 Bit; Outlook 2007; using Microsoft Exchange Server from the corporate mother ship. Having problems getting autocomplete to transfer from old machine to new machine. Old machine has Outlook 2003. Found the .N2K file on old machine. Copied it to the new machine into ...Roaming\Microsoft\Outlook. Does not seem to pick up the data in the new machine. However, autocomplet is working with the new machine with new email addresses passing throught the program. Just would like to add all of my old autocompletes. Let me know if there is any m...

why is the $ sign used in formulae
See help on absolute and relative referencing. Gord Dibben MS Excel MVP On Thu, 28 Aug 2008 22:11:52 +1000, "kandk" <keithandkath@optusnet.com.au> wrote: ...

Outlook/Exchange problem #4
Sorry if this shows up twice, I thought I posted it already, but I don't see it here still... ------------------------------------------------------------------------- Two users out of about 60 having problems accessing their mailbox using Outlook. One of the users had their mailbox moved from one store to another on the same server, the other user had no changes made. They can both access their Inbox, but not any of the subfolders, or Deleted, Sent, Contacts, Calendar, etc. OWA seems to work fine for both users in all folders. I already tried recreating the mail profile, didn't he...

rename AD user account creates problem with autocomplete in Outloo
After renaming an Active Directory user account, the new user name and the new Exchange mailbox works correctly almost everywhere, but there is a problem in the autocomplete feature of the client Outlook 2003. OLD USER jgoulding OLD EMAIL jgoulding@cemins.com OLD ALIAS jgoulding OLD DISPLAY NAME Jessica Goulding OLD AUTOCOMPLETE Jessica Goulding <jgoulding> NEW USER jwalter NEW EMAIL jwalter@cemins.com NEW ALIAS jwalter NEW DISPLAY NA...