|
I have an application that connects to a Sound Level Meter. A new feature request is to be able to provide a live streaming audio of what the instrument is recording. The data coming from the instrument is in a raw PCM format and I request a new packet of data every second.
Right now, I am saving the data into a .wav file by creating a RIFF header based on the channels, bits per sample, and sample rate configured on the instrument and calculating an arbitrary size based on 10 minutes of data. I then start writing each packet of data to the file. My plan was to then start a playback after 5 seconds using the default wave player. So far, nothing has worked. Windows Media Player complains that the file is in use (since I am still writing to it) and Nero complains that the header is invalid (most likely since the size data is not actually correct). I have also tried mciSendString() without success.
I have absolutely no experience with streaming audio so I am not sure I am even going down the correct path. If anyone has any thoughts or suggestions, I would be grateful.
Thanks,
-LG
|
|
|
|
|
Was just looking through Charles Pretzold's "Programming Windows, Fifth Edition" the other day and I noticed a section that dealt with wave form audio. All I've done is compile the example code, which dynamically creates a sine wave of desired frequency and outputs it to the sound-card.
I suppose the only real difference would be the way in which the buffer containing the sound bytes is created.
Hope this link helps. sineWAV.zip
|
|
|
|
|
|
I am trying to add a pull down to my MFC application. I want to make sure that I have my terminology correct. By a pull down item, I mean something that sits in the body of the window and enables the user to select one item from a list of items. For example, if you go to the website: http://cgi.money.cnn.com/tools/retirementplanner/retirementplanner.jsp, you will see a pull down menu to select the typical annual raises. That is what I mean by a pull down menu.
Now, my question is, how should I implement that in MFC? Is it done with a CComboBox?
Thanks
Bob
|
|
|
|
|
Yes, that is a CComboBox.
|
|
|
|
|
I am trying to use a CComboBox, however, the code is not working. Below is the code that I am using to create the CComboBox:
accountTypes[accountCount].CreateEx( WS_EX_CLIENTEDGE, TEXT("listbox"), NULL,
WS_CHILD | WS_VISIBLE | LBS_STANDARD ,
200, 200, 100, 25, m_hWnd, (HMENU)(IDC_ACCOUNT_TYPES + accountCount), NULL );
CClientDC dc(this);
accountTypes[accountCount].ResetContent();
for( int i = 0; i < sizeof(accountStrings)/sizeof(accountStrings[0]); i++ ) {
int retValue = accountTypes[accountCount].AddString( accountStrings[i] );
retValue = 0;
}
where IDC_ACCOUNT_TYPES is defined to be 500 and accountCount is an integer variable with values like
0 or 1. When I run the code, I get an area where the user can type, not a pull down. I am thinking that I created the pull down with the wrong type, but I am not sure what the correct type is.
Please tell me what I am doing wrong.
Thanks
Bob
|
|
|
|
|
In the dialog editor, select the properties of the ComboBox and change the Type to Drop List.
I have not used CreateEx to make a ComboBox before so I am not sure that will work, but the style for a drop list is CBS_DROPDOWNLIST. You could try replacing LBS_STANDARD with that and see if it works.
-LG
|
|
|
|
|
LG,
Thanks for the response. All my MFC code is hand written. Therefore, I tried your second suggestion. However, it did not work. Any other ideas?
Bob
|
|
|
|
|
I am guessing that your accountTypes is of type CListBox. Try using CComboBox instead.
Here is an example from Programming Windows with MFC by Jeff Prosise:
CComboBox m_wndComboBox;
m_wndComboBox.Create(WS_CHILD | WS_VISIBLE | WS_BORDER |
WS_VSCROLL | CBS_DROPDOWNLIST | CBS_SORT, rect, this, IDC_COMBOBOX);
This will create a drop-down list combo box that will automatically sort the items added and will display a vertical scroll bar if the items exceed the size of the rect.
Hope this helps.
-LG
|
|
|
|
|
BobInNJ wrote: TEXT("listbox") ... LBS_STANDARD
Your code is for a listbox, not a combobox.
Try TEXT("COMBOBOX") and CBS_DROPDOWNLIST instead.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have been told that the correct term for what I am asking for is not pull down but drop down. Therefore, I am asking how to implement a drop down menu using MFC.
Thanks
Bob
|
|
|
|
|
Can anybody provide me hint as how to get parent process command line in 64 bit.
I used the NtQueryInformationProcess() in conjunction with date structures:
typedef struct _PROCESS_BASIC_INFORMATION {
PVOID Reserved1;
PPEB PebBaseAddress;
PVOID Reserved2[2];
ULONG_PTR UniqueProcessId;
PVOID Reserved3;
} PROCESS_BASIC_INFORMATION
struct _PEB2
{
DWORD dwFiller[4];
DWORD dwInfoBlockAddress;
} PEB2;
struct _INFOBLOCK
{
DWORD dwFiller[16];
WORD wLength;
WORD wMaxLength;
DWORD dwCmdLineAddress;
} Block
to retrieve parent process's command line info. Worked well in 32 bit application, but failed in 64 bit application.
Any helps from you guys are greatly appreciated.
Jack Rong
|
|
|
|
|
I am working with a virtual list control for the first time. Everything is working great... almost.
One remaining problem I have is that I would like to have the first item in the list selected by default when the list is initially displayed.
With a normal list, I would set the item as 'selected' in OnInitDialog() after loading the list into the control, but now since it's virtual, I guess there's nothing in the list control to select yet at this point.
After OnInitDialog(), I can see it going in and out of OnGetDispInfo(), so I guess that's where it's actually getting the items that it needs to load into the list.
Obviously I need to wait until after that first set of items has been loaded into the list control before I can set the first item as selected.
But where in the code can I sneak that in?
I just don't know enough about where things are happening to know where I can do this. Nothing I've tried has worked.
Thanks in advance for any ideas.
|
|
|
|
|
How and from where are you adding items to the list control?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I'm getting my list of items (CStrings) from doing a database SELECT, then as I loop through each of the results, for a normal list control I would have inserted each item directly into the list control in OnInitDialog(), now for virtual I'm just putting those items into a list at that point, and then pointing the virtual list control to my list, calling .SetItemCount() to set the size for the list control, making the control LVS_OWNERDATA style, etc., following the tutorial in the link below:
http://www.codeproject.com/KB/list/virtuallist.aspx[^]
My OnGetDispInfo() function is pretty simple and looks like this:
void MyDlg::OnGetDispInfo(NMHDR* pNMHDR, LRESULT* pResult)
{
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
LV_ITEM* pItem= &(pDispInfo)->item;
int itemid = pItem->iItem;
if (pItem->mask & LVIF_TEXT) //valid text buffer?
{
CString text = MyList_.at(itemid);
lstrcpyn(pItem->pszText, text, pItem->cchTextMax);
} // if
*pResult = 0;
}
I don't know if this is typical, but I also had problems in general with programmatically selecting an item in the virtual list control. SetItemState() didn't seem to work at all. (I should mention that I am forced to use Visual C++ 5.0, so I don't know if this could be an old problem that no longer exists). But I did see someone else had this same problem, and suggested a fake mouse click on the item. (See section 'Selection Problems' in the article below)
http://www.ddj.com/184404349;jsessionid=BVQZXGZXOGLUSQSNDLOSKH0CJUNN2JVN?_requestid=130370[^]
So I followed exactly what this guy did, and in general it seems to work great, (even though it doesn't feel like the best solution).
The only issue is with that initial selection when the list first displays. Maybe if SetItemState() worked properly, it wouldn't be an issue. Maybe it's because I'm having to simulate that mouse-click, and there's not really anything there to click on yet.
I'm not really sure.
|
|
|
|
|
AmVal wrote: then pointing the virtual list control to my list, calling .SetItemCount() to set the size for the list control
Cool thanks!
You should be using SetItemCountEx() instead of SetItemCount() on a virtual list
(ListView_SetItemCountEx() is the Win32 equivalent).
Right after that call would be the place to select an item I would think.
You shouldn't have to simulate a mouse click...
Are you sure the selection isn't sticking just because the control doesn't have focus?
Where are you calling SetItemCount() from?
What does your SetItemState() code look like?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
From OnInitDialog(), I am calling my BuildList() function to get the data from the database and load into my list. As soon as I finish loading the list, I call SetItemCount(). (I don't know if this ancient version I'm using has SetItemCountEx(). I tried using it, but I got a compile error that 'SetItemCountEx' is not a memeber of CListCtrl).
My SetItemState() to set the ith element to selected looks like this:
MyList_.SetItemState( i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
I tried calling it right after calling SetItemCount(), but it doesn't work, even if I give the list control focus.
Speaking of focus, maybe this could be part of the problem. The way my dialog is designed, I have an edit control sitting on top of the list control where the user can start typing in the edit control, and I then highlight/select the nearest match in the list control. So unless they actually click on an item in the list, the focus is in the edit control where they are typing, and I'm trying to select item in the list control. It does work using the simulated mouse click, but another very minor thing is that it looks like with CListCtrl, the highlight is blue if the control has focus, and gray if it doesn't have focus. It would be nice if I could keep the highlight blue all the time, the way CListBox works. So I know even if I can get it to highlight the first item by default, it will only have the gray highlight, not the blue that I would prefer. (That's probabaly not easy to change, huh?)
I originally was just using a CListBox and everything worked great, was simple, had no problem at all. Except the list is so large (~100,000 items) that it was a little slow to load, so I decided to try my hand at a virtual list, which also meant having to change to a CListCtrl, and seems to have introduced a number of minor issues that I've been struggling with.
Does this give you any more idea how I should be handling this? Thank you very much for your help.
|
|
|
|
|
This should be the proper sequence after SetItemCount():
GotoDlgCtrl(&MyList_);
MyList_.SetItemState(0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
GotoDlgCtrl(&MyEdit_); // optional - if you want initial focus on the edit control
Then return FALSE from OnInitDialog() (important!).
(make sure you comment out any fake mouse click stuff )
That works for me - I just tested it.
Without setting the focus to the list before setting the selection, it
indeed fails to select the item as you've seen - I confirmed that as well.
AmVal wrote: I don't know if this ancient version I'm using has SetItemCountEx()
That's why I gave you the Win32 equivalent
You can get the Win32 equivalent of anything missing from your ancient MFC
version here: List View Control[^]
AmVal wrote: It would be nice if I could keep the highlight blue all the time
You'd have to use custom draw for that.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hmmm... Everything you say makes sense, but for some reason this is not working for me with the virtual list control (it does work for non-virtual).
This is pretty much what I had been trying, and I had also previously tried calling SetItemState() with one, or the other, or both LVIS_SELECTED and LVIS_FOCUSED, and even with only LVIS_SELECTED it didn't / doesn't work for me.
I'll keep looking to see if I can find something else wrong somewhere...
But I thought functionality was supposed to work the same for CListCtrl whether virtual or not, which makes it seem like it could be a bug in the version I'm using...
|
|
|
|
|
Hmm I'm stumped
I personally would use a message posted at the end of the OnInitDialog
to the dialog itself, then in response to that message do the item select.
I really don't like simulated clicks and /or keystrokes
If I think of something I'll let you know....good luck
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I would prefer not to use the simulated mouse click, that was a last resort. But it appears I may have to, as without it, right now I can't select anything in the list when the user types in the edit control. The mouse click takes care of everything except the initial display. There's gotta be a way to do the same thing on initial display, I just can't figure out where to do it.
If it's not too much trouble, could you give me an example of the code you are suggesting so I can try it?
I'm pretty new to Windows/MFC programming (this is the first time I've even used CListCtrl, much less sent messages, etc. Each step of the way has been a real struggle, looking for examples I can follow, etc. (although I'm learning a TON which is cool!) Even though I don't really like the idea of the simulated mouse click, I was actually kind of impressed that I got it to work
So anyway, a sample of the code you are suggesting would just save me some time trying to figure out how to do it! Thanks a bunch.
|
|
|
|
|
AmVal wrote: right now I can't select anything in the list when the user types in the edit control.
Wow - I thought it was just the original selection...
There's something wrong somewhere....you should be able to change
item states anywhere.
What version of Visual Studio are you using?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
It's Visual Studio 97. (Yikes! I know...)
The one article I referenced from 2000 was by a guy who sounded like a pretty experienced programmer, and he also discovered that programmatically selecting items in a virtual list control didn't seem to work. He never found any solution other than the fake mouse click. It sounded like he did get it to work for the initial selection as well. Unfortunately his code isn't out there any more so I can't see where he did that! (I don't know what version he was using, but his article was from 2000)
If I make the list box non-virtual, I can programmatically select items fine at any time. But as soon as I make it virtual, I can't programmatically select at all.
|
|
|
|
|
AmVal wrote: It's Visual Studio 97. (Yikes! I know...)
I'm worried MFC had its own version of the control then.
I just can't remember
These days (since Windows 98), the control is provided by
the operating system. You may want to not use MFC for the
control and use Win32 APIs directly. The problem seems to be
in MFC, not in the control.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
You're right, if I just use:
ListView_SetItemState(MyList_, i, LVIS_SELECTED, LVIS_SELECTED)
It works to select the first item on initial display, as well to select at any other time. So I can avoid the fake mouse clicks! Yeah!
Thanks so much Mark!
|
|
|
|
|