|
The message is processed in A in both cases.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Are you sure about that? When you SendMessage you call the WndProc directly, bypassing the pump. So SendMessage would be in the context of the worker thread, while PostMessage would be in the context of the main thread (which runs the message pump). This is also the way COM handles a call to a STA component (by posting messages instead of calling the components interfaces directly).
Of course, I may be wrong
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
Are you sure about that?
I'm 100% sure, if you pardon my arrogance. SendMessage only bypasses the message pump if issued from the same thread that attends the message. Otherwise, the message is queued as usual and the caller thread blocks until the target thread processes the message.
As a side note, using SendMessage from worker threads is likely, if no care is taken, to result in deadlocks.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Relaying facts is not arrogance! I should have read the MSDN entry on SendMessage more carefully:
If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the specified window was created by a different thread, the system switches to that thread and calls the appropriate window procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The sending thread is blocked until the receiving thread processes the message.
No doubt here. I stand corrected . But at least I was right on the "I could be wrong"-part
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
Well, as happens so often, 100% sureness is a hard position to maintain
As for the thread context switch, there's still no doubt about it. What I'm not so sure is whether the message sent gets queued or not. My hunch, after re-reading the docs, is that it is not, so it surpasses all other messages currently queued in the target thread. Most of the time this is of little relevance, I guess.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquín M López Muñoz wrote:
I'm not so sure is whether the message sent gets queued or not
It doesn't (checked and 100% sure ).
rechi
|
|
|
|
|
Thanx for the info! How did you do the test (just curious)?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I've created a SDI application with a menu item used to start the worker.
The code:
void CMainFrame::OnFileThread()
{
DWORD *th=new DWORD;
HANDLE h=::CreateThread(NULL, 0, ThreadProc_, m_hWnd,
0, th);
Sleep(3000);
delete th;
}
DWORD WINAPI ThreadProc_(
LPVOID lpParameter
)
{
MSG msg;
TRACE("in thread proc\n");
::PostMessage((HWND)lpParameter, WM_DUMMY3, 0, 0);
::SendMessage((HWND)lpParameter, WM_DUMMY2, 0, 0);
return 0;
}
LRESULT CMainFrame::Func2(WPARAM, LPARAM)
{
MSG msg;
TRACE("in dummy2\n");
while (::GetMessage(&msg, NULL, 0, 0))
if (msg.message==WM_DUMMY3)
{
TRACE("found dummy3\n");
return 0;
}
return 0;
}
And the debug output:
in thread proc
in dummy 2
found dummy 3
Due to your obvious programming skills, it should be enough .
rechi
|
|
|
|
|
Hmmm. The docs suggest that the message goes through the queue ("Messages sent between threads are processed only when the receiving thread executes message retrieval code."), but doesn't specify if it gets in front of the line or has to wait until the messages in front is processed. Where's Jeff Richter or Mike Blaszczak when you need them ? Anyway, it's probably of little consequence.
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
|
In A as the others have said. It is not a good idea to use SendMessage between threads as you are asking for a deadlock to come knocking on your door.
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
Why does it flicker sooo much inside a CMainFrame() ...?
Do I have to set the CMainFrame() to WS_CLIPCHILDREN ..? Should I make sure the CMainFrame() returns false inside OnEraseBkgnd() ...?
How can I get rid of the flicker...?
Thank u muchly
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Does anybody know some easy way to handle and
create jpeg pictures? Some free library,
or something
Regards
Janne
|
|
|
|
|
VS7
google.
How low can you go ? (enculage MS)
|
|
|
|
|
ROTFL !!!!
Christian
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
You mean like CXImage, FreeImage or GDI+ ? All three are documented here on CP.
Christian
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
|
I have the following code:
In CMainFrame::OnCreate() function:
...
m_pCbRooms = (CComboBox*) CComboBox::FromHandle(::GetDlgItem(hBar, ID_ROOMS_COMBO));
...
I also have the following function in the CMainFrame class:
void CMainFrame::UpdateRoomList(const CMeasureData* pMeasureData, int nCurrentRoom)
{
ASSERT_VALID(pMeasureData);
ASSERT(nCurrentRoom >= 0 && nCurrentRoom < pMeasureData->GetRoomCount());
ASSERT(m_pCbRooms != NULL);
m_pCbRooms->SetRedraw(FALSE);
m_pCbRooms->ResetContent();
for (int n = 0; n < pMeasureData->GetRoomCount(); n++)
{
const CRoom* proom = pMeasureData->GetRoom(n);
ASSERT(proom != NULL);
m_pCbRooms->AddString(proom->GetDescription());
}
m_pCbRooms->SetCurSel(nCurrentRoom);
m_pCbRooms->SetRedraw(TRUE);
m_pCbRooms->Invalidate();
m_pCbRooms->UpdateWindow();
}
When I call this function in the constructor of my CDocument class it works fine, but when I call this function in some CLICK-Event function, there is a ASSERTION in "afxwin2.inl" in line 120.
In the CLmsPPCDoc::OnNewRoom() event (ASSERTION):
...
((CMainFrame*) AfxGetMainWnd())->UpdateRoomList(m_pMeasureData, 0);
...
What's wrong?
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
The ASSERT seems to imply that m_pCbRooms does not point to a created window when CMainFrame::UpdateRoomList is called.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
For my MDI application Framework I normally have a Single View . i.e On a File New i get another instance of the View class .
Now I want to achieve the task of displaying two views at once. I.e when the user clicks on File--> New , user should see two view Windows . How should I do this .
All i could think of was to Add to the Document template the different views
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(IDR_VIEWTETYPE,
RUNTIME_CLASS(CViewTestDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CViewTestView));
AddDocTemplate(pDocTemplate);
pDocTemplate = new CMultiDocTemplate(
IDR_VIEWTETYPE,
RUNTIME_CLASS(CViewTestDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(View1));
AddDocTemplate(pDocTemplate);
Now on a File New I need to show both the Views ! How to do this ? Please Help
|
|
|
|
|
I am running the vc program from vbprogram using createprocess.My window
name is form1.When i click the button on the form1,i am starting my vc
program exe.Once when i start the exe,i tried to disable my vb program
taskbar name using
HWND DisWnd=FindWindow("Shell_TrayWnd","Form1");
EnableWindow(DisWnd,FALSE);
But it didnt worked out.
|
|
|
|
|
When the application is started it is restored (not-maximized).
When I open the document, I want to create view of the maximised size.
How can I get the maximized size when the window is restored?
|
|
|
|
|
You must to modifiy the PreCreateWindow... Go to FAQ of Michael Dunn...
Regards
Carlos Antollini.
Pi Five[^]Creator
Sonork ID 100.10529 cantollini
|
|
|
|
|
|
here I want maximized size of the window, but the window is NOT maximized.
|
|
|
|