|
1) There's no sense in calling PeekMessage or other message-oriented functions in Run. This thread is a 'worker' one, doesn't have message queue. Remember that message queues are created and accessed per-thread. PeekMessage inside Run is guaranted to return FALSE.
2) The main problem with application being not responsive to mouse movements etc. can be related to the frequency of calls to Invalidate/UpdateWindow being made inside Run. If updating philosopher state doesn't take much time, you're sending lots of WM_PAINT messages to hwndCtl. UpdateWindow removes these messages and repaints the control, however, message queue is stressed by 5 threads. Note that calling InvalidateWindow in worker thread posts message in the message queue of main (UI) thread.
You should invalidate the control periodically, not in every pass of the loop. Use GetTickCount to compute time elapsed from last repaint and redraw every second (for example, you may choose different interval). This will reduce flicker and should make your app responsive to user actions.
If possible, do e-mail the solution to my mail box
CodeProject server sends email to you automatically, unless you explicitly de-select this option when posting.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hi just wanna ask how do you manipulate the "Z-order" in visual C++??? How do you put one picture box on top or at the back of another picture box...
Thanks......
|
|
|
|
|
SetWindowPos is generally how you set the Z-order of a window. Given that controls are also a CWnd, I'd try that first.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
hi..
m_s1 and m_s2 are CSTATIC but seems like it's not working...
void CTesting3_bmpView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CFormView::OnLButtonDown(nFlags, point);
if (flip == TRUE)
{
flip = FALSE;
m_s1.SetWindowPos (&wndTop, 1, 1, 100, 100, SWP_NOSIZE | SWP_NOMOVE);
//m_s1.BringWindowToTop ();
}
else
{
m_s2.SetWindowPos (&wndTop, 1, 1, 100, 100, SWP_NOSIZE | SWP_NOMOVE);
//m_s1.BringWindowToTop ();
flip = TRUE;
}
UpdateData(FALSE);
Invalidate();
}
|
|
|
|
|
are you trying to show between two button at the same position to do two different task ?
if so, i sugguest you not to use z-order but just change the object text of the button ( or CStatic ) by CWnd::SetWindowText(LPCTSTR lpszString) and if they are executable, set a flag ( i think you already have, which is "flip".. ) and in OnClick of that object, check the flag and do different task.. but as you said they are just static.. i guess you only wanna display different text SetWindowText can do what you need
|
|
|
|
|
I have an ATL COM DLL for a project I'm working on. It has a progress bar so some of our other COM objects can load and use it for showing progress...
At any rate, the Dialog is based on CAxDialogImpl. This dialog HAS a Cancel button so I don't want to override OnCancel. I tried overriding WM_KEYDOWN which works fine for any OTHER key pressed but for some reason doesn't capture the Escape key.
Anyone have any other ideas? Please help.
Matt Philmon
|
|
|
|
|
GetAsynchKeyState(VK_ESKAPE);
(in your OnCancel(...) to check the state)
|
|
|
|
|
THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU!
Matt Philmon
|
|
|
|
|
I have a CFormView which pops up a dialog box which has a property page. While in the property page, I want to get a value from the CFormView, but I can't, it always returns a wierd number like -814001 or somethign not even close to what I expect.
Can I please, please, email a small demo project to someone/anyone who could look at it and help me to get a value? Please please. My email address is brinasas@yahoo.com
This will probably take 1 line of code, but I am absolutely stumped and frustrated.
Sincerely,
Danielle (an overworked graduate student)
|
|
|
|
|
How are you accessing the CFormView class? Are you passing a pointer into the property page?
Michael
|
|
|
|
|
I am working on an ATL control that has a simple CStatic text label. While I've managed to change the font in both OnInitDialog and OnPaint I cannot change the color. Basically it is a Property Sheet with a CStatic control on it.
In the Constructor m_pArial is defined as:
m_pArial->CreateFont(40, 0, 0, 0, 700, 0, 0, 0, 0, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, FIXED_PITCH, "Arial");
And it is deleted in the destructor.
Here is my code (it sets the font just fine - not the color).
void CPropPage::OnPaint()
{
CPaintDC dc(this); // device context for painting
CPen *pOldPen;
CPen BluePen;
BluePen.CreatePen(PS_SOLID, 1, RGB(0, 0, 255));
CBrush Brush(RGB(0, 0, 255));
CBrush *pOldBrush;
pOldPen = dc.SelectObject(&BluePen);
pOldBrush = dc.SelectObject(&Brush);
m_Static_Title.SetFont(m_pArial);
m_Static_Title.SetWindowText("Test");
dc.SelectObject(pOldPen);
dc.SelectObject(pOldBrush);
}
Thank You
|
|
|
|
|
You need to do it in the WM_CTLCOLORSTATIC message handler
From MSDN on WM_CTLCOLORSTATIC:
"A static control, or an edit control that is read-only or disabled, sends the WM_CTLCOLORSTATIC message to its parent window when the control is about to be drawn. By responding to this message, the parent window can use the specified device context handle to set the text and background colors of the static control."
Cheers,
-Erik
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
My thoughts are my own and reflect on no other.
|
|
|
|
|
Does anybody know how to read and write individual bits of data to a file? I would appreciate any advice that you may have.
Thanks.
|
|
|
|
|
You have a lotof options,
You can use _read() function,
CArhive::Read() function Or CFile::Read() function.
Cheers!!!!
Carlos Antollini.
|
|
|
|
|
You can write ints, BOOLs, doubles, etc.. like that, but not individual bits. Thanks though.
|
|
|
|
|
The minimum unit that can be written is a BYTE. Even the data type BOOL takes up a byte of space. So I think you can use 1 byte for each bit. But, if you want to write bits itself, you have to use the bitwise operators to fit it in the appropriate position in a byte and then write it to the file. A similar process should be done when reading.
- Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
Thank you for your reply, that is what I figured I would have to do, although I really didn't want to.
|
|
|
|
|
Hello,
Does anyone know how to give a dialog box the ability to all ways be on top? eg.. even if some other app not related to yours is open (like your internet browser), I want my dialog app to stay on top..
Rob
|
|
|
|
|
This answer MUST be in the FAQ, but ::SetWindowPos (&wndTopMost, 0,0,0,0,SWP_NOMOVE | SWP_NOSIZE);
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
Thanks Christian.. In the future, I'll do a little more searching before I post.
Thanks again for the fast response.
Rob
|
|
|
|
|
Hi,
I have a MFC test app with 2 edit fields. I want to pass the edit fields handle to an MFC ActiveX control which will just return the contents of these fields.
The problem I am facing is that ActiveX control does not allow to take in HWND as a parameter.
Is there a way to pass HWND in my activeX control.
Thanks in advance
Bobby
|
|
|
|
|
I'm not exactly sure what you're trying to do, but you can add an IUnknown derived interface and create a method that lets you pass the handles. You can also cheat and cast them to a LONG if you're using a dispinterface.
But for most stuff this doesn't seem like a good idea. What exactly are you trying to accomplish?
--CoolDev
|
|
|
|
|
Well basically my MFC activex control contains hook functions. So from my MFC test app if I pass a handle of the edit field, then my ActiveX control should process the information based on Hooks.
When I try to add a method to my ActiveX control, it doesnt allow me to add HWND as one of the argument. There is something called OLE_HANDLE instead but I dunno if that will solve the purpose.
Any help will be greatly appreciated.
Thanks
Bobby
|
|
|
|
|
It sounds like you're using a wizard, and the interface you're trying to add the method to derives from IDispatch. A handle is not an OLE Automation type. As I said before, you can create a new interface that's derives from IUnknown, or cheat and make your function take a LONG and then cast it as appropriate.
I do question the design, though. I don't see why an ActiveX control would ever want to hook a WndProc of a control in its container...
--CoolDev
|
|
|
|
|
Thanks again ..
I know it sounds wierd that an ActiveX control hooking to a WndProc of a container but it is kinda needed since when the control is downloaded then it will help me to analyze some data.
I tried the function that takes OLE_HANDLE and casting it appropriately but didnt work. I will give it a shot with LONG.
The other solution u mentioned is through ATL COM(in which I dont have my hands dirty)..is it possible through just MFC.
Thanks a mucho..
Bobby
|
|
|
|