|
Exactly... they don't come free you know
Joel Holdsworth
|
|
|
|
|
Hi,
I'm having problems painting with alpha in GDI. If I go:
backdc.FillSolidRect(&clientrect, 0xFF012345); What I end up with on the final bitmap surface is:
00 01 23 45 Does anyone know a way to overcome this?
Joel Holdsworth
|
|
|
|
|
The nearest function I can see to what you want would be the function AlphaBlend, though it looks
pretty fiddly to use.
Iain.
|
|
|
|
|
Yeah I've ended up using GDI+ now. It seems to the job nicly! I initially just wanted to avoid too many dependancies.
Joel Holdsworth
|
|
|
|
|
Hello,
How do I do about making an app replicate itself whenever a particular event occurs?
The application I have in hand is a multi-threaded one, which, at some point in time, has to create a new instance of itself dynamically and automatically, thereby replicating itself, with no user input whatsoever.
Can someone shed some light on the correct way to do this?
Thanks a lot.
|
|
|
|
|
That depends on what you mean by 'an app replicate itself'.
If you mean having a second process running the same code, in the same state, then you need to use CreateProcess() to start a second instance of your application, and pass sufficient information to the second instance for it to initialize itself to the same condition as the original. This will include information that lets you start an equivalent set of threads. This information could be passed in a file on the command line, or through some inter-process communication mechanism.
If you're looking for an API function like 'CreateDuplicateProcess() ', I'm afraid you're out of luck.
Software Zen: delete this;
|
|
|
|
|
Thanks for the tip, Gary. Will take a look at CreateProcess and see if it allows me to accomplish what I need to.
David
|
|
|
|
|
I want to share some data between a thread that has Realtime priority (24) with another thread that has Normal priority (8). The Realtime thread is sending events to a midiOut device, the Normal thread is telling the Realtime thread what volume to use for the events. I might be able to get away without using any sort of exclusion mechanism, but I want to play safe. I’m concerned that a timer interrupt might occur in the middle of a data write, causing the read to be corrupted.
The obvious thing to do is to use a CRITICAL_SECTION, and to get both threads to do EnterCriticalSection()/LeaveCriticalSection() around the code that accesses the shared data. But I’m worried that doing EnterCriticalSection() in a Realtime thread will totally lock up Windows.
So a few questions:
1) If the Normal thread calls EnterCriticalSection(), does that prevent timer interrupts from happening until it calls LeaveCriticalSection()?
2) If the Realtime thread runs when the Normal thread owns the critical section object, so that the call to EnterCriticalSection() in the Realtime thread cannot complete until the Normal thread has released ownership of the critical section object, will this cause any problems? I’m worried that the Normal thread won’t be able to run because it’s been interrupted, and the Realtime thread won’t be able to run because it’s waiting for the critical section object.
3) Will all 32-bit versions of Windows behave in the same way with regard to this possible problem?
Thanks in advance.
Chris.
|
|
|
|
|
Hi Chris,
1) I don't think that I really do understand what you mean with timer interrupts, but the call to EnterCriticalSection() on the "normal" thread will cause the "realtime" thread to block on the EnterCriticalSection() call and this will give the processing cycles back to your "normal" thread, which will be happily executing until it calls LeaveCriticalSection(). Ie it is like having a high priority thread calling Sleep, so regardless of the priority of the thread, the processing time will be granted to other threads.
2) There is no need to worry about the "normal" thread, it will most probably still get the same amount of processing time (maybe even more than) that it used to get before. (Beware that I'm not saying that this processing time is enough for your normal thread to be 'responsive enough') The thing about the "realtime" thread is, you're correct it will block until the "normal" thread calls LeaveCriticalSection() so your realtime operation will probably stall. Instead of doing this you can call TryEnterCriticalSection on the realtime thread, and if it returns zero, you can skip trying to read that information and retry on the next loop.
3) As you probably already know, using real time priority in a thread is strongly discouraged and I'm not sure that all versions of Windows provides the same flexibility on multithreading (especially Win9x series) and you should expect lock-ups due to the realtime priority of your thread.
Besides that, if you're concerned about corruption in single read-write's of 32bit values, I'd like to remind you that in Win32 all 32 bit operations are guaranteed to be atomic, so there is no need for synchronization if you're just reading from or writing to an integer from multiple threads. There will be no problem if in one thread you are just reading an integer and in the other thread just updating it.
|
|
|
|
|
This is a fairly serious design issue. Windows is not a real time operating system, so you can't rely on it to do the right thing with regard to scheduling of threads in this way. The scenario you are describing with the thread being kicked off the CPU and struggling to get back on is 'priority inversion'.
Understanding the windows threading model is difficult, and it takes time. One of the simplest ways to think of it is that the main thread (what I believe is your 'normal' thread) does nothing but handle the message pump (event queue). Messages in the main thread are dealt with in two ways, synchronously (PostMessage) or asynchronously (SendMessage). PostMessage forces events to be dealt with immediately, SendMessage buffers the messages in a queue to be dealt with in FIFO order.
The main thread can only do one thing at a time, however it can be interrupted by another thread. If the main thread enters a critical section it prevents another thread from entering that region at the same time, until the main thread leaves the critical section. AFAIK another event having occured (a WM_TIMER message) is irrelevant because the timer message is buffered in the message pump.
Like the last poster recommended, I suggest that you don't bother changing thread priorities unless you can show that this provides a significant benefit at the end of the day - 'premature optimisation is the root of all evil'. It may be that with a single thread at priority 24 the main thread won't get any CPU or enough CPU to run the GUI.
2) rely upon the operating system doing something reasonable at a low level - like giving non-blocked threads a chance on the CPU in preference to blocked threads. This sounds like you are worried about 'deadlocks' but they generally occur only in situations where multiple resources are in contention.
Chris Hills wrote:
3) Will all 32-bit versions of Windows behave in the same way with regard to this possible problem?
Yes, although apparently their are kernels now available which sit on top of Windows that minimise this problem, but they are fairly expensive, and probably not redistributable. If you do need an operating system which can avoid this problem look at something like MaRTE[^]
Also, ensure that the frequency of WM_TIMER messages on the main thread occurs at the rate that you expect it too, especially with the priority of the main thread so high. From past experience WM_TIMER messages can only be set to arrive at a minimum of 10ms intervals, and even then I've seen that regularly blow out to 200ms. It may be more appropriate to poll the clock from the main thread and interpolate volumes between key-points.
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
I think you got this backwards:
"PostMessage forces events to be dealt with immediately, SendMessage buffers the messages in a queue to be dealt with in FIFO order."
I am pretty sure SendMessage dispatches message into the receiver's message queue immediately and PostMessage will add it to the queue.
|
|
|
|
|
Blake Miller wrote:
I think you got this backwards:
Whoops. Of course you're correct
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts your aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
I have a problem getting CEditView::SerializeRaw() to work whenever I try to use the usual "tricks" to get the WinXP look-n-feel to work (xxx.exe.manifest, or the xxx.rc tricks). It only sends 1 character to the file.
Also, when trying to use the "Find" menu item in a project (and using the above-mentioned "tricks"), I get the dialog to appear but it doesn't interact with my program.
I tried the sample "NPP" example (that comes with MSDN) and it gives the same problems, except I get nothing but [] (square chars. (nulls?)) when I load a text file.
If I remove the "WinXP tricks", then everything works properly as expected, but of course no WinXP look'n'feel.
Anyone have a clue what I need to do to get the WinXP look'n'feel to work properly on the WinXP platform? I am using the Platform SDK 2003 and VC++6 with SP6.
Thanks in advance
|
|
|
|
|
ok so i did some testing and you can randomly select items by holding control or you can select a group by using shift how does one get the random select functionality by just clicking?
thanks
Tyrus
|
|
|
|
|
You have to handle the LVN_ITEMCHANGING and LVN_ITEMCHANGED notifications from the list control.
The default behavior of an unmodified click (no shift or ctrl keys) in the list control is to deselect all selected items, and then select the item clicked on.
You will need to handle the notifications such that you prevent the deselection of items you want to remain selected, and to allow the selection of items you want.
Software Zen: delete this;
|
|
|
|
|
Dear ALL ,
How to issue the mouse_event without "SendInput" and "mouse_event"?
and Cloud you expend "SendInput" how to issue the mouse event to os?
Is it need to use interrupt or someone ?
Thanks in advance.
Aaron
|
|
|
|
|
Hi,
I'm trying to create a project using multiple document templates on a windows CE target. Starting my application the menu line is missing. Why ?
|
|
|
|
|
Hello,
I need to calculate the response time of a http request using a VC++ program.Is there any function MFC classes(CHttpRequest or CInternetSession) that provides response time or should I calculate it manually.
Please help me.
regards and thanks,
John.
Overcome fear,everything is possible.
|
|
|
|
|
I don't think that it provides such a feature. Calculate it manually, that should make things easier.
Don't try it, just do it!
|
|
|
|
|
hello i have a list control and i want it to be multi select but currently the only way to multi select is to hold down shift how does one make it function more like a list box
thanks
Tyrus
|
|
|
|
|
http://www.codeproject.com/combobox/listbox_tut.asp?df=100&forumid=1373&exp=0&select=655474
|
|
|
|
|
im not looking for list boxs im looking for list controls
thanks tho
|
|
|
|
|
In function OnItemchangedListCtrl put:
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
m_cListCtrl.SetItemState(pNMListView->iItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
|
|
|
|
|
You'll need to subclass the list control and reflect the L-click message so you can handle (see the list control classes at CP for examples). In the L-click handler, add the item to the list of selected ones by doing:
SetItemState (nItem,
LVIS_SELECTED | LVIS_FOCUSED,
LVIS_SELECTED | LVIS_FOCUSED); /ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Hi guys,
Just encountered a small problem with ADO when trying to read data from two tables in a database that have the same variable names. In my example I have table_1 with a variable called "id" and a table_2 which also has a variable called "id". The id's in each table are not related. I then want to execute a mysql query something like this:
select table_1.id, table_1.country, table_2.id, table_2.country \
from table_1,table_2 where table_1.country=table_2.country
In this case I am matching table_1 to table_2 by country. So far so good. The problem comes when I want read back the values using this method:
var_1 = (long *) (_bstr_t)pRecordSet->GetCollect("id");
In this line above, how does ADO know which id value I am referring too?? I tried this:
var_1 = (long *) (_bstr_t)pRecordSet->GetCollect("tablel_1.id");
var_2 = (long *) (_bstr_t)pRecordSet->GetCollect("tablel_2.id");
.. but it didn't like "tablel_1.id" How can I distinguish between the two if tables contain the same variable names? In this case "country" is the same in both tables, so that one doesn't matter, but id dcoes. I can't find any example anywhere in books or the web. All the examples seem to have tables with completely different variables names and hence do not have this problem.
Help anyone?, I would be very grateful.
Graham.
|
|
|
|