why is dialog opening with edit box text automatically selected?

Hello,
    I have seen this before, and struggled to understand why. In
OnInitDialog I am setting the text of an edit box. When I run the program, I
can see the text there, but for some reason all of the text is selected. I
did not ask for this, and am unable to unselect the text.
    I tried calling m_myEdit.SetSel(-1, -1) on the edit box, and that
doesn't work. In fact, I can't set the selection to anything else at all.
I'm returning TRUE from OnInitDialog, and I thought that the focus could be
set to a control only if you call SetFocus on that control and then return
FALSE from OnInitDialog.

Any ideas?

thanks,
Stuart


0
7/21/2004 1:26:18 AM
vc.mfc 33608 articles. 0 followers. Follow

8 Replies
683 Views

Similar Articles

[PageSpeed] 28

    The edit box might the first control in the tab order. Change the tab
order of the edit box.

-- 
Cheers
Check Abdoul [VC++ MVP]
-----------------------------------

"Stuart" <stuart@stopspam.com> wrote in message
news:%23avL7GsbEHA.3944@tk2msftngp13.phx.gbl...
> Hello,
>     I have seen this before, and struggled to understand why. In
> OnInitDialog I am setting the text of an edit box. When I run the program,
I
> can see the text there, but for some reason all of the text is selected. I
> did not ask for this, and am unable to unselect the text.
>     I tried calling m_myEdit.SetSel(-1, -1) on the edit box, and that
> doesn't work. In fact, I can't set the selection to anything else at all.
> I'm returning TRUE from OnInitDialog, and I thought that the focus could
be
> set to a control only if you call SetFocus on that control and then return
> FALSE from OnInitDialog.
>
> Any ideas?
>
> thanks,
> Stuart
>
>


0
CheckAbdoul
7/21/2004 2:12:07 AM
It must be the default control. Try changing the z order(tab order) in
resource editor or at run time.

--
Ajay Kalra [MVP - VC++]
ajaykalra@yahoo.com


"Stuart" <stuart@stopspam.com> wrote in message
news:#avL7GsbEHA.3944@tk2msftngp13.phx.gbl...
> Hello,
>     I have seen this before, and struggled to understand why. In
> OnInitDialog I am setting the text of an edit box. When I run the program,
I
> can see the text there, but for some reason all of the text is selected. I
> did not ask for this, and am unable to unselect the text.
>     I tried calling m_myEdit.SetSel(-1, -1) on the edit box, and that
> doesn't work. In fact, I can't set the selection to anything else at all.
> I'm returning TRUE from OnInitDialog, and I thought that the focus could
be
> set to a control only if you call SetFocus on that control and then return
> FALSE from OnInitDialog.
>
> Any ideas?
>
> thanks,
> Stuart
>
>


0
ajaykalra (6842)
7/21/2004 2:14:10 AM
Hi Stuart,
As CheckAbdoul and Ajay Kalra said, the edit box is the first valid control
in the tab order.
If you want it like that and don't want to have all the text selected,
return FALSE from OnInitDialog.
Normand.

"Stuart" <stuart@stopspam.com> a �crit dans le message de news:
#avL7GsbEHA.3944@tk2msftngp13.phx.gbl...
> Hello,
>     I have seen this before, and struggled to understand why. In
> OnInitDialog I am setting the text of an edit box. When I run the program,
I
> can see the text there, but for some reason all of the text is selected. I
> did not ask for this, and am unable to unselect the text.
>     I tried calling m_myEdit.SetSel(-1, -1) on the edit box, and that
> doesn't work. In fact, I can't set the selection to anything else at all.
> I'm returning TRUE from OnInitDialog, and I thought that the focus could
be
> set to a control only if you call SetFocus on that control and then return
> FALSE from OnInitDialog.
>
> Any ideas?
>
> thanks,
> Stuart
>
>


0
NoEmail9920 (149)
7/21/2004 2:21:26 AM
Try doing the SetSel (0,0) in OnInitDialog, but also do a SetFocus, and return FALSE, This
will keep the built-in dialog SetFocus from setting the focus, which forces the selection.
You are confusing SetFocus and SetSel. For reasons I don't undrestand, the selection seems
to be done as part of setting focus.
				joe


On Tue, 20 Jul 2004 20:26:18 -0500, "Stuart" <stuart@stopspam.com> wrote:

