|
Hi all,
I have two classes one which is derived from CFormView and other which is derived from CWinThread. I want to pass calculated values from CWinThread derived class to the Class derived from CFormView Class. Now, what i wanted to know is that should i use SendMessage() API or PostMessage() API,to pass the values....
Thanks in advance
|
|
|
|
|
VCProgrammer wrote: Now, what i wanted to know is that should i use SendMessage() API or PostMessage() API,to pass the values....
Depends on your need and way you are passing it?
If you want to immediately return after notifying user of some event then you can use PostMessage also then make sure that you don't pass UDT's that are on stack, but native local variables are safe since they will be copied.
SendMessage blocks so that's synchronous, won't return unless the message is processed.
Nibu babu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
When SendMessage() is called, it doesn't return until the target window has processed the message. However when PostMessage() is called, it returns and doesn't wait for the target window to process the message. Therefore it depends whether you want the calling function to have a value returned or not - if so, SendMessage() is more appropriate, if not, then PostMessage() is more appropriate.
Regards,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
Since the sender is derived from CWinThread I assume that you want to send/post a message from a different thread than the supposed receiver is running in. Correct?
Like others already have advised, SendMessage() blocks until the message has been handled, as PostMessage() returns without waiting for the receiving thread.
The answer depends on your situation.
In case you are using different threads you'll have a potential deadlock situation if you're using SendMessage() , which you avoid completely by using PostMessage() .
On the other hand, since PostMessage() doesn't wait for the message to be handled, you won't get any result from the message handler.
What you could do is use SendMessageTimeout()[^] that will in case of a deadlock situation only lock the system for as long as you've set the timeout to be.
For more info on how to use threads and potential deadlock situations, read this[^].
I would suggest a queue between the threads where you queue your calculated values.
You could post a message to the receiver when you've added a new block of values to the queue.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hi,
I want to develop a window desktop application which is capable of screen capturing.
Can I get any application related to it.
Thanks
dhiraj Kumar saini
|
|
|
|
|
Have you searched Google and CodeProject for articles the same?
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
Hi,
I haven,t searched codeproject forum. Surely I will search and then again again repost if not able to get.
Thanks
Dhiraj Kumar Saini
|
|
|
|
|
He means have you searched on the Code Project for articles that may help you with your problem?
Regards,
--perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
CamStudio's Desktop Recorder[^] is an excellent one, If you are looking for a open source, professional screen capturing tool for reference. You can download the source from here[^].
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
See here.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Hello guys,
I want to write an application able to detect system wide keyboard hooks installed on the machine.
Is there any way to enumerate all system wide keyboard hooks?
Thanks.
modified 7-Mar-17 16:35pm.
|
|
|
|
|
See DebugProc()[^]. If the wParam value passed on to DebugProc() is WH_KEYBOARD , then the hook installed is a Keyboard hook (or if it is WH_KEYBOARD_LL , then that is a low level keyboard hook).
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
I need some opinions, does make inheritance C++ slower than C and if yes, would it make sense to not use inheritance at all for that reason. I must admit that I'm not getting the idea behind inheritance and therefore would rather like to keep inheritance out of my code! I mean I know how to use inheritance in theory but I always felt it's something programmers don't really need.
In short terms, I HATE INHERITANCE. So I'm looking for a good reason(excuse ) to keep it out of my code. I'm working on a project right now and so far I'm not using inheritance and I'm happy with that.
So in order to have something to write into my Technical Design Document of the Gunman project. I need a few good reasons why I kept inheritance out of my code. This Technical Design Document later will read my future employer, so it's part of my CV and I need something good to write. Everything, but no excuses!
|
|
|
|
|
Cyon111 wrote: I need some opinions, does make inheritance C++ slower than C and if yes, would it make sense to not use inheritance at all for that reason.
Inheritance helps to reuse the existing code with little or no modification. It always improve your performance design and reduce complexity - if used wisely.
I think the term performance made confusion.
Cyon111 wrote: In short terms, I HATE INHERITANCE. So I'm looking for a good reason(excuse Laugh ) to keep it out of my code. I'm working on a project right now and so far I'm not using inheritance and I'm happy with that.
I recommend you to go through the object oriented concepts once again.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
modified on Tuesday, August 26, 2008 5:47 AM
|
|
|
|
|
Funny how you got downvoted on that.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
Rajesh R Subramanian wrote: Funny how you got downvoted on that. Smile
No idea buddy. Well, now a days I try to follow CPillani. He's so cool to down votes. He really never minds it.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Does inheritance make C++ slower? Assuming you're comparing to C++ used without inheritance then the answer is probably yes a tiny bit in the short term but no in the longer term. Each call to a virtual instruction takes a few ~5 instructions more than a non virtual call but becuase your code will be smaller when written using inheritance, with less copying of data the overall result has a reasonable chance of being faster, less cache misses, faster loading, faster Dll rebasing etc.
If you're really keen on speeding up your C++ code you'll get 1000 x as much performance improvement from using an optmised heap manager as you will from avoiding a few virtual calls. As for inheritence, it's there for a reason and that reason is that a lot of very experienced developers think it's good idea and make use of it. Draw your own conclusions
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|
I was afraid of that. A lot of very experienced developers you say? Well, whether I want it to or not I think as soonest I have time available, I have to run some tests on inheritance. I mean, if I try to play the smart ass and say that inheritance is for nothing but the truth is the opposite, what would my future employer think? NOOOOOB! That would be bad!
|
|
|
|
|
I think you are only looking at one side of the problem. Everything is not only about performances. Otherwise, why not write everything in assembler ? That's certainly in theory the most performant choice. In theory only because of course you loose a lot of features that help you write maintainable code, so you will probably introduce more bugs.
I know what you think about it because I had the same point of view when I learned that at school. I also thought that virtual functions were totally useless. Man, was I ever so wrong . I think you need to play a lot with it to see that it can make your code much more readable. But you have to switch to the OO way of thinking which is quite difficult at the begining. Otherwise, why using C++ if you are merely doing C using the C++ syntax ?
|
|
|
|
|
Exactly. Of course as Cedric says it's not al about performance. There's also all the cool things you can do with inheritance that you could of course do without it but it wouldn't be any fun.
Here's my map class for example
<br />
template < class TFirst, class TSecond ><br />
class CTMap : public CTIndexedArray < CTMapPair < TFirst, TSecond > ><br />
{<br />
public:<br />
typedef CTMapPair<TFirst, TSecond> TItem;<br />
<br />
CTMap()<br />
{<br />
}<br />
<br />
virtual ~CTMap()<br />
{<br />
}<br />
<br />
bool operator != (CTMap<TFirst, TSecond>& Comperand)<br />
{<br />
return ! CTIndexedArray< TItem >::operator ==(Comperand);<br />
}<br />
};<br />
Yep, that's all of it. So small I can post it here thanks to inheritance.
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|
Cyon111 wrote: This Technical Design Document later will read my future employer, so it's part of my CV and I need something good to write.
Well, don't put that in your CV because I guess nobody a bit experienced will hire you. Without inheritance, you wouldn't be able to realistically write Object Oriented code. And I can assure you that OO programming is quite used in C++ or any library that you will use. I guess you didn't really understand all the power it can bring to your code. Read some articles about polymorphism, you'll see what it will bring to you.
Cyon111 wrote: but I always felt it's something programmers don't really need.
I use it all the time, believe me. I can't imagine not using it anymore.
|
|
|
|
|
Cedric Moonen wrote: Well, don't put that in your CV because I guess nobody a bit experienced will hire you.
Yes, to this conclusion I came with the last reply of mine, too.
Hell it was a good idea to post here before I put it seriously into my TDD and not to mention into the CV.
|
|
|
|
|
If inheritence was useless, why would people invent new languages such like Java or C# which are fully OO ?
man, you certainly have to go through OOP and forget your way of thinking in C.
|
|
|
|
|
Yes, I guess I stick to C pretty much. My slogan was: "Simple but effective!". With inheritance now I'm not sure whether I can maintain this slogan any more. Though, if it's true that inheritance can improve the design of the code, and I'm beginning to understand that it can, then for the sake of my slogan indeed I HAVE to include inheritance into my code.
|
|
|
|
|
Cyon111 wrote: Yes, I guess I stick to C pretty much. My slogan was: "Simple but effective!".
Simple? You must try working on large code bases, one written on C and another on C++. You will then know which is more simpler.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|