|
Hi
The SendMessage function is used to send a message directly to a window procedure.
Does this means that for messages received by SendMessage, the message loop( GetMessage & DispatchMessage) is not needed to process the message and call the windowproc.
What happens internally on SendMessage?
Welcome all suggestions
Thanks
Anil
|
|
|
|
|
anilFirst wrote: to send a message directly to a window procedure.
no. It will go through the message loop. Why dont you try it for your self?
nave
|
|
|
|
|
Naveen R wrote: no. It will go through the message loop.
No, it wont. Thats why its SendMesssage.
As opposed to PostMessage , which are posted to message loop.
|
|
|
|
|
ok ok..
So it directly call the window proc?
nave
|
|
|
|
|
Naveen R wrote: So it directly call the window proc?
No exactly, but its system(windows) does that.
|
|
|
|
|
anilFirst wrote: Does this means that for messages received by SendMessage, the message loop( GetMessage & DispatchMessage) is not needed to process the message and call the windowproc.
It depends on from what thread the message is "sent".
If the message is sent from the thread that created the window, the message handler will get called directly without taking the detour of the message loop.
If the message is sent from another thread, the receiving thread must be running a message loop since a context switch will be made to the receiving thread while the sending thread is blocked. This is also the reason why a deadlock situation can occur when sending messages from different threads and the receiving thread doesn't process messages.
Have a closer look at MSDN documentation for SendMessage() here[^] below the "Remarks" section.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
In "Programming Windows" by Charles Petzold
"Programs generally don't call window procedures directly. The window procedure is almost always called from Windows itself. A program can indirectly call its own window procedure by calling a function named SendMessage"
So how the SendMessage and PostMessage invoke window proc's? What is internal working of both?
Thanks
Anil
|
|
|
|
|
What Charles Petzold meant with the statement you've quoted is probably that you seldom call a message handler directly as an ordinary function call.
If you find yourself in a situation where you would like to call a message handler directly, you should call SendMessage() with appropriate message ID as argument. I guess this is what Petzold refers to as being "called from Windows itself" since your using the Win32 API method SendMessage() .
anilFirst wrote: So how the SendMessage and PostMessage invoke window proc's? What is internal working of both?
This addresses the message management routines from a different perspective than the Petzold qoute. The qoute answers a question such as "how do I call a message handler from my code", but I understand your question to be more like "in what ways does a message handler get called when sending a message with SendMessage and PostMessage".
A part of the answer for that question can be read in my previous post and also by following the MSDN link I provided.
In addition: when posting a message with PostMessage(), the message is always placed in the message queue for the receiving window and retrieved with a call to GetMessage() . The matching message handler is then usually determined by a switch-case statement and called with the parameters that came with the message.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
MessageLoop ( GetMessage & DispatchMessage ) not needed in some cases. So it means that SendMessage() can call WindowProc directly. For a test case call UpdateWindow() before MessageLoop will invoke WindowProc directly. WindowProc will be called with WM_PAINT message. Then only the control comes to MessageLoop.
|
|
|
|
|
anilFirst wrote: MessageLoop ( GetMessage & DispatchMessage ) not needed in some cases. So it means that SendMessage() can call WindowProc directly.
Yes. In case the message is sent using SendMessage() .
anilFirst wrote: For a test case call UpdateWindow() before MessageLoop will invoke WindowProc directly. WindowProc will be called with WM_PAINT message. Then only the control comes to MessageLoop.
I don't understand what you mean. Is this a question?
If you want to see how message handling works, I suggest you use your own user defined message ID. You cannot use WM_PAINT or WM_TIMER for this purpose since those messages are treated differently than other messages.
Try sending with SendMessage() and posting with PostMessage() from the main thread and see how the call stack differs in the two scenarios.
Then try sending the message from another thread and you'll find that the call stack looks the same as if the message was posted from the main thread.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
I did try user defined message using SendMessage() before the message loop, soon after a call to CreateWindow() API. The message was send from main thread only. The windowproc received the User defined messages. This means that the message loop is not needed for SendMessage to deliver messages to WindowProc.
|
|
|
|
|
i have to create a tab with items that change dynamically. i have to use only one dialog for all the tabs. how to do this?. is it possible
Arise Awake Stop Not Till ur Goal is Reached.
|
|
|
|
|
this is a very not advisable way but i am sure that it will work.
you can make different controls on the dialog visible property false and make it true when u need them
|
|
|
|
|
Take a look at this article[^], I think it does what you are looking for.
|
|
|
|
|
//*****************************Main Program ******************************
#include <stdio.h><br />
#include <conio.h><br />
#include <stdlib.h><br />
#include "ReadWrite.h"<br />
#include "Graph.h"<br />
<br />
<br />
void main(int doiso, char *thamso[])<br />
{<br />
<br />
GRAPH G;<br />
int rf=G.ReadData(thamso[1]);<br />
if(!rf)<br />
printf("Khong doc duoc file!\n");<br />
else<br />
{<br />
printf("Doc duoc file!\n");<br />
G.GraphAlgorithm();<br />
int wf=G.WriteData(thamso[2]);<br />
if(wf)<br />
printf("Ghi file thanh cong!");<br />
}<br />
<br />
getch();<br />
}<br />
//******************************Graph.cpp*********************************
#include <stdio.h><br />
#include <conio.h><br />
#include "Graph.h"<br />
<br />
int GRAPH::ReadData(char *FileName)<br />
{<br />
FILE *fp=fopen(FileName,"rt");<br />
if(!fp)<br />
return 0;<br />
fscanf(fp,"%d",&n);<br />
B=new unsigned char *[n];<br />
unsigned char *temp=new unsigned char [n];<br />
for(int d=0; d<n; d++, temp+=d)<br />
B[d]=temp;<br />
for(int i=0; i<n; i++)<br />
for(int j=0; j<n; j++)<br />
fscanf(fp,"%d",&B[i][j]);<br />
fclose(fp);<br />
return 1;<br />
}<br />
<br />
const int GRAPH::WriteData(char *FileName)<br />
{<br />
FILE *fp=fopen(FileName,"wt");<br />
if(!fp)<br />
return 0;<br />
fprintf(fp,"%d",n);<br />
for(int i=0; i<n; i++)<br />
{<br />
fprintf(fp,"\n");<br />
for(int j=0; j<n; j++)<br />
fprintf(fp,"%d\t",B[i][j]);<br />
}<br />
<br />
int nLT=label;<br />
if(nLT==1)<br />
fprintf(fp,"\nDo thi lien thong!");<br />
else<br />
{<br />
fprintf(fp,"\nDo thi khong lien thong");<br />
fprintf(fp,"\nCo %d thanh phan lien thong:",nLT);<br />
for(int m=1; m<=label; m++)<br />
{<br />
fprintf(fp,"\nMien %d: ",m);<br />
for(int i=0; i<n; i++)<br />
if(LabelLT[i]==m)<br />
fprintf(fp,"%4d",i);<br />
}<br />
}<br />
fclose(fp);<br />
return 1;<br />
}<br />
<br />
void GRAPH::GraphAlgorithm()<br />
{<br />
label=0;<br />
LabelLT = new int[n];<br />
for(int i=0; i<n; i++)<br />
LabelLT[i]=0;<br />
for(i=0; i<n; i++)<br />
if(LabelLT[i]==0)<br />
{<br />
label++;<br />
Visit(i);<br />
}<br />
}<br />
<br />
void GRAPH::Visit(int i)<br />
{<br />
LabelLT[i]=label;<br />
for(int j=0; j<n; j++)<br />
if(B[i][j]==1||B[j][i]==1)<br />
if(LabelLT[j]==0)<br />
Visit(j);<br />
}<br />
//***********************Graph.h**************************************
class GRAPH<br />
{<br />
private:<br />
int n;<br />
int label;<br />
int *LabelLT;<br />
unsigned char **B;<br />
public:<br />
int ReadData(char *FileName);<br />
const int WriteData(char *FileName);<br />
void GraphAlgorithm();<br />
void Visit(int i);<br />
<br />
};
Help me, make virtual method in my project!
<(-|-)> "To be or not to be"
|
|
|
|
|
I can see only one class in this code. And really dont understand your question.
|
|
|
|
|
what function do you want to be virtual!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
Hi
can u suggest me how to use a form view in tab control.I have done using dialogs in tab control for each tab item
Thanks,
Sireesha
|
|
|
|
|
Why you want to use form view instead of a dialog? What feature do you expected doing so?
nave
|
|
|
|
|
My application is like...
I need to get a vertical scroll bar when the size of the dialog increases.this should not increase the size of tab control
is there any way of doing that
|
|
|
|
|
is your dialog size increasing dynamically?
|
|
|
|
|
yes,the dialog size should be increased dynamically.
|
|
|
|
|
hey i will try getting a better solution in while u just make the vertical scroll property true
|
|
|
|
|
ok..I will suggest your a mehtod to this in dialog itself.
Specify the WS_VSROLL style fo the dislog that you added to tab
Create another dialog as the child of the dialog that you add to tab control.
you should put all the control in the second dialog.
So when use clicks on the scroll button, just move the innner dialog up or down
specify the WS_VSROLL style if you want to scroll dialog horizontally
use Setscrollinfo funtion in the begining to set the scroll bar sizes
nave
|
|
|
|
|
Hello Friends,
I also want to use Form view in a Tab Control.
My problem is we have developed the code using From view. And used menu bar for different screens.
Now we got a requirement form client tht they want Tab Controls instead of Menus..
I tried many things but its not working..
Can u tell me whether we can add form view in a Tab Control or not????
Megha
|
|
|
|