|
Hi!
How do I make an edit box only validate it's contents when
hitting the enter key? The edit box is attached to a
variable, and I only want the variable to get updated when
I hit enter.
Something that's not necessary, but a "nice to have" would be
doing the same thing for the tab key. Besides doing the
validation, it would also tab over to the next control.
Steve
|
|
|
|
|
You need to use the OnKeyDown. When you detect the Enter, you can validate the Edit.
Cheers!!!
Carlos Antollini.
|
|
|
|
|
The usual way of doing this is to handle validation in the OnKillFocus method call for that object. Then, hitting Enter (which will submit the dialog if the edit control is on a dialog) or hitting Tab (which will go to the next field in the tab order if if the edit control is on a dialog) will both kick-off that event.
If you're rolling your own interface in a non-dialog setting, you should be subclassing the parent window to pre process all the messages that come through your main window proc, and that would be where you would do Enter and Tab key handling (and other key for that matter).
|
|
|
|
|
Does anyone know of a technique to "raise events" between two class objects? For example I have class A and Class B, I make a change to one of the member variables in class B, could be 20 of them, how do I notify class A of the change so it can see what has changed and act accordingly? Sort of of like Windows WinProc?
Here are some simplistic ideas I have come up with
1. Create a system timer within class A and have it poll a "isDirty" variable in B and that is when it knows something is amiss.
2. Create a message queue in class A that B would send things too, and when A has a chance respond to the message.
3. Give up C++ programming and go back to Visual Basic (Not that I can do what I need to do within VB)
I don't prefer C because that might weigh heavily on system performance, and 2 seems more complex than it should, and I am definitely trying to avoid 3 !
So if any C++ gurus can give me a hint or point me in the right direction I would be mighty appreciative of yous. <g>
Sam C
----
Systems Manager
Hospitality Marketing Associates
|
|
|
|
|
Don't use the timer for such thing. It is bad .
Take a look at the "Observer" design pattern (I think there is an article on it on CodeProject). This is the way to go. Basically, you subscribe objects ("event sinks") to an object that raises events.
I vote pro drink
|
|
|
|
|
Dang that was a fast response
I can see not many people want me to go with option 3 either <g>
Let me take a look at the observer design pattern. Thanks again for the quick response.
Sam C
----
Systems Manager
Hospitality Marketing Associates
|
|
|
|
|
|
Thanks for the respone and the URL I'll take a look at it, and thanks for helping me avoid option 3!
Sam C
----
Systems Manager
Hospitality Marketing Associates
|
|
|
|
|
The only way is to go with (3). Give up this C++ thing and code in VB. If you care for performance, implement time-critical things in assembly
I've heard that there's a group of open source programmers working on porting VB to Linux, so you'll be able to quickly adapt your app to this wonderful OS.
I think now I'm going to reply to my own posts
To Chris Maunder - do I qualify for 'The Most Stupid Post in VC++ Forum' award? Like CP Mug with Bob?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Actually, you qualify for the 'Most clever post in VC++ forum' award
Now, let's be serious. I've read that in VC++ 7.0 we have new keywords ( _event, I think) that enables "unified event handling". Of course, it is a non-standard extension. How do you like that?
I vote pro drink
|
|
|
|
|
Is this keyword usable outside of .NET world? I mean, they have something called Managed C++ which introduces new keywords like __gc and others.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
As far as I know, it has nothing to do with MC++. It is for the "native" code.
I vote pro drink
|
|
|
|
|
I know MC++ supports __event keyword (not _event as you said) to declare events through delegates, but I'm not aware that any such keyword exists in native C++.
// Fazlul
Get RadVC today! Play RAD in VC++
http://www.capitolsoft.com
|
|
|
|
|
If you have VS .NET Beta 2, take a look into documentation (I found this info there). I'm pretty sure, they added this "unified" event approach to native C++.
I vote pro drink
|
|
|
|
|
I knew I should've stuck with Visual Basic it rules!!! None of the complexities that are associated with C++ and chicks love it :-P
Yeah right!
Sam C
----
Systems Manager
Hospitality Marketing Associates
|
|
|
|
|
As for complexities, I don't think VB is much simpler than C++, when you have "big" projects (I've tried both).
As for chicks, I'm happily married, so this argument is also not valid for me.
I vote pro drink
|
|
|
|
|
Actually the comment was directed towards Tomasz, but since you replied...
We'll I have developed a ColorFORTH version of Internet Explorer and I'm happily divorced! Take that!
(gg)
Sam C
----
Systems Manager
Hospitality Marketing Associates
|
|
|
|
|
I give up. VB is definitely better.
I vote pro drink
|
|
|
|
|
Hello everyone,
Does anyone know if there is any simple way to change the font for menus from MS Sans Serif to Tahoma, as is done in Office 97?
If it is necessary to use owner-drawn menus, is there any way I can just change the font and then let default drawing take place?
Thanks very much,
Stephen Wilson
|
|
|
|
|
|
I posted a question a few days back about WM_COPYDATA.. I have a console app that needs to send CString data to several other apps with the same .exe name.. When I do the WM_COPYDATA I need all the other dialogs to look at the CString data and determin if the msg was intended for it (is this possible?).. I tried changing the window text name of the dialogs using ::SetWindowText("blahblah").. but when I send the msg to "blahblah" unless it is the first opened dialog box he will not see the msg.. is there a way to WM_COPYDATA from one app to several apps with the same .exe name?
Thanks,
Mike
|
|
|
|
|
If you're enumerating open windows and getting the HWND from the Window title, then you should have no trouble sending data to whichever window you want. The problem you have is that you specify a HWND in WM_COPYDATA, therefore you send the message to one Window only. You can do one of two things:
1/ Enumerate Windows and send the message to all the Windows that may want it, or
2/ If you always have the same number of windows up you can set up a chain where the message gets passed on if it's not needed.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
Thanks for the reply.. I think I may have it figured out.. Once you use WM_COPYDATA do you have to wait a certian amount of time before you can use it again? It seems to work fine if I wait for a minute or so between copying the data.. For example I have a console app with a list control and as I open dialog boxes I set a different name for each dialog and then I have the dailog box send its name to the console app then I can pick the name of the dialog from the list control and push a kill button and it sends a msg to the dialog with the name I picked and it closes the dialog box.. If i move right away to the next dialog box in the list and click close it comes back and says cant find dialog XXXXX.. if I wait for a minute or so and try again it works.. weird huh? If you want I can post some code of my WM_COPYDATA.
Thanks,
Mike
|
|
|
|
|
Maybe if you post some code - I've only used copydata to send info between two programs, so I've never had that problem.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
I have been doing some troubleshooting and found that when it sends the kill CString to the receiving app the string contains garbage along with the string.. Here is the code I use to send the string to the other app. Any ideas on how to remove the garbage?
Btw, the m_strKill is the name of the other window and the string being sent for the kill command..
UpdateData(TRUE);
LRESULT copyDataResult;
CWnd *pOtherWnd = CWnd::FindWindow(NULL, m_strKill);
if (pOtherWnd)
{
COPYDATASTRUCT cpy;
cpy.dwData = 0;
cpy.cbData = m_strKill.GetLength();
cpy.lpData = (void*)m_strKill.GetBuffer(cpy.cbData);
copyDataResult = pOtherWnd->SendMessage(WM_COPYDATA,
(WPARAM)AfxGetApp()->m_pMainWnd->GetSafeHwnd(),
(LPARAM)&cpy);
m_strKill.ReleaseBuffer();
}
else
{
MessageBox("Can't find "+m_strKill);
}
UpdateData(FALSE);
Thanks,
Mike
|
|
|
|