|
Thanks for the reply cedric Moonen
i store the the colors which are in this form #CC0000, #EA0000, #5E5EFF
the problem is that i can't just compare if they are the same because most of the times they use simmilar colors for the bg and fonts but not identical for example white bg and very light yellow for the fonts still unreadable but it won't match if i compare the colors
|
|
|
|
|
There are many way of doing this. One way is to consider the colour as a point in 3D space: The difference between two colours using this scheme is the length of the line between them which we can calculate using Pythagoras’ theorem (extended to 3D).
double Difference(BYTE red1, BYTE green1, BYTE blue1, BYTE red2, BYTE green2, BYTE blue2)
{
BYTE rdiff = red2-red1;
BYTE gdiff = green2-green1;
BYTE bdiff = blue2-blue1;
return sqrt(rdiff*rdiff + gdiff*gdiff + bdiff*bdiff);
}
The return value will always be positive and you'll have to decide how small a return value means the colours are too close.
Steve
|
|
|
|
|
This is way to advance for me but i like it looks good i'll try it
Thank very much appresiate the help
i'll post a msg if i need some assistant
thanks again u ve been very helpful
|
|
|
|
|
Hi,
I don't think this works with bytes suppose the color black (0,0,0) and white (255, 255, 255)
look add the difference of a component say red:
BYTE rdiff = 0 - 255;
but when the two colors are almost the same gray (128,128,128) & (127,127,127)
BYTE rdiff = 128 - 127;
One must use signed short to let this work.
The multiplication wil create positive numbers
double Difference(short red1, short green1, short blue1, short red2, short green2, short blue2)
{
short rdiff = red2-red1;
short gdiff = green2-green1;
short bdiff = blue2-blue1;
return sqrt(rdiff*rdiff + gdiff*gdiff + bdiff*bdiff);
}
A good site for this kind of problems is http://www.webwhirlers.com/colors/combining.asp[^]
codito ergo sum
|
|
|
|
|
Thanks badkarma for the help i think i got it
1.first i need to transform hex to decimal?(do you know how btw )
2.First 2hex digits corespond to red second 2digits to green and 2 last to blue
3. i perform the arithmetic operations of your function and i set a number (by trial and error to find the compinations of colors that i should consider similar)
looks good thanks again!
if you know any fuction to convert hex to decimal that would be very helpful
Thanks again
|
|
|
|
|
Yes, you right: You'll need to use a signed type as you've done.
Steve
|
|
|
|
|
antonaras_marcou wrote: What i'm trying to do is check if the font color and the background color are similar
Similar but not exact?
antonaras_marcou wrote: i found something similar but for c#.net is
So are you wanting a C++ slution or a C# slution?
antonaras_marcou wrote: if (cbg.R <= cfg.R + 15 ||cbg.R >= cfg.R - 15)
{
if (cbg.R <= cfg.R + 15 ||cbg.R >= cfg.R - 15)
{
if (cbg.R <= cfg.R + 15 ||cbg.R >= cfg.R - 15)
These three tests appear to do the same thing? Is that intentional?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"We will be known forever by the tracks we leave." - Native American Proverb
|
|
|
|
|
Hi all,
i've developed a dialog based application, which has to respond for certain events (ex:when the sound filled in a buffer has stopped playing.. etc).
To achieve this i've used the function,
MsgWaitForMultipleObjects( 1, &g_hNotificationEvent,FALSE, INFINITE, QS_ALLEVENTS );
where,
g_hNotificationEvent --> handle to the event to be triggered.
the problem what i'm facing is,where to place this function? if i put this within OnInitDialog the application stops executing further.The problem will be solved if this function is placed within
WinMain() ,but where i do i find WinMain in a dialog based MFC application?
It'll be really great if someone can help me out in this.
Thanks and regards,
rajeev
|
|
|
|
|
Start a separate thread to check for that, otherwise your GUI will freeze until you receive the event.
Once the event is received in your thread, send a user defined message to your dialog to specify that the event is finished.
|
|
|
|
|
Umm.. The whole thing about having an event signaled is the use of multiple threads.
Since you seem to have only one thread I don't understand why you consider this solution.
Why don't you post a user defined message from where you are signalling the event and write a message handler for that message instead?
--
Roger
It's suppose to be hard, otherwise anybody could do it!
|
|
|
|
|
Let me explain the application more clearly. i've a demodulator hardware which keeps pumping out some sound data which is being feed to a sound card.
I've used "DirectX" to achieve this. when the sound fed to the card has finished playing ,the application has to be notified so that it can fill the buffer with new data and play it again.This process has to repeat continuously.
Please let me know whether using MsgWaitForMultipleObjects(...)is a good idea ?
rajeev
-- modified at 6:54 Thursday 27th April, 2006
|
|
|
|
|
rajeev82 wrote: MsgWaitForMultipleObjects(...)is a good idea ?
It depends on how you know when your demodulator has finished feeding the sound card...
If it signals an event, then I suggest you create a worker thread simply waits for the event with WaitFormUltipleObjects(), presumably there's no need to process messages.
If a message gets posted you write a message handler and restart the feeding process from there.
To be able to help you futher we need to know how you can tell when the demodulator has finished feeding the sound card.
--
Roger
It's suppose to be hard, otherwise anybody could do it!
|
|
|
|
|
The demodulator doesnt feed the data to the sound card directly.Itz my program which collects the data from the demodulator and feeds it to the sound card so that it can be heard.the sound which comes out from the demodulator is in chunks of 4096 points.
In directx there is a interface called IDirectSoundNotify which will notify my application when one chunk of 4096 has been played ,so that the next 4096 points can be loaded ,played and so on.
as long my application runs the demodulator will work and it'll pump out something(atleast noise).so please tell me how to call a function according to the notification i receive.
rajeev
|
|
|
|
|
Well, given that I've understood your problem correctly I suggest the following:
1. Set up interface sinks and create objects necessary.
2. Create a worker thread that gathers the data from the demodulator and put the data in a queue which is read from...
3. a second worker thread that feeds the sound card and waits for an event which gets signalled when your app is notified using WFMO().
4. Marshal needed interfaces to your threads before you unleash them. (Create them suspended.)
This will keep the GUI responsive since the main thread is not blocked.
You should also get the notification in the main thread.
Read JoeNewcomer's article[^] about multithreading if you are unfamiliar with the subject.
Hope this helps
--
Roger
It's suppose to be hard, otherwise anybody could do it!
|
|
|
|
|
(VS 2005 MFC) I have a list of 5 threads, for example:
struct T_PARAMS
{
HWND hWnd; // a handle to dialog window, using in thread
};
int thread_count = 5; // I have 5 threads
CWinThread *pThread; // pointer to thread
CList<cwinthread*, cwinthread*=""> mList; // list of the pointers to threads
int lp = 0;
// First I create 5 stopped threads:
for(lp = 0; lp < thread_count; lp++)
{
params = new T_PARAMS();
params->hWnd = m_hWnd;
pThread = AfxBeginThread(ThreadFunc, params, THREAD_PRIORITY_NORMAL, 0,
CREATE_SUSPENDED);
pThread->m_bAutoDelete = true;
mList.AddTail(pThread);
}
Now, when I have a list of pointers to threads, I want run threads, but I want to do it in this way: run first thread (mList[0]), wait so long how the first thread is working, next run second thread (mList[1]) and so on. For example:
POSITION pos;
CWinThread *wsk = NULL;
pos = mList.GetHeadPosition();
for(lp = 0; lp < thread_count; lp++)
{
wsk = (CWinThread *) mList.GetNext(pos);
wsk->ResumeThread();
// [*] now wait until thread is working - how to do it?
}
My threads are working properly, I use one semaphor to allow works only 1 thread at once, but I don't know how can I do - in line [*], that programm will wait after wsk->ResumeThread() until this thread is finished his work?
Regards
mwgomez
Poland
|
|
|
|
|
Have a look at Joe Newcomer's article about worker threads. It's excellent!
He'll show you how to all of this the correct way here[^].
I urge you to read the complete article since it will make you aware of problems you have to know how to deal with when doing multithreading.
Hope this helps
--
Roger
It's suppose to be hard, otherwise anybody could do it!
|
|
|
|
|
First when you create the thread but before you let it run make sure you do the following (you will have to create it suspended):
pThread->m_bAutoDelete = FALSE;
There is no point in having a collection of CWinThread pointers if you have no way of knowing if the object pointed to has been delete or not!
Now you can wait for a thread to exit using the Win32 API as follows:
WaitForSingleObject(pThread->m_hThread, INFINITE);
Remember we've turned auto deletion off so you have to remember to delete the CWinThread objects when you're done with them - deleting one doesn't stop the thread running (if it's running).
Steve
|
|
|
|
|
how to write a logfile in the COM component
suresh
|
|
|
|
|
Use an ofstream object for that:
ofstream OutputFile("MyFile.txt");
int SomeVariable = 10;
OutputFile<<"SomeText"<<SomeVariable<<endl;
|
|
|
|
|
ok thanq
but,i want create .txt file at the server side.........
suresh
|
|
|
|
|
Which server ?? Please when asking a question be more specific. What are you trying to do exaclty ? Provide as much relevant information as possible.
|
|
|
|
|
Then give a file name to a file at the server! Example:
\\Server02\Share$\aDirectory\aTextFile.txt
|
|
|
|
|
Is there a way to do this in Windows without .neT?
Thanks!
|
|
|
|
|
BOOL CreateDirectory(
LPCTSTR lpPathName, // pointer to directory path string
LPSECURITY_ATTRIBUTES lpSecurityAttributes // pointer to security descriptor
);
BOOL RemoveDirectory(
LPCTSTR lpPathName // pointer to directory to remove
);
|
|
|
|
|