|
There is never a message map entry by "magic". They are added manually or by the class wizard.
EM_* are messages send to an edit control for getting or setting properties, or starting specific operations. So there is no need to process these messages by your application and they are not supported by the class wizard. For most of these EM_* messages there are corresponding MFC functions which just send the message with some optional parameter processing. So you might for example override CEdit::GetSel() (which sends the EM_GETSEL message) to add some funcionality.
In the case of EM_SETWORDBREAKPROC your application would send this message to the control to pass the address of a function. Then there is no need to handle the message because you can do the necessary operations just before or after sending the message.
|
|
|
|
|
Let me clarify from the oninitdialog I did editcntl.Sendmessage(EM_SETWORDBREAKPROC,0,(LPARAM)editcntlwordwrap);
I had assumed based on the documentation
Quote: A Wordwrap function defines the point at which the system should break a line of text for multiline edit controls, usually at a space character that separates two words
that when I would type in a space my call back function would get control, this didn't happen. However I kept on typing and when I did get to the end of the line my call back function did get control
|
|
|
|
|
How is that related to your initial question about a message map entry or a virtual function for this message?
What you have quoted describes what the function usually does.
I have never used it but would expect that it is called when required (e.g. every time when reaching the line limit while typing and when "the user presses arrow keys in combination with the CTRL key to move the caret to the next word or previous word").
Have a look at the EditWordBreakProc callback function (Windows)[^]. It describes the actions passed to the callback function which indicate when it is called.
But it does not matter when it is called. You just have to return a value according to the requested action. For the case of word break checks (WB_ISDELIMITER ), the return value is usually TRUE for a space.
|
|
|
|
|
I am getting an Error while compiling `DESolver.cpp`
DESolver.cpp: In member function ‘void DESolver::Setup(double*, double*, int, double, double)’:
DESolver.cpp:57:24: error: cannot convert ‘DESolver::Best1Exp’ from type ‘void (DESolver::)(int)’ to type ‘StrategyFunction {aka void (DESolver::*)(int)}’
calcTrialSolution = Best1Exp;
Detailed Error is shown Here
Complete Code
modified 29-Jan-21 21:01pm.
|
|
|
|
|
This appears to me to be a call taking a pointer to a function - it wants a pointer and didn't getting one. Add an ampersand and see how that works for you. This is a shot in the dark though because I do not see the code in its context or the prototype declaration of the function call in question. In other words, if you had posted more of the code you would likely receive a better answer.
|
|
|
|
|
Probably the ampersand will do the trick.
|
|
|
|
|
Instead of
calcTrialSolution = Best1Exp;
you have to write
calcTrialSolution = &DESolver::Best1Exp;
(so for all case statements, of cause)
|
|
|
|
|
Thanks It worked
modified 29-Jan-21 21:01pm.
|
|
|
|
|
Hi,
I have a server client application using TCP/IP sockets in MFC VS2017. Originally i have written the code in VS2008. Kindly see the below code which sends the data to client. But this same code gives me some problem in MFC VS2017.
In the below code when I assign the value 190.000015f to a local variable, its taking the value whereas when I assign it to the union member variable
UNI.S.fTestValue1
and
UNI.S.fTestValue2
it showing some junk value. Please help me to fix the problem
unsigned char* CSendValue :: SendLiveValues()
{
union USendLive
{
struct SSend
{
float fTestValue1;
float fTestValue2;
char cChr;
}S;
unsigned char Buffer[LIVEUNISIZE];
}UNI;
memset(UNI.Buffer,0,LIVEUNISIZE);
float fLocalValue;
float fTest;
fTest = 190.000015f;
fLocalValue = fTest; UNI.S.cChr = 'c'; UNI.S.fTestValue1 = fTest; UNI.S.fTestValue2 = 190.000015f;
return UNI.Buffer;
}
|
|
|
|
|
|
D.Manivelan wrote: it showing some junk value. Where is it showing, and what value?
|
|
|
|
|
float fLocalValue;
float fTest;
fTest = 190.000015f;
fLocalValue = fTest; UNI.S.cChr = 'c'; UNI.S.fTestValue1 = fTest; UNI.S.fTestValue2 = 190.000015f;
Output
190.000015 - Correct value
'Ô' - Junk value - Wrong
6.360e-39#DEN - Junk value - Wrong
1.401e-45#DEN - Junk value - Wrong
|
|
|
|
|
Most likely you are not converting your values to/from network order when sending and receiving. See htonf function (Windows)[^].
|
|
|
|
|
The same code works fine in VS2008.
And moreover the issue occurs when I try to initialize the union member before actually sending the data to the socket.
My question is why I am not able to assign a float value to the union member which is also a float variable. This same line of code assigns the value in VS2008. Why its not doing it in VS2017
UNI.S.fTestValue1 = fTest;
UNI.S.fTestValue2 = 190.000015f;
|
|
|
|
|
Well since we have no real idea of what your code is doing to produce these bad values, it is difficult to offer any further suggestions.
|
|
|
|
|
This function returns a pointer to a local variable. If you want UNI.Buffer to continue to be accessible outside the function you have to allocate memory for it somehow.
|
|
|
|
|
Just to extend the reply of Graham Breach:
move the
union USendLive
{
struct SSend
{
float fTestValue1;
float fTestValue2;
char cChr;
}S;
unsigned char Buffer[LIVEUNISIZE];
}UNI; to the CSendValue class ctor to make the UNI a class member.
Then your CSendValue :: SendLiveValues() would look like
unsigned char* CSendValue :: SendLiveValues()
{
float fLocalValue;
float fTest;
fTest = 190.000015f;
fLocalValue = fTest;<br />
UNI.S.cChr = 'c';<br />
UNI.S.fTestValue1 = fTest;<br />
UNI.S.fTestValue2 = 190.000015f;
return UNI.Buffer;
}
|
|
|
|
|
I've been familiar with C++ for a few years now but I can't seem to think of a good solution for debugging my code. Can anyone make a suggestion?
|
|
|
|
|
|
I should probably have mentioned. It's a class file, not a full program. I'm using Visual Studio Code and the Debugger wants an executable to run but I haven't even compiled the file.
|
|
|
|
|
Then you have first to compile and link it!
BTW, is this file already a part of some project?
|
|
|
|
|
You cannot test a class file in isolation, it must be part of an executable. And if you have not even compiled it yet, you are quite a way from that step. I would suggest getting a copy of Visual Studio 2017 (free from Microsoft) and using the tools that come bundled with that.
|
|
|
|
|
Of course your code must first compile.
Then you could make a simple executable just for testing it, i.e. stressing the class features by fully using its public interface.
|
|
|
|
|
Between your subject and your post it is not clear what you want to do.
If you want to formally 'test' your code then
1. Research unit test libraries and select one
2. Add the library to your project (not part of production delivery)
3. Use the library and write unit test code to test both happy path, boundaries and failure cases.
4. Run the unit tests.
If you want to information test your code then
1. Create ANOTHER project
2. COPY your class to it
3. Add a second class with a main method
4. Write a number of methods that exercise the code.
5. Build and run it.
6. If you make changes copy it back.
If you already know the class has a problem and you cannot not determine what the problem is
1. Find a way to replicate the problem (see two above examples.)
2. As per the other posts find a debugger and figure out how it works.
3. Step through your code in the debugger to find the problem.
Note that if you have large application and you already know that your class is failing then attempting to debug the entire application just so you get to the class is not very effective.
|
|
|
|
|
Do you think is there any other or rather say faster way to remove the bug from solution! I doubt there is any. I remember when I don't know how to debug the MFC application, I used to put MessageBox to identify the pain areas. You think how many time have to run application just to point the pain location, if I know how F9,F5 and F10 work at that time, my time would be reduced by 99% in my case.
|
|
|
|