|
1) User defined message is declared as Follows [ Defined in Both Sender and Receiver ]
#define TEST_MSG WM_USER + 1
2) The Message data Structure Declared [ In both The Application ]
class msgData<br />
{<br />
public:<br />
int msgNo;<br />
CString data;<br />
};
3) Window1 in App1 Sending the Message
void CTesterDlg::OnButton1() <br />
{<br />
HWND hw = ::FindWindow(0, "TestDCLeak") ;<br />
msgData * data = new msgData();<br />
data->data = "Sample Message" ;<br />
data->msgNo = 20 ;<br />
::SendMessage(hw, TEST_MSG, (WPARAM) data , 0 );<br />
}
4) The Following Message Map is Added in the AFX_MSG_MAP Section of the App2:
ON_MESSAGE (TEST_MSG, OnTest )
5) The Linkage b/t the Handler and the Message is Done as Follows [ In App 2] :
afx_msg LRESULT OnTest(WPARAM wParam, LPARAM lParam);
6) Window 2 in App2 Receiving the Message
LRESULT CTestDCLeakDlg::OnTest(WPARAM wParam, LPARAM lParam)<br />
{<br />
msgData * theData = (msgData * ) wParam ;<br />
AfxMessageBox(theData->data);<br />
return 0;<br />
}
* I can Find the App2 Message is Handler is Invoked & the pointer thedata in App2 is Equal to pointer
data in App1.
* But, I can't Able the get the data packed in App1, inside the App2..
Can Anybody Please Explain why this is Happened? What Correction I should take in Code?
|
|
|
|
|
These are 2 different applications ?
Then, forget about it because they don't share the same address space. You won't be able to share memory between two applications.
You'll need to go for another way to share your data. Either pipes, memory mapped files (I only used this one), or even files.
|
|
|
|
|
Cedric Moonen wrote: memory mapped files
Can you Please Explain the Technique?
|
|
|
|
|
It is a little bit complicated to explain in details but basically it is memory that can be shared between several applications. This memory 'pool' has a name that identifies it, then, given this name, you can get a pointer to the start address of the memory pool and from there you can retrieve data.
Take a look here[^] for a start but it will require some time to implement.
|
|
|
|
|
Instead of sending the user defined message(TEST_MSG), Use WM_COPYDATA Message
nave
|
|
|
|
|
Thanks, I will Try..
-- modified at 3:39 Friday 7th April, 2006
|
|
|
|
|
Yes it's true, you can use WM_COPYDATA also (I forgot about that one). But be carefull because you have to take care of what you send. Take a look at the MSDN[^] for more details.
|
|
|
|
|
Hello,
i m s/w professional mainly in C,C++. but now i want to learn VC++ and i want so start with develop a GUI in VC++.
so pls guide me or suggest me. "how to start?"
kedia
|
|
|
|
|
Go to the Site www.FunctionX.com
It has a very good VC++ Tutorials for the Beginers.. [ You have to click the VC++ Link inside it]
|
|
|
|
|
looser, Codeproject is the best programming forum ever
|
|
|
|
|
And the crowd applauded maddly
"Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Kedia wrote: "how to start?"
Go to the Site www.FunctionX.com
It has a very good VC++ Tutorials for the Beginers.. [ You have to click the VC++ Link inside it]
|
|
|
|
|
|
ask specific question and you'll find all the help you want about Visual Studio environment here...
|
|
|
|
|
Hi Kedia,
As of me, I do suggest CoderSource.net, to the beginners.
http://www.codersource.net/codersource_mfc_prog.html[^]
You can get most of the concepts for "Windows Programming in VC++ - MFC".
I've enjoyed Functionx.com too.
Come here to CodeProject.com, only for specific problems.
Enjoy programming in VC++,
Sarvan AL
|
|
|
|
|
1) i'm not Kedia
2) you're wrong : Codeproject has plenty of beginners tutorials/articles, and the forums are full of very professional developpers.
|
|
|
|
|
Hello
MSDN help is useful for u.
CDC is main class in GUI
Regards
KK
|
|
|
|
|
Krishna Kumar N wrote: CDC is main class in GUI
I am afraid you are wrong... CDC is main class of graphics, right?
- NS -
|
|
|
|
|
|
#include "AddSectordlg.h"
#include ".\addsectordlg.h"
why does VS2003 adds these two lines in an mfc application, all i can see is that the two paths are same so why two seperate entries.
*radio crackle*
The cucumber has left the salad
- I say again -
The cucumber has left the salad
|
|
|
|
|
when you use the wizard to generate some code (add of a new event handler for example), it includes in the cpp file modified the related header.
the .\ means that the header - by its relative path that it - is located in the same directory as the cpp.
but this is a bug of the environment. it is useless...
you can without problem delete this #include ".\addsectordlg.h" because the file is already included the line before...
|
|
|
|
|
i hv created a thread. the cpu percentage during this time is 100%.
Any alternate soln for these.
|
|
|
|
|
What are u doing inside that thread....?
Put some sleep...
nave
|
|
|
|
|
Naveen R wrote: What are u doing inside that thread....?
Put some sleep...
Very bad advice for "solving" CPU usage problems in threads. It never resolves the underlying cause of high CPU usage. And how long should the thread sleep? 10 ms is probably the smallest quantum that can be gotten, and that might be too long to be responsive in some cases. And in other cases 10 ms isn't nearly long enough. So any choice is completely ad hoc, made as a result of some testing on the developer's machine for conditions that might not be valid on the user's machine.
In my experience, the presence of Sleep() in a thread, with the possible exception of Sleep(0), is generally a bad design choice.
Best regards,
Mike
|
|
|
|
|
Threads, like any other process, will take up as much CPU as there is available. If you're doing pure processing in a separate thread, there's not a lot you can do - you can reduce the priority of the thread but this will only reduce the CPU time if other processes are running too.
I suspect more likely you're writing code like:
void MyThread()
{
extern volatile bool isThereAMessage;
while (!isThereAMesage) { }
...process message...
}
This type of behaviour, spinning in a loop waiting for something to happen, is a frequent cause of threads taking up all available CPU time. If you are in this kind of situation, then I suggest you look at your OS's thread synchronisation and wait functions. If you're on windows, WaitForMultipleObjects, WaitEvent and similar. These put your thread to sleep until a message (or timeout) occurs, releasing the CPU for other processes to use it.
[NB the code example I have above is it itself not strictly thread safe; instead of using pure volatile bools, one should use thread safe calls, for example the Win32 InterlockedIncrement() and InterlockedAdd() etc]
Matt Godbolt
Engineer, ProFactor Software
StyleManager project
|
|
|
|