|
You do realise this is a C++ group, with a strong bias to MFC?
There is a java and a javascript forum on codeproject too.
Good luck,
Iain.
I am one of "those foreigners coming over here and stealing our jobs". Yay me!
|
|
|
|
|
Hi,
I have a CWinThread::run overidable that is generating a division by zero at a call to IsIdleMessage which I cann't for the life of me figure out why
Any insight is appreciated
<pre lang='cpp'> int SockCLeintThread::Run()
{ ASSERT_VALID(this);
MSG m_msgCur;
// for tracking the idle time state
if (!flags.is_connected)
return TRUE;
BOOL bIdle = TRUE;
LONG lIdleCount = 0;
// acquire and dispatch messages until a WM_QUIT message is received.
for (;;)
{ phase1: // check to see if we can do idle work
while (bIdle && !::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE))
{ // call OnIdle while in bIdle state
if (!OnIdle(lIdleCount++))
bIdle = FALSE; // assume "no idle" state
} // phase2: pump messages while available
do { // pump message, but quit on WM_QUIT
if (!PumpMessage())
return ExitInstance();
// reset "no idle" state after pumping "normal" message
<b>if (IsIdleMessage(&m_msgCur))<=== code causing exception </b> bIdle = TRUE;
lIdleCount = 0;}
} while (::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE));
}
ASSERT(FALSE); // not reachable
} </pre>
|
|
|
|
|
have you overridden IsIdleMessage ?
|
|
|
|
|
|
Why are you overriding CWinThread::Run() anyway? I don't see anything in your code that would require you to do this.
|
|
|
|
|
I am overriding it because I want to use PostthreadMessage and am using the code to create aa mesaage queue
|
|
|
|
|
Hi,
All my exceptions Were occurring in CWinThread::Run Being an Assembler programmer I went into Assembly mode to try and debug it
However the optimizer made things crptic
I then proceeded to use the #pragma to turn off optimization after doing this however the exceptions disappeared
Thanks Again
|
|
|
|
|
You don't have to override Run() to use PostThreadMessage() , and you also don't have to manually create a message queue.
|
|
|
|
|
Hello!
In my current project I'd like to have some additional std::string functions, like trim[r/l], to_lower/to_upper, split and stuff like that.
I know that inheriting from std::string borders on heresy, but I am not sure what else I should do.
I could make a file like strtools.h where all the functions I want are defined but that does not fit the OO scheme of std::string and C++ in general.
Or I could make a class that does not inherit from std::string but privately uses a variable of that type. That would obey OO rules but it's heck of a lot work to do and I guess there will be some overhead (I haven't tested it yet, so hopefuly you can tell me)
What would you recommend me to do and why?
Thanks in advance.
modified 31-May-12 9:29am.
|
|
|
|
|
i usually do it with global (non-class) functions. it's cleaner than going through all the ridiculous hassle of extending std::string.
|
|
|
|
|
Be sure to look at Boost String Algorithms Library[^]. It already does what you want, and even if you don't want to use it directly, there is a lot to learn from there.
|
|
|
|
|
Good suggestion!
|
|
|
|
|
Write a set of free functions that take const string references and spit out strings modified the way you want. There are a couple of observations here...
First one is that just because a function isn't a member of a class doesn't mean that it violates some great principle of OO. A free function can be as much a part of a class's interface even if it's not a member:
class A
{
public:
A &operator+=( const A &add_to );
};
A operator+( const A &a, const A &b )
{
A temp( a );
temp += b;
return temp;
} In this example the freestanding operator+ is very much part of A's interface. As is the usual practice of declaring an insertion and/or extraction operator to do input or output:
class B
{
public:
friend std::ostream &operator<<( std::ostream &str, const B &print_me );
friend std::istream &operator>>( std::ostream &str, const B &load_me );
}; Second one is that C++ isn't just an OO language. OO is probably the dominant idiom but even hardcore OO programmers use a fair number of generic techniques e.g:
std::string to_upper( const std::string &source )
{
std::string upper_case( source.size(), 0 );
std::transform( begin( source ), end( source), begin( upper_case ), toupper );
return upper_case;
} and:
std::string &to_upper_in_place( std::string &upper_case_me )
{
std::string temp = to_upper( upper_case_me );
std::swap( temp, upper_case_me );
return upper_case_me;
} They're both free functions but the second works very much like you'd defined a member of std::string.
Anyway, I've gone on enough. The points I was trying to make are:
- free functions can be part of a class's interface
- if a class hasn't been built to be extended by inheritance (which std::string isn't) then you have to use free functions to extend it
modified 31-May-12 12:40pm.
|
|
|
|
|
|
This is better than some of the articles we see on here. How about posting this into Tips & Tricks for the benefit of the community as a whole?
|
|
|
|
|
I'll have a crack at that over the weekend, thanks for the suggestion.
|
|
|
|
|
Hello Experts,
I want to know how to create a Remote desktop Application in Visual C++ 6.0 (i.e in MFC),I have good knowledge in MFC,but I need to create my own program.
Is there any chance I can create it using C++
Please let me know.
Regards
Kiran
|
|
|
|
|
Please explain what you mean by "Remote desktop Application"?
|
|
|
|
|
Member 9052985 wrote: Is there any chance
Doesn't seem like there's much.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
If you have "good knowledge in MFC", then you should already know what you can do in C++.
In order to create a remote desktop app, you need to know a few things:
0.Sockets (maybe secure sockets while you're at it).
1.Server-client applications.
2.Screen capture methods.
3.Mouse/keyboard capture methods (and the inverse, how to transmit the captured keys).
Can you do it in C++, literally, no... you have to use APIs that are OS dependent... but that's just a technicality, so yes.. you can do it in C++ (with proper use of APIs).
|
|
|
|
|
|
I am trying to animate my object like below, the object should move back and forth, but with this i can't see the movement. please tell me whats going wrong in this code below. Thanks Sujan
[code]
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);
transObj2[0]=transObj2[0] - 40.0f;
Invalidate();
Sleep(5000);
transObj2[0]=transObj2[0] + 40.0f;
Invalidate();
Sleep(5000);
wglMakeCurrent(NULL,NULL);
[/code]
|
|
|
|
|
But there's no drawing code!
OpenGL maintains the positions of your vertices and polygons for 1 frame.
In this sample you never tell GL anything, except the HDC of the window you'd like it to draw in. Even this looks a little suspicious. Generally, one would get the HDC of a static control and throw that to GL.
You've not draw the objects at all, hence you'll not see them drawn in different positions.
Go lookup Nehe OpenGL tutorials. Or even 'Rotate Triangle openGL'...
|
|
|
|
|
MY OBJECT IS THERE I DINT POST THE DRAWSCENE PART OF THE CODE. IT'S DRAWN ON THE SCREEN, ONLY DIFFICULTY I AM FACING IN SIMULATING IT. I WANT THE OBJECT TO MOVE BACK AND FORTH FOR 1 MINUTE. HOW CAN I ACHIEVE THIS PLS HELP.
|
|
|
|
|
YOUR REWARD FOR YELLING IS NOTHING!
That's right, I'm going to give you nothing.
Bugger off!
|
|
|
|