|
waldermort wrote: ...most of the text's I have read say not to update the GUI from a thread.
True. This is why secondary threads should not use SendMessage() when communicating with the primary thread. It could very easily create a blocking situation. Using PostMessage() allows the secondary thread to continue to work regardless of what the primary thread is doing (e.g., responding to user input).
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: True.
So if you are not supposed to use SendMessage, and PostMessage doesn't work, how would you deal with this situation?
Maybe I should also note that these message are only used to inform the main thread of the current progress, text is sent to a status bar aswel as progress bar messages which is also located on the status bar.
When the thread is complete a use Postmessage to send a confirmation to the main thread. The thread then ends itself with a call to _endthreadex().
|
|
|
|
|
waldermort wrote: ...and PostMessage doesn't work...
Why?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
waldermort wrote: Well, after a long time, way too long, I have managed to implement multi threading into my project. Whoever said Multithreading was easy to learn should be taken out and have TCP poured into his eyes.
Creating a thread is easy... balancing it, synchronizing it, reading/writing from it, and many other processing is far more difficult. So no, multithreading is not "easy" from a grand standpoint of overall functionality and control.
I do believe it is important though. You have good suggestions as far as this specific problem, you will find others that need synchronized control (only one thread reading/writing), and that is where Mutex and critical sections come in. There are many tutorials on multithreaded synchronization from java to C++ and C# so there is a lot to choose from out there.
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
As the other replies have said, SendMessage is a quick fix, but that negates most of the benefit of the worker thread, since it will block until the main thread processes the message.
Another issue to look at is how often you're updating your progress UI. I personally don't do it more than once every 500ms, because that's fast enough to satisfy a person that stuff is happening. If your updates are happening like every 10 ms or so, there are going to be so many context switches that it will quickly drag down performance.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
Hi to all,
I have to create Crop feature using MFC. If we are selecting a rectangle area in a bitmap i have to wipe whole bitmap excluding the selected rectangle area. this is available in Photoshop I think so. Selected area only should appear and other place should be colored with white. Can anybody help me how to take out the selected rectangle area.
Please help me. its urgent.
Thanks
|
|
|
|
|
Just have a look in Charles Petzold. This will clear lots of doubts regarding manipulation of images
Vision is Always important and so is your ATTITUDE.
Wishes.
Anshuman Dandekar
|
|
|
|
|
I am currently trying to select a CBitmap into a device context. And it does work when I create the first CBitmap but not when I try and use the function again. It only then gives a Microsoft error. Can anyone help with this cause I am going insane here! ANd can anyone give me pointers on Device Contexts- any golden rules cause I find them really confusing. ANy help would be greatly appreciated!
I tried:
hdc = (HDC)*pm_dcMem; //pm_dcMem points to CDC
HDC* p_hdc;
p_hdc =&hdc;
// Create a memory device context compatible with the device.
hDCMem = CreateCompatibleDC (hdc);
// Retrieve the width and height of window display elements.
int iWidth = GetSystemMetrics (SM_CXSCREEN) / 10;
int iHeight = GetSystemMetrics (SM_CYSCREEN) / 10;
// Create a bitmap compatible with the device associated with the
// device context.
*p_hb = CreateCompatibleBitmap (hdc, iWidth, iHeight);
*p_hb = (HBITMAP)*p_cbmME; //*_cbmME points to CBitmap that was created
*pm_hBmpOld = (HBITMAP)SelectObject(*p_hdc, *p_hb);
I know there must be mistakes in here but just can't figure it out. The onl reason why I am trying to pass in a HBITMAP is because I am using LoadImage in another function and everything works fine there. I also tried to simply use
pm_dcMem->SelectObject(*p_cbmME);
which again works first time around but then it just doesn't and the microsoft error talks abot some memry not being able to be read. Can anyone help here cause I am at the end of my wits, cause everyone seems to be able to use this function except for me
-- modified at 10:53 Monday 27th March, 2006
|
|
|
|
|
maybe it is some helpful to you
CPaintDC dc(this);
HDC hdc=CreateCompatibleDC(GetDC()->m_hDC);
int iWidth = GetSystemMetrics (SM_CXSCREEN) / 10;
int iHeight = GetSystemMetrics (SM_CYSCREEN) / 10;
HBITMAP hBit=CreateCompatibleBitmap(GetDC()->m_hDC,iWidth,iHeight );
SelectObject(hdc,hBit);
...
...
BitBlt(dc.m_hDC,0,0,iWidth,iHeight ,hdc,0,0,SRCCOPY);
|
|
|
|
|
if you want to show picture in the Dialog you can use
CImage m_Image;
m_Image.Load("c:\\picture.bmp");
OnPaint()
{
CPaintDC dc(this); // device context for painting
m_Image.BitBlt(dc.m_hDC,CRect(0,0,800,600),CPoint(0,0));
}
....else...........
HBITMAP hBit;
HDC hdc;
hdc=CreateCompatibleDC(GetDC()->m_hDC);
int iWidth = GetSystemMetrics (SM_CXSCREEN) / 10;
int iHeight = GetSystemMetrics (SM_CYSCREEN) / 10;
//hBit=CreateCompatibleBitmap(GetDC()->m_hDC,iWidth,iHeight );
HBITMAP hBit = (HBITMAP)::LoadImage(NULL,"c:\\picture.bmp",IMAGE_BITMAP,0,0,
LR_LOADFROMFILE|LR_CREATEDIBSECTION);
SelectObject(hdc,hBit);
OnPaint()
{
CPaintDC dc(this); // device context for painting
BitBlt(dc.m_hDC,0,0,800,600,hdc,0,0,SRCCOPY);
}
maybe it is some helpful to you
|
|
|
|
|
Thank you for your reply so far. I just wanted to take the chance to explain my problem a bit further. I am trying to write a bitmap in memory. I just have an array of RGB values and am creating the CBitmap using CBitmap::CreateBitmap(width, height, 1, 32, imagedata). And it does work when I first select a file and read in the imagedata. However then when I select a new file (testing what happens if a user changes his mind for eample) and it then does not work. Why would the function SelectObject not change the current bitmap and just completely break down?
|
|
|
|
|
I update my vs2003 project to 2005, and then build it, got an error lnk2001 error LNK2001: unresolved external symbol "struct std::_DebugHeapTag_t const std::_DebugHeapTag" (?_DebugHeapTag@std@@3U_DebugHeapTag_t@1@B) globalchecker.lib
but I did not know why this happened. globalchecker.lib is successfully export by another project just with some warnings, and the globalchecker may use boost_1_33_1, I can not find any solution on google, any one knows?
Thanks!
Dilly
|
|
|
|
|
In the project properties, did you specify to link with that library ?
|
|
|
|
|
Oh, yes, I linked it.
Linker->command line contains "..\bind\common.lib" "..\bind\globalchecker.lib"
Dilly
|
|
|
|
|
Let me guess... You're project uses a static lib that was compiled in VS2003.
|
|
|
|
|
The globalchecker.lib was built by 2005 too.
I have try several method in msdn with LNK2001, but not worked.
Dilly
|
|
|
|
|
I installed both 2003 and 2005 in my computer.
I guess some envriment variable has been set ambiguously.
Dilly
|
|
|
|
|
I think you are right, I find another .lib file built by 2003 which the project need to use.
Thanks a lot.
Dilly
|
|
|
|
|
Hi,
I have taken dialog based application.When i run the application the dialog is displayed in default color.I want to change the Background color of the dialog to RED color .
thanks in before
jamesrocky
|
|
|
|
|
Handle WM_ERASEBKGND .
BOOL CDlg::OnEraseBkgnd(CDC* pDC)
{
CBrush backBrush(RGB(255, 0, 0));
CBrush* pOldBrush = pDC->SelectObject(&backBrush);
CRect rect;
pDC->GetClipBox(&rect);
pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(),
PATCOPY);
pDC->SelectObject(pOldBrush);
return TRUE;
}
Nibu thomas
Software Developer
|
|
|
|
|
Sorry its not working, can be more clear..
thanks in before
Jamesrocky
|
|
|
|
|
Add a message map entry
BEGIN_MESSAGE_MAP(...,...)
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()
//just add the rest of the code here...
Nibu thomas
Software Developer
|
|
|
|
|
I think you can use WM_CTLCOLOR and declare a variable CBrush
|
|
|
|
|
You can call the SetDialogBkColor() . You can have a look at this.[^]
Thanks,
Vini
|
|
|
|
|
Hi
USe this in WM_CTLCOLOR
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
hbr = CreateSolidBrush(RGB(134,179,174));
pDC->SetBkColor(RGB(255,0,255)); // Pass the RGB of RED color
return hbr;
Cheers
"Peace of mind through Technology"
|
|
|
|