473,625 Members | 3,222 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SetFocus()

I use a CDialog with several controls and I want to set the focus in one of
them , a CEdit, when an instance is created.
The trouble is that I can get a pointer to the CEdit window, say p, but if I
use the code
p->SetFocus();
then a warning about a fatal error " memory that can't be read " is issued
and application is killed.
I've tried the code in the constructor and after creation; both producing
the same effect.
Any help ?
Jan 30 '07 #1
4 2638
joseramonbravo wrote:
I use a CDialog with several controls and I want to set the focus in one of
them , a CEdit, when an instance is created.
The trouble is that I can get a pointer to the CEdit window, say p, but if I
use the code
p->SetFocus();
then a warning about a fatal error " memory that can't be read " is issued
and application is killed.
I've tried the code in the constructor and after creation; both producing
the same effect.
Any help ?
The Ui for the control is valid only after CDialog::OnInit Dialog() call.

Add your ui initialization stuff to the overridden method.
ismo
Jan 31 '07 #2
Thank you for you advice.
Following your advice I coded:
--------------------------------------------------
BOOL CDialog_Newchat ::OnInitDialog( )
{
CDialog::OnInit Dialog();
CEdit* p;
p= (CEdit*)this->GetDlgItem(IDC _NEWCHAT);
p->SetCapture() ;
.... etc
----------------------------------------
and this solved the error but didn't bring the desired effect of putting
next to come keyboard input into the CEdit control unless a left-mouse-click
on any place of the window application was made.
I have tried simple solutions ( SetFocus(), DoClick(), etc) but none
have worked.
Any further help?
José Ramón

"Ismo Salonen" wrote:
joseramonbravo wrote:
I use a CDialog with several controls and I want to set the focus in one of
them , a CEdit, when an instance is created.
The trouble is that I can get a pointer to the CEdit window, say p, but if I
use the code
p->SetFocus();
then a warning about a fatal error " memory that can't be read " is issued
and application is killed.
I've tried the code in the constructor and after creation; both producing
the same effect.
Any help ?

The Ui for the control is valid only after CDialog::OnInit Dialog() call.

Add your ui initialization stuff to the overridden method.
ismo
Feb 15 '07 #3

"joseramonbravo " <jo************ @discussions.mi crosoft.comwrot e in message
news:72******** *************** ***********@mic rosoft.com...
Thank you for you advice.
Following your advice I coded:
--------------------------------------------------
BOOL CDialog_Newchat ::OnInitDialog( )
{
CDialog::OnInit Dialog();
CEdit* p;
p= (CEdit*)this->GetDlgItem(IDC _NEWCHAT);
p->SetCapture() ;
... etc
----------------------------------------
and this solved the error but didn't bring the desired effect of putting
next to come keyboard input into the CEdit control unless a
left-mouse-click
on any place of the window application was made.
I have tried simple solutions ( SetFocus(), DoClick(), etc) but none
have worked.
Any further help?
SetCapture deals with the mouse, while SetFocus deals with the keyboard.

The thing is that while the active application can give focus away to any
window, no inactive application can steal the focus. This is very desirable
behavior from a user's perspective. I hated what happened in previous
versions of Windows: when I'm typing away in a window and some messagebox
pops up, it would dissappear as soon as I hit the spacebar, before I even
realized it was there. Also now when you try to activate your application,
Windows flashes the taskbar instead, that's also to keep asynchronous
notifications from disturbing work.

You can hook keyboard input system-wide, it's just a lot more effort.

But ask yourself, if your user is typing a Word document when the chat
window appears and reaches the end of the line without noticing the new
dialog, do you want those last few words+ENTER key to go to your dialog? Of
course not. Even worse, what if they had just copied something large and
embarassing, and now hit Ctrl+V, ENTER. That would be very bad for your
program to intercept.
Feb 15 '07 #4
Thanks. Your answer has helped me to "focus" the problem I was tampering with.

"Ben Voigt" wrote:
>
"joseramonbravo " <jo************ @discussions.mi crosoft.comwrot e in message
news:72******** *************** ***********@mic rosoft.com...
Thank you for you advice.
Following your advice I coded:
--------------------------------------------------
BOOL CDialog_Newchat ::OnInitDialog( )
{
CDialog::OnInit Dialog();
CEdit* p;
p= (CEdit*)this->GetDlgItem(IDC _NEWCHAT);
p->SetCapture() ;
... etc
----------------------------------------
and this solved the error but didn't bring the desired effect of putting
next to come keyboard input into the CEdit control unless a
left-mouse-click
on any place of the window application was made.
I have tried simple solutions ( SetFocus(), DoClick(), etc) but none
have worked.
Any further help?

SetCapture deals with the mouse, while SetFocus deals with the keyboard.

The thing is that while the active application can give focus away to any
window, no inactive application can steal the focus. This is very desirable
behavior from a user's perspective. I hated what happened in previous
versions of Windows: when I'm typing away in a window and some messagebox
pops up, it would dissappear as soon as I hit the spacebar, before I even
realized it was there. Also now when you try to activate your application,
Windows flashes the taskbar instead, that's also to keep asynchronous
notifications from disturbing work.

You can hook keyboard input system-wide, it's just a lot more effort.

But ask yourself, if your user is typing a Word document when the chat
window appears and reaches the end of the line without noticing the new
dialog, do you want those last few words+ENTER key to go to your dialog? Of
course not. Even worse, what if they had just copied something large and
embarassing, and now hit Ctrl+V, ENTER. That would be very bad for your
program to intercept.
Feb 20 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3255
by: amy | last post by:
I have a text box, after user input the value, a validate function trigered. if the value is invalid, alert display, and also set focus back to this control. The alert displays, but when the click the 'OK' in the alert, the set focus to this field does not work. see the code bellow: if (run!="" && IsNumber(run)==false && decimalinputvalid(run,2)==0 )
4
9674
by: Mad Scientist Jr | last post by:
i am trying to set focus to a specific control depending on the outcome of a validator control and it is not working. none of these methods are working to setfocus: 1. RegisterStartupScript("sf","<scriptlanguage='javascript'>document.form.MyControlID.focus();</script>"); 2. Andy Smith's FirstFocus control from http://www.metabuilders.com/tools/FirstFocus.aspx
8
34275
by: Shachar | last post by:
Hi All, I need to start a new process calc for example and when ever the user click on the button the application should setfocus to the calc application. I use this code but it is NOT working, what I do wrong ? 10x,
0
1519
by: MrsLeigh | last post by:
I have a datagrid on a web page. In the footer there is a field that should be recieve the focus, either at the start or after a button is clicked to insert the row that is being added in the footer. I created the following Sub... Private Sub SetFocus(ByVal ctrl As Control) Dim SetFocus As String = "<script language='javascript'>document.getElementById(""" & ctrl.ClientID & """).focus();</script>"
3
6671
by: Jim Devenish | last post by:
In my application vehicles arrive and depart from a workshop. The ArrivalDate and the HandoverDate are each entered. Sometimes the person who should enter the arrival date forgets to do so. When the vehicle is handed over to the customer and the HandoverDate is entered I wish to warn about the possibly missing ArrivalDate. In the BeforeUpdate event of HandoverDate I have: Private Sub HandoverDate_BeforeUpdate(Cancel As Integer) If...
12
2877
by: Michael R | last post by:
TabCtrl --- ..............Tab1--Subform1 ..............Tab2--Subform2---TabCtrl2---Tab21 ..........................................................---Tab22 ..........................................................---Tab23 ..............Tab3--Subofrm3 I need to setfocus on Tab22 I've tryed - me.Tab2.Tab22.setfocus and me.Tab2.Subform2.Tab22.setfocus and me.Tab2.Subform2.Form.Tab22.setfocus with no success.
0
1538
by: srinivasarao yarru | last post by:
hi sir, in access 2003 how we can use the setfocuse property(we have to lostfocuse from one field with in that we have to setfocuse in same field) i am using this code but not setfocuse to same field :- Description about this code:- Sex field is one combo box in two options male-1;female-2 IND_APPL is one combo box here options are applicable-1;not applicable-0 CODE:-
3
3468
by: srinivasarao yarru | last post by:
hi in access 2003 how we can use the setfocuse property(we have to lostfocuse from one field with in that we have to setfocuse in same field) i am using this code but not setfocuse to same field (this is my problem please give proper gidence for this problem) :- Description about this code:- Sex field is one combo box in two options male-1;female-2 IND_APPL is one combo box here options are applicable-1;not applicable-0
5
3275
agroover
by: agroover | last post by:
I can't seem to figure out how to get rid of the errors. I recieve the following error when I leave the Grade.SetFocus in my code... Microsoft Access can't move the focus to the control Grade GRADE.SetFocus - Highlighted when I hit debug on the error message Private Sub C_Click()
3
16957
by: ckrows | last post by:
I have a main form with a button that makes a subform visible. I added a button in the form footer of the subform that is supposed to hide the subform. This does not work because the focus is on that form. I tried moving the focus back to the main form and it fails because it says it does not recongize the entered form. I tried a docmd.close of the subform also nothing is working Please help! Here is all 3 attempts Main Form Name:...
0
8256
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8189
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8694
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8497
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6118
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4089
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.