|
I imagine most modern programs use FIFO linked lists for the reason you state -- data overruns. With a circular queue you have one of two choices to make: either overwrite existing data or discard new data until some function removes data from the queue. The programs I wrote discarded the data because overwriting existing data usually renders the contents of the entire queue useless. You need to make your circular queue large enough to handle most situations which largly depends upon how frequently data is removed from the queue. You need four pointers, not just two. Head & tail for incoming data and head & tail for outgoing data. Maintaining these four pointers is actually as much if not more overhead then a simple linked list with just a next pointer.
|
|
|
|
|
The basic circular buffer is as you describe in point 5. Maintain two numbers, Read and Write which correspond to the read and write locations within the buffer. You can then use array notation rather than pointers which makes the arithmetic more intuitive.
Let's use recording audio as an example. The soundcard driver gives you regular buffers of data. Simply copy this into your circular buffer at the write position. To make wrapping arithmetic easy (and also ensuring only one memcpy is needed per iteration), make the size of your circular buffer a multiple of the size of the buffers the soundcard provides. For example, if the soundcard gives you 1024 sample buffers, make the circular buffer 16384 samples long.
Decide what rate you want to read data from the circular buffer e.g. in 8192 blocks. Then when you write to the circular buffer firstly update the write location and then check to see if the difference between read and write is >= 8192 (easy way to do this is to add the size of the circular buffer to each location and then take the difference). If it is, then signal your read thread to read the fresh data (and update your read pointer). This is easier than getting your read thread to continuosly poll thus leaving it more time to finish the formatting. Everytime you change the read or write values, make sure you use modulo arithmetic:
Write+=1024;
Write%=16384;
Read+=8192;
Read%=16384;
Hopefully, you shouldn't have problems with overrun since you're forcing a read when data is available. Experiment with buffer sizes to find the most efficient way. With audio, it's good to have small buffers since you get low latency, in your case it may not be necessary; bigger buffers put less strain on the CPU.
Hope this is useful.
|
|
|
|
|
Thanks, guys for the suggestions. I think I have it done now. I still need to test it with a max load of data. I kept my buffers kind of small because of the application. I wanted to timestamp each 8, 14, or 32 byte message with a unique timestamp in msecs. However, legacy software only supports resolution to 10ths of a second.
Consequently, I used a small receive buffer of 128 bytes and a circular buffer of 1024 bytes. Though, I won't be able to maintain the millisecond accuracy, it should be fine for 10ths of a second.
I wrote it so that the read thread calls SetEvent() in which the process thread waits infinitely for. So, it doesn't poll and only gets used if there is data to process.
I found a pretty good example online of a C++ class that implemented a circular queue and I converted it to C. The thing I like about this one is that the front or head is always one position less then where the data actually begins making it easier to detect when the queue is full. Of course, that means one element in the queue is not used or 1023 of 1024 elements are used.
And as one of you wrote, I decided to discard any data if the processing thread couldn't keep up.
I'm still experimenting around but as its set up now the read thread is at a priority of 15 while the process thread is set to 15 when WaitingForMultipleObjects() but 17 when it gets control. Do you guys have any advice on this or does that sound normal?
Thanks again.
|
|
|
|
|
Hi. I am using the windows XP-style controls (commctl32 version 6). In this, the tab control's "client area" is colored differently from the background, and is not a single color. So, when I put a control on top, such as the label (static) control, or a radio button, the dialog background fills the area of the control, making it look rectangular and ugly. Is there any way to make the text of my controls transparent rather than opaque, so that I can avoid this problem?
Thank you.
- Andy Oxfeld (andy@serialgaming.com)
|
|
|
|
|
I need to create "Help Topics" for each of my WinCE application programs that run on PocketPC 2002 using eVC++ 3.0 compiler. On desktop programs use WinHelp.exe, but that program does not exist on the PPC device. Does anyone know how to do this?
|
|
|
|
|
|
Can someone show me where I can find an example to write a program that will have multi language gui. For example user will select the language that he wants and gui will be in that language
Thank you
Orcun Colak
|
|
|
|
|
I suppose you'd use multiple resource-bearing files,
one for each language, and then use AfxSetResourceHandle
to specify which to use. Then make sure to code your
project with no inlined strings-- everything from the
resources.
Here's some google results:
TN057, Q147149, over at Microsoft
http://www.codeguru.com/misc/MultiLang.shtml
http://www.eanet.cz/~lvanek/develop/windows/international/international.htm
I love search engines.
|
|
|
|
|
I'm having a problem with MessageBox(). I am creating a thread to interact with a device driver and if the driver is not loaded/started, I'm trying to display a message to the user. All that happens is that the message box pops up for a second.
The return is 1 (IDOK) and GetLastError is 0 (I called SetLastError(0) before MessageBox).
I'm calling:
::MessageBox (NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION);
Thanks for the help,
David
|
|
|
|
|
|
Anyone knows how to deal with ghost windows in XP? How to get rid of the ghost windows in windows XP system with Platform SDK? Thanks.
Windows XP: If a top-level window stops responding to messages for more than several seconds, the system considers the window to be hung and replaces it with a ghost window that has the same Z order, location, size, and visual attributes. This allows the user to move it, resize it, or even close the application. However, these are the only actions available because the application is actually hung. When in the debugger mode, the system does not generate a ghost window.
reference from MSDN.
mIchAel Liu
|
|
|
|
|
Until you learn to write a subject line that is
1 - not an attempt at giving me/us an ORDER and
2 - learn to not fill it with completely annoying characters;
I have but one advice for you: Have a nice day, go play on the highway.
|
|
|
|
|
Did you try FindWindow?
Apparently, no one knows the answer since you've posted this at least 3 times already. Look in newsgroups.
Jason Henderson quasi-homepage articles "Like it or not, I'm right!"
|
|
|
|
|
why not fix the hang? I happen to like the ability to close programs that are misbehaving!
|
|
|
|
|
Hi. I am trying to create a configuration dialog for an application I am writing. It is (or at least will be) fairly complex, so I cannot fit all the configuration options in one dialog. So, I made the configuration dialog have a list box on the left side of the window, which lists different "sections" of the application. Depending on which section you have selected in the list box, the options on the right side of the dialog change.
One way I could have done this would have been to put all the controls for all the sections in the same dialog, and use ShowWindow() to show some and hide others depending on what is selected in the list box. I've done this before, and it's a big hassle. So, this time, I thought I would put the controls for each section into their own dialogs. I could then would only have to show and hide the dialogs. The dialogs would be child windows of the main configuration dialog.
To test this idea, I made the configuration dialog, which only has the list box, and "Ok" and "Cancel" buttons. The list box does nothing right now. In response to WM_INITDIALOG, it uses CreateDialog() to make the child dialog (and there's only 1 right now). I made a test child dialog which only consists of a few buttons, which do nothing. However, I am getting a weird issue when you click the buttons... after clicking them, they get thick, like a default button does, and stay that way.
To make it easier to understand what I'm saying, I made a little webpage with pictures demonstrating what happens when you click the buttons:
http://serialgaming.com:8080/nnirc/
I also tried deleting the manifest and using regular Windows95 buttons, and the same problem occurs.
I have spent many, many hours trying to get this working. I've looked throughout the web (including things on this website), but the only programs I could find which did something similar to mine were written in MFC (I'm not using MFC.)
Here's the code I'm using to create the dialogs:
To create the main, modal configuration dialog:
DialogBox(hInst, MAKEINTRESOURCE(IDD_CONFIGURE), hWnd, ConfigureDlgProc);
To create the child, modeless dialog (this is in WM_INITDIALOG of ConfigureDlgProc):
hDlg = CreateDialog((HINSTANCE)hInst, MAKEINTRESOURCE(IDD_TEST), hWnd, TestDlgProc);
ShowWindow(hDlg, SW_SHOW);
Here is the child modeless dialog's window procedure:
BOOL CALLBACK TestDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return true;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
EndDialog(hWnd, IDOK);
break;
case IDCANCEL:
EndDialog(hWnd, IDCANCEL);
break;
}
break;
}
return false;
}
If you have any idea what's wrong, I'd really appreciate it. This has really baffled me more than any other problem I've ever had programming. Or, alternatively, if you have non-MFC source for a program that does something similar, I'd really appreciate it if you can show it to me.
Thank you for the help.
- Andy Oxfeld (andy@serialgaming.com)
|
|
|
|
|
I have been trying to create a reportview list control in MFC using the control toolbox and placing the list control on a dialog form, with the inbsertcolumn type function with the index parameter as zero. But I get two columns! One with my title specified, and one with no title. I only want one column to show up in my report view style list control. I hope its possible.....
|
|
|
|
|
Have you tried to just set the text for the first column? IIRC you always get one column, and if you add another column it would be obvious you see what you see.
Just an idea.
|
|
|
|
|
Heres what I'm using to set the column header:
m_list1.InsertColumn(0,"dir",LVCFMT_LEFT,70);
and to insert:
nItem = m_list1.InsertItem(0,str);
So how to set the column header and yet have only 1 column? If you put index as -1, it doesnt show up at all...
If you dont set the column header with insertcolumn, you cant populate with insertitem....nothing shows up in the box!
Thanks!
|
|
|
|
|
The second one is not a column, it's just the space not used by the first column. To correct, just resize the first column to fill all available space:
m_list1.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER);
Of course, if you resize your list, you'll then need to alter the size of the column also.
--------
Have you hugged your monitor today? --Shog9 --
|
|
|
|
|
Hello,
In my MDI project, I want to make the child CFormView dialog form unmoveable by the user. When I went to the dialog resources properties I saw that the titlebar property was already unchecked. However it still shows up with the blue caption bar and can be moved around inside the MDI frame. Is there some code I should use to accomplish this? I put in the precreate function of the child frame:
//cs.dwExStyle = WS_EX_DLGMODALFRAME ;
but it didnt seem to do anything different from when the line is commented out...the title bar that moves the window around is still there.....
Thanks very much for your help!
|
|
|
|
|
I got it! Thanks. I had to use cs.style = ~WS_CAPTION
Hurray!
Now to get rid of the Child scrollbars....
~WS_VSCROLL isnt doing it....
|
|
|
|
|
(I asked this in the COM forum, thought this one might get a responce sooner, sorry)
Hi, i appologise if this question has been asked be before but its got me stummped, i need to overwrite one of the function pointers in a COM interface, i dont have access to the COM source nor can i modify it, i simply need to overwrite the pointer, i keep getting access violations.??
Goes something like this.
IInterface * MyInterface= MakeInterface();
unsigned * vTbl = ((unsigned**)MyInterface)[0];
vTbl[THE_FUNCTION_INDEX] = NewFunction;
Hope that gives you the idea of what i want, kinda like hooking a COM interface, i have yet to find an easy/any soloution like simply overwriting the functions pointer.
|
|
|
|
|
Hello
I have a simple app, a CMainFrame with some CDialog derived based members, custom classes. One of the dialogs has a CComboBox. I want the main window to be informed when this drop down selection is changed. I have tried adding a handler in the main window, no luck. I have tried PostMessage, SendMessage, and checking for the message in the main window using 'DefWindowProc' and using ON_MESSAGE maps. Nothing. If I add a handler to the dialog class it does detect the selection change, but this is no use to me, as I want the main window to be able to react also.
I am sure that what I am doing is so simple, so useful and so obvious that there is an easy way that I don't know about. Can anyone help?
Cheers,
solosnake
|
|
|
|
|
If you're launching the dialogs as modals in response of some menu action of mainframe you may block the main thread's message queue.
Try launching some worker thread and communicate to the worker, or launch the dialogs as modelesses.
rechi
|
|
|
|
|
No, they are not modals but continously displayed windows.
Cheers,
solosnake
|
|
|
|
|