>Hello,
>    I have seen this before, and struggled to understand why. In
>OnInitDialog I am setting the text of an edit box. When I run the program, I
>can see the text there, but for some reason all of the text is selected. I
>did not ask for this, and am unable to unselect the text.
>    I tried calling m_myEdit.SetSel(-1, -1) on the edit box, and that
>doesn't work. In fact, I can't set the selection to anything else at all.
>I'm returning TRUE from OnInitDialog, and I thought that the focus could be
>set to a control only if you call SetFocus on that control and then return
>FALSE from OnInitDialog.
>
>Any ideas?
>
>thanks,
>Stuart
>

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
7/21/2004 2:24:08 AM
"Stuart" <stuart@stopspam.com> wrote in message
news:%23avL7GsbEHA.3944@tk2msftngp13.phx.gbl...
> Hello,
>     I have seen this before, and struggled to understand why. In
> OnInitDialog I am setting the text of an edit box. When I run the program,
I
> can see the text there, but for some reason all of the text is selected. I
> did not ask for this, and am unable to unselect the text.

The reason why the edit text gets selected when the dialog sets focus to the
control is because an edit control returns DLGC_HASSETSEL in response to
WM_GETDLGCODE.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/dialogboxes/dialogboxreference/dialogboxmessages/wm_getdlgcode.asp

>     I tried calling m_myEdit.SetSel(-1, -1) on the edit box, and that
> doesn't work. In fact, I can't set the selection to anything else at all.
> I'm returning TRUE from OnInitDialog, and I thought that the focus could
be
> set to a control only if you call SetFocus on that control and then return
> FALSE from OnInitDialog.

No that's not right...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/dialogboxes/dialogboxreference/dialogboxmessages/wm_initdialog.asp

The dialogbox will always set the focus to whichever one of its controls it
deems appropriate unless you return FALSE, but "An application can return
FALSE only if it has set the keyboard focus to one of the controls of the
dialog box".

>
> Any ideas?

As others have said, you can shift the edit in the tab order so it is not
selected for default focus status, or set the focus to another control and
return FALSE. Or you might could try doing a PostMessage/EM_SETSEL instead
of a SendMessage. Keep in mind, that it might work some of the time, all of
the time or never and may be platform variable in efficacy. What will most
likely work all of the time is to subclass this edit, handle WM_GETDLGCODE,
call the default, and return everything but DLGC_HASSETSEL. You could do
this first time or every time depending on what it is you want to happen
during the dialog's and edit's lifetime.

-- 
Jeff Partch [VC++ MVP]


0
jeffp (1711)
7/21/2004 2:42:49 AM
I wonder if ES_NOHIDESEL control style will help

"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
news:vmkrf0hvljsadbce1g0jlms73bk79s4l3s@4ax.com...
> Try doing the SetSel (0,0) in OnInitDialog, but also do a SetFocus, and
return FALSE, This
> will keep the built-in dialog SetFocus from setting the focus, which
forces the selection.
> You are confusing SetFocus and SetSel. For reasons I don't undrestand, the
selection seems
> to be done as part of setting focus.
> joe
>
>
> On Tue, 20 Jul 2004 20:26:18 -0500, "Stuart" <stuart@stopspam.com> wrote:
>
> >Hello,
> >    I have seen this before, and struggled to understand why. In
> >OnInitDialog I am setting the text of an edit box. When I run the
program, I
> >can see the text there, but for some reason all of the text is selected.
I
> >did not ask for this, and am unable to unselect the text.
> >    I tried calling m_myEdit.SetSel(-1, -1) on the edit box, and that
> >doesn't work. In fact, I can't set the selection to anything else at all.
> >I'm returning TRUE from OnInitDialog, and I thought that the focus could
be
> >set to a control only if you call SetFocus on that control and then
return
> >FALSE from OnInitDialog.
> >
> >Any ideas?
> >
> >thanks,
> >Stuart
> >
>
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm


0
alegr (1131)
7/21/2004 3:32:39 AM
"Alexander Grigoriev" <alegr@earthlink.net> wrote in message
news:%23IRMhNtbEHA.3988@tk2msftngp13.phx.gbl...
> "Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
> news:vmkrf0hvljsadbce1g0jlms73bk79s4l3s@4ax.com...
> > Try doing the SetSel (0,0) in OnInitDialog, but also do a SetFocus, and
> return FALSE, This
> > will keep the built-in dialog SetFocus from setting the focus, which
> forces the selection.
>
> I wonder if ES_NOHIDESEL control style will help
>

No, it shouldn't do. FWIW, I do like Joe's solution though.

-- 
Jeff Partch [VC++ MVP]



0
jeffp (1711)
7/21/2004 3:50:54 AM
I've had the same problem in the past.  My solution was to post a UDM at the
end of OnInitDialog.  In the handler for that message, I called SetSel(0,
0).

