|
Hey All,
I am having a small problem setting the focus to a control on a property page in my OnInitDialog() function.
BOOL CPage::OnInitDialog()
{
CPropertyPage::OnInitDialog();
<snip>
if (some_condition)
{
m_Edit.SetReadOnly();
m_ComboBox.SetFocus();
}
else
m_Edit.SetFocus();
return FALSE;
}
It does not matter if some_condition is TRUE or FALSE, the m_Edit control always has the input focus. m_Edit is the first control in the tab order. Does returning FALSE from OnInitDialog() not work for property pages, or am I missing something?
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
For a CPropertyPage -derived class, you need to use the OnSetActive() method instead.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Ok, I am starting to feel like a complete idiot. I still can't get this to work.
BOOL CPage::OnSetActive()
{
BOOL ret = CPropertyPage::OnSetActive();
if (some_condition)
m_Combo.SetFocus();
return ret;
}
m_Combo.SetFocus is called successfully, but the focus remains on the edit control when the page finally shows.
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
How about:
#define MSG_SETFOCUS WM_APP+1
BOOL CPage::OnSetActive()
{
BOOL ret = CPropertyPage::OnSetActive();
if (some_condition)
PostMessage(MSG_SETFOCUS);
return ret;
}
LRESULT CPage::MySetFocus( WPARAM, LPARAM )
{
m_Combo.SetFocus();
}
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
That definitely works, thanks. I will use that hack for now.
But is it really necessary to go through that that type of hack to set the focus to a control? There is obviously something that I am missing.
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
'Tis not a hack:
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q148/3/88.asp&NoWebContent=1
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Just because MS does it, does not mean it's not a hack;P
Thanks for the help and the link
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
I simply provided the link so you would have something to reference. Since the tab is the first control on the property page, it only makes sense that it would receive initial focus. I don't consider using PostMessage() a hack.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Ok im going to sound like an idiot asking this... But im having trouble figuring this out.. I'm trying to get it when i click "Button A" It will some words in "Text Box A" Yea im a newb i look like a newb i feel like a newb! Just someone help me please!
|
|
|
|
|
DarkRaven41 wrote:
Ok im going to sound like an idiot asking this... But im having trouble figuring this out.. I'm trying to get it when i click "Button A" It will some words in "Text Box A" Yea im a newb i look like a newb i feel like a newb! Just someone help me please!
Give control IDs to your button and edit box. Then handle the BN_CLICK event for your button and add a variable of the CString type to your edit box. Then in your button's BN_CLICK event handler function type something like (assuming "m_strText" is the name of the variable you added to your edit box):
m_strText = "Yea im a newb i look like a newb i feel like a newb!";
UpdateData(FALSE); // Update the UI.
That should do it. Good luck in your programming efforts!
Happy Programming and God Bless!
Internet::WWW::CodeProject::bneacetp
|
|
|
|
|
Like i said i am a NEWB! i got most of what you said but its still not working... I know im doing it wrong and thats why can you maybe explain it a little better? Thanks for your time!
|
|
|
|
|
Ok. Let me try explaining from the begining step by step.
1. Create an MFC project using the Dialog application type (I assume that is what you are doing).
2. Add a Edit Box and a Button from the Toolbox to your Dialogbox.
3. Using the Property window, change the Edit Box's ID to IDC_MESSAGE and the Button's ID to IDC_MESSAGE_BTN.
4. Using the Property window, change the Button's Caption to "Show Message".
5. Right-click on the Edit Box and click "Add Variable...". Change the Category to "Value" and then the Variable Type to "CString". Name the variable "m_strMessage". Click the Finish button. You will be directed to the code view. Go back to the dialog editor.
6. Right-click on the Button control (the one you renamed earlier) and click "Add Event Handler...". Make sure the Message Type is "BN_CLICKED" and click the "Add and Edit" button.
7. Delete the comment (the line beginning with the "//") and type in its place:
m_strMessage = "Hello World! I am a beginner in Visual C++ .NET!";
UpdateData(FALSE); // Updates the controls.
8. Compile and run the program. It should work. Enjoy!
If you are interested, you could go to Amazon.com and buy the book: Sams Teach Yourself Visual C++.NET in 21 Days (2nd Edition), ISBN- 0672321971, URL-http://www.amazon.com/exec/obidos/tg/detail/-/0672321971/qid=1086480839/sr=1-1/ref=sr_1_1/102-3025056-5268100?v=glance&s=books[^]
It will help you from a beginner level to knowing your way around the environment pretty well. Hope this helps.
Happy Programming and God Bless!
Internet::WWW::CodeProject::bneacetp
|
|
|
|
|
First you'll need a CEdit control variable (e.g., m_edit ). Then in the handler for the button, just make a call to m_edit.SetWindowText("some text") .
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hi,
I'm a newbie C++ programmer, and I'm wondering one thing: How do I use optional parameters in my methods?
|
|
|
|
|
well, if you mean this:
void function1 (a=0)
{
cout >> a;
}
if you call the function this way:
function1;
the result is that 0 will be printed
if you call the function this way:
function1(9);
the result is that 9 will be printed
|
|
|
|
|
|
Yeah, I knew it wasn't to hard Just had some trouble finding it. Thanks!
|
|
|
|
|
when i statically link the MFC libarary
i get this warning when i go to build the release
LINK : warning LNK4089: all references to "SHELL32.dll" discarded by /OPT:REF
what can i do about this?
|
|
|
|
|
There is nothing to do.
- Linker told to link to shell32.dll.
- Linker told not to link to modules where no functions are being used.
- Linker found that module being compiled does not use any functions from shell32.dll.
- Linker telling you this.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Go to the command line linker options and add /IGNORE:4089. (This warning is purely informational. Ignoring it causes no problems.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
How would one convert a float to an int without rounding it? Currently:
float f = 1.9;
int i = (int)f;
i would equal 2. How do I get it to not round, and have i equal 1 in the above example? Any help is appreciated.
-Dev578
|
|
|
|
|
As defined by the C++ standard, floating to integer conversions truncate. So 1.9 would convert to 1.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
int i = (int)(f + 0.5);
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
You expression rounds, which I think is the opposite of what he wants, which is simple truncation.
Software Zen: delete this;
|
|
|
|
|
i would not equal 2. Simple 'C'-style casts truncate, so you will see i == 1 .
Software Zen: delete this;
|
|
|
|