473,386 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 2618
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::OnInitDialog() 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::OnInitDialog();
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::OnInitDialog() call.

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

"joseramonbravo" <jo************@discussions.microsoft.comwrote in message
news:72**********************************@microsof t.com...
Thank you for you advice.
Following your advice I coded:
--------------------------------------------------
BOOL CDialog_Newchat::OnInitDialog()
{
CDialog::OnInitDialog();
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.microsoft.comwrote in message
news:72**********************************@microsof t.com...
Thank you for you advice.
Following your advice I coded:
--------------------------------------------------
BOOL CDialog_Newchat::OnInitDialog()
{
CDialog::OnInitDialog();
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
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...
4
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....
8
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...
0
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...
3
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. ...
12
by: Michael R | last post by:
TabCtrl --- ..............Tab1--Subform1 ..............Tab2--Subform2---TabCtrl2---Tab21 ..........................................................---Tab22...
0
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...
3
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...
5
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 ...
3
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...

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.