"Stuart" <stuart@stopspam.com> wrote in message
news:%23avL7GsbEHA.3944@tk2msftngp13.phx.gbl...
> Hello,
>     I have seen this before, and struggled to understand why. In
> OnInitDialog I am setting the text of an edit box. When I run the program,
I
> can see the text there, but for some reason all of the text is selected. I
> did not ask for this, and am unable to unselect the text.
>     I tried calling m_myEdit.SetSel(-1, -1) on the edit box, and that
> doesn't work. In fact, I can't set the selection to anything else at all.
> I'm returning TRUE from OnInitDialog, and I thought that the focus could
be
> set to a control only if you call SetFocus on that control and then return
> FALSE from OnInitDialog.
>
> Any ideas?
>
> thanks,
> Stuart
>
>


0
7/21/2004 5:37:58 PM
Reply:

Similar Artilces:

Access 2003 resets form variables during debugging while the form is open
Hello, I am using MS Access 2003. (FWIW, this is about an ADP project, not MDB.) A form has a variable that is initialized (by some function call) in Form_Load() and then stays unchanged for the form's entire lifetime. (In a language more advanced than VBA, it would be a constant, not a variable; unfortunately, in VBA I cannot initialize a constant by non- constant expression). Specifically, in my case it looks like this: Private sTempFileName as String ... Private Sub Form_Load() ... sTempFileName = GenerateTempFileName(...) ... End Sub Priv...

if cell is text move left one column
ColB is a long list with sections names followed by category codes I need to move the text into colA leaving colB with codes only (all numbers) ColB. Doors 940590 555998 447006 447008 810697 810705 810706 810707 Windows 619435 525691 525692 Try Sub Macro1() Dim lngRow As Long For lngRow = 1 To Cells(Rows.Count, "B").End(xlUp).Row If Not IsNumeric(Range("B" & lngRow)) Then Range("A" & lngRow).Value = Range("B" & lngRow).Text Range("B" & lngRow).Value = "" End If Next End Sub -- Jacob ...

office 2000 [excel] cannot open previously OK file. Help
When trying to open a Microsoft Excel Work Sheet that I had accessed modified and saved to only yesterday [Office 2000] a window pops up with: "name.xls cannot be accessed. The file may be resd-only, or you may be trying toaccess a read only location. Or, the server the document is stored on may not be responding." Older files stored on the same mediums ;HD, Flash memory or 3.5in. diskette are accessed with no problem. This is on a network drive? ...

Cannot open Excel attachment from e-mail when Excel is already ope
This is driving me crazy. If I already have Excel open (with or with out a spreadsheet open) I cannot open an Excel spreadsheet attached to an e-mail. If I close Excel and retry it will open Excel and the spreadsheet. Any ideas? I hate having to close all my open spreadsheets when I want to open a spreadsheet that's been e-mailed to me! One of these usually works with a similar problem starting workbooks by double clicking them in Windows Explorer. Maybe one will work for you and your email problem. Tools|Options|General|Ignore other applications (uncheck it) --- or --- Close E...

