|
Hi everyone,
i made already my own WM and it works nice
i made it like this:
In the Grid :
GetParent()->PostMessage(WM_COMMAND, WM_GRID_DOWN);
with a define for this kind of mesage :
#define WM_GRID_DOWN (WM_USER + 1)
and in my View :
ON_COMMAND(WM_GRID_DOWN,On_Grid_Down)
with a function :
afx_msg void On_Grid_Down();
Now, i need to send a message from the Grid to the View with a parameter.
Is there another kind of message?
Thanks a lot !
|
|
|
|
|
What are you doing?
Why are you posting a WM_COMMAND with a self made up UI event and control ID?
Why do I ask these questions???
Here's what MSDN[^] has to say about WM_COMMAND message:
"The WM_COMMAND message is sent when the user selects a command item from a menu, when a control sends a notification message to its parent window, or when an accelerator keystroke is translated."
Furthermore the wParam for WM_COMMAND has two meanings (your made up WM_GRID_DOWN):
it's a concatenation of the notification code and the ID of the control that sends the WM_COMMAND message.
Clearly you have not understood how to use user defined messages.
Your code "works", but it has about a dozen built-in assumptions that you don't seem to know about and it might make a little more sense if you were subclassing a control but I get the impression that it's not what you're doing.
Even if you are subclassing a control, you're not using WM_COMMAND correctly.
Read Joe Newcomer's article[^] on how to use user defined messages.
While you're at it, have a go on his other articles as well. They're outstanding IMHO. Especially how to use worker threads, the one suggested to you by David Crow about a week ago.
Please read those articles! A hundred questions on this forum cannot make up for not getting the concept and we, at least not I, cannot help you if you don't.
--
Roger
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"No one remembers a coward!" - Jan Elfström 1998 "...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying above
|
|
|
|
|
Sorry, but it's quite difficult to learn MFC into 2 month at work.
I don't make "Hello World" Projects from MFC-Books, i learn a basic operation of MFC
and must applic it directly on my big project with all conditions.
And to fall down from C# and JAVA on MFC won't facilitate it.
It's all new for me
|
|
|
|
|
baerten, I apologize if you found my post rude, that was not my intention.
However, I found it strange when you asked about threading a week ago and you were told, rather subtile perhaps, that you had not yet understood the multithreading concept by Michael Dunn, David Crow, myself and others.
The other day you posted again about the same problem suggesting that you did not follow the recommendations you were given and that the concept was still not within your grasp.
Don't get me wrong, we are all children in the beginning and that's allright.
I thought that the response you got earlier was too subtile and that's why I tried to make the message as clear as I could, perhaps I overdid it.
The reason is that I know it can create a lot of unnecessary problems if you go ahead without knowing you're taking the wrong path.
In my opinion I do you a greater favour if I make sure you understand me when I tell you that you're holding the map upside down, instead of telling you to run along and get lost in the forest.:->
At last:
Don't be sorry! Consider it a favour to be able to learn MFC on payed time.
If you're short for time, you cannot spend your precious initial time better than reading the suggested articles on Joe's pages[^].
--
Roger
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"No one remembers a coward!" - Jan Elfström 1998 "...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying above
|
|
|
|
|
WM_USER is obsolete so you should use WM_APP instead.
Why dont you use an ON_MESSAGE
#define UWM_TESTMESSAGE (WM_APP + n)
GetParent()->PostMessage(UWM_TESTMESSAGE, WM_GRID_DOWN, lOtherParam);
ON_MESSAGE(UWM_TESTMESSAGE, TestMessage)
afx_msg LRESULT OnTestMessage(WPARAM, LPARAM);
LRESULT CTestView::OnTestMessage(WPARAM wParam, LPARAM lParam)
-- modified at 8:18 Friday 17th November, 2006
|
|
|
|
|
|
baerten wrote:
[...]
Now, i need to send a message from the Grid to the View with a parameter.
I think you can send simple parameters using the third and fourth parameters of PostMessage function. For example:
GetParent()-> PostMessage(WM_COMMAND, WM_GRID_DOWN, (WPARAM)1234, (LPARAM)5678);
In case of longer data, try dynamic allocation:
MyData * data = new MyData(. . .);
GetParent()-> PostMessage(WM_COMMAND, WM_GRID_DOWN, 0, (LPARAM)data);
In this case the receiver should delete the data using delete . Alternatively use SendMessage :
MyData data(. . .);
GetParent()->SendMessage(WM_COMMAND, WM_GRID_DOWN, 0, (LPARAM)&data);
I hope this helps.
|
|
|
|
|
It works already,
thanks nevertheless
|
|
|
|
|
As Roger indicated, you should read the article by Joseph M. Newcomer. By relying on WM_APP or WM_USER, you run the risk of clashing (trust me when I say it happens all too easy when you start using a number of user defined messages )
Message Management[^]
I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:
|
|
|
|
|
Hi,
I have four threads in my application and want to show some log messages from each of them into a common list box owned by application.
I want that
Thread#1 always show its log message into row #1 of listbox
Thread#2 always show its log message into row #2 of listbox
Thread#3 always show its log message into row #3 of listbox
and so on ...
Is it possible, if yes then how, and if no then what could be the alternate way.
Waiting for your replies.
Best regards.
Cyber Friend
|
|
|
|
|
Cyber Friend wrote: Is it possible
Yes.
Cyber Friend wrote: if yes then how
Not that easy. Better would be to have one list box for each thread, living near each other. That way you do not have to mess up with columns.
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
|
|
|
|
|
Rage wrote: Not that easy. Better would be to have one list box for each thread, living near each other. That way you do not have to mess up with columns.
Not that easy neither: you cannot update the listbox from another thread. You better send a message to the GUI thread with the string in it. Otherwise, you'll have problems.
|
|
|
|
|
Cedric Moonen wrote: you cannot update the listbox from another thread
Never said you can ! I just realized that he was actually asking for synchronization help rather than simply listbox handling.
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
|
|
|
|
|
Have each thread Post a WM_USER* message to the main thread. Trap this message and update the list accordingly.
|
|
|
|
|
Hi,
Thanx for reply.
I will try this method.
Best regards.
Cyber Friend
|
|
|
|
|
Have each secondary thread post a message to the primary thread. In that message, set WPARAM to a value indicating which thread the message is from. That way, you can call InsertString() with an appropriate index value.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
« Programm3r » wrote: char strDest[100];
Try a ZeroMemory on strDest before using it.
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
|
|
|
|
|
Thank you Rage, It seems to have done the job...
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
Pasted from MSDN:
"The strncpy function copies the initial count characters of strSource to strDest and returns strDest. If count is less than or equal to the length of strSource, a null character is not appended automatically to the copied string."
You have to terminate the string yourself.
Rage suggested one way to it to be absolutely sure. Another way is to place a '\0' at the correct position, i.e. at the end of the string if you know where that is.
--
Roger
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"No one remembers a coward!" - Jan Elfström 1998 "...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying above
|
|
|
|
|
Thank you Roger, the qoute form MSDN makes perferct sense now
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
Take the function void foo(unsigned char * param) . It does not change the value of the string (it's a Win32 API function, don't ask me why it's not const). Now i'd like to pass it the value of std::string MyString . I do this liek that
foo(reinterpret_cast<unsigned char *>(MyString.c_str()));
but this can hardly be the recommended way (it works, but it's bad). Any suggestions anyone ?
|
|
|
|
|
why not the simple static_cast ?
i can't see anything wrong otherwise...
|
|
|
|
|
static_cast gives a compiler error:
error C2440: 'static_cast' : cannot convert from 'const char *' to 'unsigned char *'
|
|
|
|
|
hum, yes, that's right (i have no compiler with me at the moment...).
does it work without any explicit cast ?
|
|
|
|