|
Try a couple of things:
1 - use the following message:
::SendMessage(
m_hwndText, //Handle to edit control.
EM_SETBKGNDCOLOR,
0,
clrBackground) ; //e.g., ULONG clrBackground = RGB(255, 0, 0) ;
2 - Also, I seem to remember some time ago having to first put some text into a rich edit before I could change the background. You first have to select the text using CHARRANGE, then use CHARFOMAT2 to format the text. I have a vague recollection of putting a single space character into the rich edit to get it to work, but you may not have to.
Scott
|
|
|
|
|
I have created Thread Using AfxBeginThread, to diaply continous text on dialog bar, while if I close entire application or interrupt the application i gets Memory leakage, please help.
|
|
|
|
|
Maybe posting your code will make our lives easier...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
How do you cancel the thread?
This doesn't seem to be a suitable solution for updating text.
Consider using a timer, CWnd::SetTimer(), to update the text.
--
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
|
|
|
|
|
^^ yep if possible use a timer...
otherwise by using a thread:
load:
ThreadRef = AfxBeginThread(Thread, ¶ms, THREAD_PRIORITY_BELOW_NORMAL, 0, CREATE_SUSPENDED);
disable auto delete:
ThreadRef->m_bAutoDelete = false;
start Thread:
ThreadRef->ResumeThread();
then use a global variable to signalize the thread to exit (in Thread func)
if(params->pDlg->m_WantExit){<br />
return 1;<br />
}
and use a own method in the main function to clean up the threads, calld before ending, and also wait till they end.
do{<br />
Sleep(1);
GetExitCodeThread(ThreadRef->m_hThread,&ExitCode);<br />
}while(ExitCode == STILL_ACTIVE);
this makes sure that the thread gets canceled correct on end of the main function.
|
|
|
|
|
I suggested a timer in the same thread since you will eventually get a deadlock situation if you update GUI objects from other threads. The timer solution is also more straight forward.
Besides, your thread handling suggestion contains a lot of errors and bad solutions that should not be recommended someone.
1. You left out the information what 'params' really is. Usually you pass the 'this' pointer and call a static member function that converts the void pointer.
2. You set CWinThread::m_bAutoDelete to FALSE without deleting the object returned by AfxBeginThread which will create a memory leak.
3. You're calling GetExitCodeThread in a loop where you think your thread will terminate by a call to ::Sleep(), even if you set the priority of the thread below normal. It will terminate eventually, but your main thread has higher priority.
The comment that a call to ::Sleep() will execute your secondary thread is very wrong: there's no guarantee that your thread will be executed. Even the argument to ::Sleep() reveals a lot. The correct way to do it is to wait on the thread handle, CWinThread::m_hThread, with a call to e.g. ::WaitForSingleObject().
For more information about how to do multithreading, read here[^].
--
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
|
|
|
|
|
Well I left several part out, thats true.
- I thought its well known whats able to fill 'params' with
- the Threadobject would be deleted after the loop jumps out, what happens when the thread has ended (I didnt write it, ok).
- that the Sleep() is no 100% secure statement for a threadchange ist true
- to secure the application for deadlocks, there are several locking mechanism possible so secure shared variables.
- WaitForSingleObject has the problem that it locks up the application that calls it if used tirect in a window creating code, thats why i used a loop.
Well Im not a code guru, dont think Im one and also theres every time someone that knows more than me
|
|
|
|
|
My first post I suggested an alternative design solution for the OP, since I'm under the impression that he had selected the wrong solution for the problem.
You don't paint the walls with a hammer.
In my second post I was really trying to help you to avoid troubles in your way of doing multithreaded applications.
spielehelfer wrote: - I thought its well known whats able to fill 'params' with
- the Threadobject would be deleted after the loop jumps out, what happens when the thread has ended (I didnt write it, ok).
Ok, so noted.
A word of caution though: don't assume that the person you're trying to help is aware of things you consider 'common knowledge'. In my opinion it's hard enough to help someone while guessing their level of expertise.
spielehelfer wrote: - that the Sleep() is no 100% secure statement for a threadchange ist true
True, in fact it might be quite the opposite: it's almost 100% wrong to use ::Sleep() in this situation. ::Sleep(0) would make a little more sense but it would still not be quite right.
Read the timing section [^] of Joe Newcomer's article and you will know why afterwards.
spielehelfer wrote: - to secure the application for deadlocks, there are several locking mechanism possible so secure shared variables
A "deadlock" and "corrupt data due to multiple threads accessing the same data" are two very different problems, but both are related to multithreading.
Protecting shared data is often called "thread synchronization".
You cannot prevent deadlocks by the use of thread synchronization; you may, however, cause a deadlock by improper use of thread synchronization.
spielehelfer wrote: - WaitForSingleObject has the problem that it locks up the application that calls it if used tirect in a window creating code, thats why i used a loop
If it's the blocking part you worry about I can tell you that your loop solution is worse. (Calling ::Sleep()!) :->
It really doesn't matter: you should use ::WaitForSingleObject(), or ::WaitForMultipleObjects(), for multiple reasons (the ones below at the top of my head):
1. you can set a timeout
2. the waiting function consumes a very small amount of CPU cycles
3. the calling thread's priority gets boosted temporarily when any of the handles waiting for reaches its signalled state
4. you really don't want to process messages during this time to prevent other problems with re-entrancy
If you want to read more about why it's wrong to use ::GetThreadExitCode(), have a look here[^].
spielehelfer wrote: Well Im not a code guru, dont think Im one and also theres every time someone that knows more than me
Quite allright!
However, I strongly advise you to read Joe Newcomer's articles about how to use worker threads here[^] and the other ones I suggested above from his MVP tips page, http://www.flounder.com/mvp_tips.htm[^].
Cheers
--
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
|
|
|
|
|
what is the use/function of manifest file in WTL
|
|
|
|
|
|
Hiii,all
I need MFC Internals by scot wingo if anyone having ebook copy of this ,please send it to me on abhi_bhopale@rediffmail.com
Thanks ...
-- modified at 5:05 Monday 27th November, 2006
There Is Nothing Right & Wrong
|
|
|
|
|
abhijit bhopale wrote: I need MFC Internals by scot wingo if anyone having ebook copy of this ,please send it to me on
This book can be acquired through purchasing it at http://www.Amazon.com[^]
I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:
|
|
|
|
|
abhijit bhopale wrote: please send it to me on abhi_bhopale@rediffmail.com
no
|
|
|
|
|
abhijit bhopale wrote: I need MFC Internals by scot wingo..
Have you tried scot_wingo@msn.com?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi all,
i have creted my project with visual studio 6.0
and after that for certain needs i started using visual studio 7(Version 7.1.3088)
till now it was working very smoothly. but today i tried to add a propertysheet in my project and for that i created a dialog template and then by right cliking on that dialog box i clicked on add class.
and in the add class dialog box i gave CPropertyPage as base class as it is required for the property sheet.
and by this way i created the class but now when i compile the project
it gives lot's of errors
Why these errors are coming?
i am doing nothing than just creating a class and giving it base class as
CPropertyPage and then it gives me 1625 errors
some of the errors are as follows
e:\TemporyWorking\Triton\hdr\DocTree.h(20) : error C2504: 'CSizingControlBarG' : base class undefined
e:\TemporyWorking\Triton\hdr\DocTree.h(46) : error C2146: syntax error : missing ';' before identifier 'm_imageList'
e:\TemporyWorking\Triton\hdr\DocTree.h(46) : error C2501: 'CDocTree::CImageList' : missing storage-class or type specifiers
Thanks and Regards
Harshal
|
|
|
|
|
harsha_1234 wrote: e:\TemporyWorking\Triton\hdr\DocTree.h(20) : error C2504: 'CSizingControlBarG' : base class undefined
The specified base class, CSizingControlBarG , was declared but never defined. This error can be caused by a missing include file or an external base class that was not declared with the extern specifier.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Dear friends,
I would like to know how to change the properties of o/p exe file when right click like:
File version, company name etc.
Any help will be greatly appreciated!!
Thanks
Suman
I got it!, we have to goto the Resource tab, click the plus of Version folder,
double click the Version node and edit the properties.
Thanks for help!
|
|
|
|
|
Use the resource editor to edit the version.
|
|
|
|
|
I would like to use embedded code to obtain the current memory usage of my program. I would like to use ToolHelp32-API, instead of going the way of using psapi.h.
please provide detailed steps or instructions.
Thanks.
|
|
|
|
|
Hello,
how can i show a line separator between dialog objects, like in visual basic?
I like to put some radio boxes on the left side of my dialog, vertical, and i want to make a litle
difference between, not to use "GroupBox", just a simple line like menu separator:
° radio1
° radio2
° radio3
----------------- // <-- my line separator
° radio4
° radio5
° radio_n
is this posible?
thanks in advance
break;
|
|
|
|
|
override the OnPaint() function and add this code :
CRect l_rctClient;<br />
GetClientRect(&l_rctClient);<br />
<br />
CDC * l_pDC = GetDC();<br />
<br />
CPen l_GrayPen(PS_SOLID, 1, RGB(100, 100, 100));<br />
CPen l_WhitePen(PS_SOLID, 1, RGB(255, 255, 255));<br />
<br />
int l_nYLine = l_rctClient.top + l_rctClient.Height()/2;
<br />
CPen * l_pOldPen = l_pDC->SelectObject(&l_GrayPen);<br />
l_pDC->MoveTo(l_rctClient.left+2, l_nYLine);<br />
l_pDC->LineTo(l_rctClient.right-2, l_nYLine);<br />
<br />
l_pDC->SelectObject(&l_WhitePen);<br />
l_pDC->MoveTo(l_rctClient.left+2, l_nYLine+1);<br />
l_pDC->LineTo(l_rctClient.right-2, l_nYLine+1);<br />
<br />
l_pDC->SelectObject(l_pOldPen);<br />
<br />
ReleaseDC(l_pDC);
|
|
|
|
|
Hello,
thaks for answer, yes tis is what i mean, only i recive an error in line:
CRect l_rctItem;
GetDlgItem(IDC_RADIO)->GetClientRect(l_rctItem);
i think that the IDC_RADIO dont exists at this time,
Error is "Access violation 0x00000005". And the compiler show this:
<code>
_AFXWIN_INLINE void CWnd::GetWindowRect(LPRECT lpRect) const
{ ASSERT(::IsWindow(m_hWnd)); ::GetWindowRect(m_hWnd, lpRect); }
</code>
How to solve this
The rest od your sample works fine, the new line goes through the middle of my dialog
regards
break;
-- modified at 9:16 Monday 27th November, 2006
|
|
|
|
|
So you can do that :
CWnd * l_pRadioWnd = GetDlgItem(IDC_RADIO);<br />
if( !l_pRadioWnd )<br />
return;<br />
<br />
CRect l_rctItem;<br />
l_pRadioWnd ->GetClientRect(l_rctItem);<br />
<br />
int l_nYLine = l_rctItem.bottom+10;<br />
<br />
CDC * l_pDC = GetDC();<br />
<br />
CPen l_GrayPen(PS_SOLID, 1, RGB(100, 100, 100));<br />
CPen l_WhitePen(PS_SOLID, 1, RGB(255, 255, 255));<br />
<br />
CPen * l_pOldPen = l_pDC->SelectObject(&l_GrayPen);<br />
l_pDC->MoveTo(l_rctClient.left+2, l_nYLine);<br />
l_pDC->LineTo(l_rctClient.right-2, l_nYLine);<br />
<br />
l_pDC->SelectObject(&l_WhitePen);<br />
l_pDC->MoveTo(l_rctClient.left+2, l_nYLine+1);<br />
l_pDC->LineTo(l_rctClient.right-2, l_nYLine+1);<br />
<br />
l_pDC->SelectObject(l_pOldPen);<br />
<br />
ReleaseDC(l_pDC);
|
|
|
|
|
Hello,
i solve my problem, thank you! I override the wrong OnPaint() function, because i have more childdialogs!!!
regards
break;
|
|
|
|
|
Just insert a static control that is 1 DLU tall, and has the SS_SUNKEN style.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|