Outlook 2000 not opening.
I am having a major problem with outlook. Can anyone tell why Outlook will not open when selecting it. When I check in the processes there is an instance of Outlook.exe there but it is not doing anything. When a different user logs onto the machine Outlook will open fine with no problems. I have deleted the users profile and recreated it but to no use. I have tried comparing the local registry keys of the two users and they seem to be the same. Can anyone please help me as I have ran out of things to try. Thanks in advance. Justin Does Outlook start in /safe mode? (I'm assumi...

Mail will not Send/Receive automatically
I have outlook set up to send/receive every minute but it suddenly stopped doing so. Anyone have ideas why? Robin Several. For starters, a one minute polling interval is just nuts. It is difficult to determine why automatic polling is failing when you do not post your mail account type, connection type and polling settings. If automatic polling once worked and now fails, you also need to examine what changes were made to your setup before automatic polling stopped working. In general, here are the reasons automatic polling might fail in Outlook: 1. You have created an unrealistic po...

Add rows automatically? Accordion
Is there a way to automatically add/show rows that have data? I have a data entry sheet. Then I have a report. The report pulls data from the entry sheet. If there is no data for a specific line/row item, is there a way to automatically hide or not show the row(s) with no data? Thanks Thanks can I have more than one autofilter on a sheet? Sloth wrote: > Use the filter function > Select the data and click on... > Data->Filter->Autofilter > This should make an arrow appear at the top of the data (in the header row). > click the arror and select "Nonblanks"....

How do I create a click on + symbol to open a root and click on -.
I'm looking to create an excel file with drop down menus. I'd like to have a category. Click on the "+" symbol and the category opens up and shows all of the subcategories. Each category can further be opened if I so choose. Each category can be have a number total associated with it. When you click the "-" symbol. The subcategories close and the sum total of all subcategories is shown in the category total. example. creating a budget. Category is utilities sub categories are: phone, cable, electric, gas, etc... Monthly utility total ...

How do I copy the result of a check box into another check box?
I'm trying to copy the result of a "check box form field" into another check box. For example: if I check (or uncheck) one box in a form, another box later in the protected form will also be checked (or unchecked) , much like the ref + F9 command for the text form field. Is this possible? Thanks. This cannot be done without macros. If your project will allow macros - see http://word.mvps.org/faqs/tblsfldsfms/ExclusiveFmFldChbxs.htm -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> G...

can I snap wrap points to a text box
rather than having to add individual wrap points to the edge of a frame, which is never as accurate anyway, can they be set to 'snap' to a frame (eg the ellipse) so that they are perfectly inline, (and which would of course be a lot quicker)? Edit points will not snap. There are options for edit points, select a point, right click. If you hold down control, the cursor will turn into an x, you can delete a point with a click. Truly a good draw program would be preferable. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com &q...

Global distribution List Not Appearing in Outlook Global Selections list
I have created a global list in AD in Server 2003 ( using Exchange 2003) and assigned my users. For some reason the list is not showing in the Outlook client global address list. I have compared this list to others i have created in the past and cannot spot any differences. What am I missing? 1. Have you got it hidden from the GAL? 2. Using cached Exchange mode? Therefore requiring a rebuild of the OAB to see it? Oliver On Fri, 16 Feb 2007 13:24:05 -0500, "rlm" <rmorton@execpc.com> wrote: >I have created a global list in AD in Server 2003 ( using Exchange 2003...

140 MB file went to 5.08 MB after editting 1 table
Hello All - I need some ACCESS insight...please... Several years ago, I built an access db to track my business scheduling and accounts payable/receivable. So this database is EXTREMELY IMPORTANT TO ME. The file has grown to 140 MB. Today I made a copy of the file and then edited my calendar table. I removed all columns which had 2006 data (72 totals columns) - the table had about 144 columns originally. I then added 72 columns with 2008 headers. These columns are now blank since I have not added any 2008 data yet. Afterwards, I looked around and everything looks good - my 2007 data is the...

Select Nodes
I am using the XmlDocument Select Nodes method and it seems to work OK except that it returns embedded nodes in the collection when I only want the nodes that are not embedded. For example I have a statement as follows: nodes = doc.SelectNodes(\\Node1\\Node\\DesiredNode); It gives me back in the collection all the DesiredNode tags. If I select retrieve the nth node as follows node = nodes[n-1]; It gives me the correct node and all DesiredNodes that are embedded within the nth node. So if I ask for the first node it gives me the first node which includes about 5 embedded DesiredNode...

Updating a chart Automatically
Hi, i update a spreadsheet with new data from Access everyweek. I have a chart that displays the last thrity days, how do i do this automatically, so i dont have to keep updating the chart manually ? Thanks in advance Jay Jay Richardson wrote: > Hi, i update a spreadsheet with new data from Access > everyweek. I have a chart that displays the last thrity > days, how do i do this automatically, so i dont have to > keep updating the chart manually ? > > Thanks in advance Jay See www.tushar-mehta.com, Dynamic Charts. Dave dvt at psu dot edu ...

Dynamic Range Selection Using VBA
What I'm trying to accomplish is to be able to run a procedure that selects a range based on a number provided in another cell. For example; if the number 10 is in cell A1, then cells A20:A30 would be selected when I run the macro. If the number 6 is provided, then cells A20:A26 would be selected. Not sure where to start, so any help is appreciated. this may do what you want range("A20").Resize(range("A1").Value+1).select -- Gary Keramidas Excel 2003 "TEK" <TEK@discussions.microsoft.com> wrote in message news:DA9FFF99-FC28-...

how can i edit the positioning of the balloon comment in a word fi
how can i edit the positioning of the balloon comment in a microsoft word file ? please reply on my email What you can do is adjust the space reserved for the balloons in the margin. In Word 2007, on the Review tab, click Track Changes, and then click Change Tracking Options. Change the "Preferred width" setting. -- Stefan Blom Microsoft Word MVP "melikelmalik" <melikelmalik@discussions.microsoft.com> wrote in message news:80E5F3D3-04A0-4E81-B154-FA8459B25F00@microsoft.com... > how can i edit the positioning of the balloon comment in a mi...

Excel. I am having a problem with hidden text
As I type text in some cells, it does not always dispaly if it exceeds the cell length. I wish to keep the cell lenghts for the entire document, but do wish for teh text in that particular row to be displayed. How about if you select that cell, then format|cells|alignment tab|check wrap text And with that row selected format|row|autofit SHR77 wrote: > > As I type text in some cells, it does not always dispaly if it exceeds the > cell length. I wish to keep the cell lenghts for the entire document, but do > wish for teh text in that particular row to be displayed. -- Da...

pulling certain characters from a string of text
I need to look up "certain critera" within a string of characters, then return that "certain criterea" to a new column. Some examples of a strings of characters may look like these: K5J091509001 Sample PO#S881009 K55sample PO CarrieRJR TJ5 My "Certain Critera" I have listed on another sheet, named "REP ID" K5J S88 K55 RJR TJ5 How do I pull out the 3 characters of "Certain Criterea" from the string of text and copy or enter it into a new column? Hi, =left(a1,3) "SaraMack" wrote: > I need to look up "c...

Automatic changes in cells
Hi for some reason I now have to save my work for any formlas etc to change when I update a worsheet, how can I stop this as it is a pain and sometimes I need to do changes to see how they work before saving the work. Many thanks Click on Tools | Options | Calculation tab and set to Automatic calculation, as it is probably set to Manual. You can press F9 to force a recalculation under a manual setting. Make sure you save the file with the Automatic setting, to avoid it happening next time. Hope this helps. Pete On Feb 1, 11:42=A0am, Office 2004 Test Drive User <heepenm...@yahoo.co.u...

default text height comment
Is there a way to set the default text height for a new comment? Thanks mark (I've looked through help but can't find it if it's in there.) I assume you mean the font size? There is no text height available in Excel. A comment has a shape property and that is what you can use to change the font size. They didn't make it easy ... Range("D4").Comment.Shape.TextFrame.Characters.Font.Size = 12 -- Jim Cone Portland, Oregon USA http://www.mediafire.com/PrimitiveSoftware (free and commercial excel programs) "mp" <nospam@Thanks.com> wrote in message...

Change the text of a shape rather than its master
Hi, I build custom masters by mixing two general shapes, say square and circle together, and have text on both the shapes. But after I drop an instance of the master into a page, I cannot modify the text of the instance. To do so, I need to modify the text on the master, which is non-sense for me. How to change the text of a shape without modifying its master? Thanks! How are you doing this? By code or by the UI? Are you grouping the shapes? If you drag two shapes to the stencil, it will group the shapes. So instead of a square and a circle you have three shapes. A Square, Circle and the...

Opening Multiple Web Links in a Column
Hi, I am very new to using web links in excel. A task I do very often is open a list of different websites that are in various columns in an excel spreadsheet. I am quite sure I am doing it the slowest way possible, so I need some help please. Basically I have been clicking on one link at a time. When I do this, the first website opens and excel automatically minimizes, then I have to go re maximize excel and then click the next web link and the same thing happens, etc... very time consuming. I am wondering if there is a way, either through Excel or whatever means necessary, to open all...

Removing spaces from text #4
I'm in excel and i have a bunch of text data that has an extra space at the end of the text on the right hand side for each cell. Is there any easy way to remove this space? Use the TRIM() function. -- Kind regards, Niek Otten "lj" <lj@spu.edu> wrote in message news:1144876429.220961.309040@j33g2000cwa.googlegroups.com... > I'm in excel and i have a bunch of text data that has an extra space at > the end of the text on the right hand side for each cell. Is there any > easy way to remove this space? > I tried using that function but the results st...

Request Selection
Hi, if we try to assign an activity to an open Request there are all Requests available (include closed). is there a way to show only open requests in this select-formular ? regards armin ...

how to automatically update inventory list with sales
Please provide the help on how to update the inventory list when some items are sold. Do you want to check this out while you wait for an answer? http://office.microsoft.com/en-us/FX011429711033.aspx Epinn "lalani" <lalani@discussions.microsoft.com> wrote in message news:07A10BC7-97FB-4E93-A686-CAAE3AA2DE88@microsoft.com... > Please provide the help on how to update the inventory list when some items are > sold. The page that Epinn points out is probably as good as any. Excel is a rather poor tool for trying to track inventory. You'll notice that the actual...