|
As Cpallini said, you should have added to your previous message instead of posting a new message. anyway, you didnt answer my earlier query i.e. whether by any chance OnNotify is called twice?
I dont know why i feel i had this stupid problem of a piece of code executing twice inside some windows message handler.
and the problem in my case was that windows was sending the message to my control as well as to its parent also and parent was forwarding the message to its child. So, in effect, child was receiving the same message twice.
You are suggested to put breakpoints at *all possible places* and check if your message handler is being called twice.
Happy programming.
|
|
|
|
|
If you consider that the SysIPAddress32 control is comprised of four Edit controls, those edit controls are sending EN_CHANGE and EN_UPDATE notifications. That may not be an exact answer to your question, but it should give you enough to plow through Spy++ to see exactly what is going on.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Good morning,
I have trouble creating a wave file from the data stream I got from the microphone input.
The recording seems to go quite well but know I´m stuck at the task of converting that data into a wave file.
I recorded the mic data into a WAVEHDR structure like this ...
const int NUMPTS = 44100 * 10;
int sampleRate = 44100;
short int waveIn[NUMPTS];
HWAVEIN hWaveIn;
WAVEHDR WaveInHdr;
MMRESULT result;
int main( int argc, char *argv[] )
{
WAVEFORMATEX pFormat;
pFormat.wFormatTag=WAVE_FORMAT_PCM;
pFormat.nChannels=1;
pFormat.nSamplesPerSec=sampleRate;
pFormat.nAvgBytesPerSec=sampleRate*2;
pFormat.nBlockAlign=2;
pFormat.wBitsPerSample=16;
pFormat.cbSize=0;
result = waveInOpen(&hWaveIn, WAVE_MAPPER,&pFormat, 0L, 0L, WAVE_FORMAT_DIRECT);
if (result)
{
char fault[256];
waveInGetErrorText(result, fault, 256);
return 1;
}
WaveInHdr.lpData = (LPSTR)waveIn;
WaveInHdr.dwBufferLength = NUMPTS*2;
WaveInHdr.dwBytesRecorded=0;
WaveInHdr.dwUser = 0L;
WaveInHdr.dwFlags = 0L;
WaveInHdr.dwLoops = 0L;
waveInPrepareHeader(hWaveIn, &WaveInHdr, sizeof(WAVEHDR));
result = waveInAddBuffer(hWaveIn, &WaveInHdr, sizeof(WAVEHDR));
if (result)
{
return 1;
}
result = waveInStart(hWaveIn);
if (result)
{
return 1;
}
do
{
}
while (waveInUnprepareHeader(hWaveIn, &WaveInHdr, sizeof(WAVEHDR))==WAVERR_STILLPLAYING);
waveInClose(hWaveIn);
save();
std::cin.get();
return 0;
}
... and now I am trying to store the data to a wave file like this:
bool save()
{
int subchunk2size = WaveInHdr.dwBufferLength*1*2;
fstream myFile ("test.wav", ios::out | ios::binary);
myFile.seekp (0, ios::beg);
myFile.write ("RIFF", 4);
myFile.write ((char*) 36+subchunk2size, 4);
myFile.write ("WAVE", 4);
myFile.write ("fmt ", 4);
myFile.write ((char*) 16, 4);
myFile.write ((char*) 1, 2);
myFile.write ((char*) 1, 2);
myFile.write ((char*) 44100, 4);
myFile.write ((char*) 88200, 4);
myFile.write ((char*) 2, 2);
myFile.write ((char*) 16, 2);
myFile.write ("data", 4);
myFile.write ((char*) subchunk2size, 4);
myFile.write (WaveInHdr.lpData, WaveInHdr.dwBufferLength);
return true;
}
But somewhere I got a bad memory access or such something since I get a read error (in memcpy.asm).
Can anybody help me here?
Souldrift
|
|
|
|
|
Well, nevermind. I just fixed it .
Modified the save function like this:
bool save()
{
int bitsPerSample = 16;
int subchunk1size = 16;
int numChannels = 1;
int subchunk2size = WaveInHdr.dwBufferLength*numChannels;
int chunksize = 36+subchunk2size;
int audioFormat = 1;
int byteRate = sampleRate*numChannels*bitsPerSample/8;
int blockAlign = numChannels*bitsPerSample/8;
fstream myFile ("test.wav", ios::out | ios::binary);
myFile.seekp (0, ios::beg);
myFile.write ("RIFF", 4);
myFile.write ((char*) &chunksize, 4);
myFile.write ("WAVE", 4);
myFile.write ("fmt ", 4);
myFile.write ((char*) &subchunk1size, 4);
myFile.write ((char*) &audioFormat, 2);
myFile.write ((char*) &numChannels, 2);
myFile.write ((char*) &sampleRate, 4);
myFile.write ((char*) &byteRate, 4);
myFile.write ((char*) &blockAlign, 2);
myFile.write ((char*) &bitsPerSample, 2);
myFile.write ("data", 4);
myFile.write ((char*) &subchunk2size, 4);
myFile.write (WaveInHdr.lpData, WaveInHdr.dwBufferLength);
return true;
}
Cheers
Souldrift
|
|
|
|
|
Hi,
How to split a string
something like making "hello world" into an array of "hello" and "world"...
Thanks in advance.
|
|
|
|
|
Are you using MFC CString?
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
See CStringArray.
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
I included the header file, #include <string>;, for CString.
But CString is nowhere found. Do I need to include any other headerfiles to access CString?
|
|
|
|
|
Actually you don't need CString , you may also use strtok [^] for the purpose.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
string first = strtok(str,"C");
str is the string type which I would like to split by character 'C'.
Got the following compiler error,
'strtok' : cannot convert parameter 1 from 'std::string' to 'char *'
Can we convert the string to char * type.
|
|
|
|
|
You don't need strtok for dealing with std::string . Use std::string.find instead. For instance
#include <string>
#include <iostream>
void main()
{
const int SIZE = 10;
std::string s[SIZE];
std::string str = "Hello folks, welcome!";
int i;
int start_pos, end_pos = 0;
for (i = start_pos=0; i <SIZE && (end_pos = str.find(' ', start_pos)) != std::string::npos; i++)
{
s[i] = str.substr(start_pos, end_pos-start_pos+1);
start_pos=end_pos+1;
}
if ( start_pos < str.length() && i < SIZE)
{
s[i] = str.substr(start_pos, str.length()- start_pos+1);
i++;
}
for (int j=0; j<i; j++)
{
std::cout << "s[" << j << "]=" << s[j] << std::endl;
}
}
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
NarVish wrote: Can we convert the string to char * type.
Try:
const char* cstr = str.c_str();
string first = strtok(cstr, "C");
Or just the simple
string first = strtok(str.c_str(), "C");
[EDIT]Or, just use CP's solution[/EDIT]
|
|
|
|
|
Whit CString s, for instance, your best bet is the Tokenize method [^], some extra work is required, however.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
this drives me nuts...
I have the following function that checks against an IP address control for displaying an error message box if users specify an invalid IP value that greater than 255
ON_NOTIFY(IPN_FIELDCHANGED, IDC_EDIT_LISTEN_ADDRESS, &CNetworkBindingDlg:SurprisenEditListenAddressChanged)
void CNetworkBindingDlg:SurprisenEditListenAddressChanged(NMHDR* pNMHDR,LRESULT* pResult)
{
LPNMIPADDRESS pIPAddr = reinterpret_cast<LPNMIPADDRESS>(pNMHDR);
if(pIPAddr->iValue > 255)
{
CStringW ErrMsg;
ErrMsg.Format(ResourceString(IDS_INVALID_IP_ADDRESS),pIPAddr->iValue);
MessageBox(ErrMsg,ResourceString(AFX_IDS_APP_TITLE), MB_ICONERROR);
}
}
Somehow the MessageBox() function execute twice. I chased the code and noticed that the MessageBox() is executed the first time, but the message does not show up, but the execution control comes back to the CStringW ErrMsg line, the MessageBox() will be executed the second time. And then the message box dialog shows up twice.
Any suggestion?
thanks.
|
|
|
|
|
yes, one suggestion. what's this ResourceString function. Check if there's some event happening that is sending ON_NOTIFY twice. THere can be more than one reason why OnNotify is called..
|
|
|
|
|
Hello,
I have xl5en32.h type library for automation . The header file contains classes like
appliction
workbooks
workbook
charts
chart
I have gone through the example of drawing charts in VC++ using automation . In each example they have the following code
_Application app;
_Workbook newBook;
Workbooks books;
Worksheets sheets;
_Worksheet newSheet;
Charts charts;
_Chart newChart;
COleVariant vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
//Create Excel server (start Excel)
if(!app.CreateDispatch("Excel.Application"))
{
AfxMessageBox("Can’t start Excel server!");
return;
}
app.put_Visible(true); //set Excel visible
app.put_UserControl(TRUE); //user can operate Excel
books = app.get_Workbooks();
newBook=books.Open("C:\\mynew.xls",vOpt, vOpt, vOpt, vOpt, vOpt,
vOpt, vOpt, vOpt, vOpt, vOpt,vOpt, vOpt,vOpt,vOpt);
newBook = books.Add(vOpt);
sheets = newBook.get_Sheets();
newSheet = sheets.get_Item(COleVariant((short)1));
charts = newBook.get_Charts();
------------------------------------------------
but the above classes are are missing in xl5en32.h type library
and all the functions return COleVariant
How shd i go about writing code for charts ?
Prithaa
|
|
|
|
|
I am trying to replace
if(watever)
somecode;
with
if(watever)
{
somecode;
}
(if\([^`]*\))([ \n])([^`]*[;])
This regex finds out all such if blocks but when I try to replace \3 with {\3}, I get nothing; meaning \1, \2, \3 are just empty. \0 has value and it is equal to the complete string found.
I expect
\1 = (if\([^`]*\))
\2 = ([ \n])
\3 = ([^`]*[;])
It may be obvious by now that this is the first time I am using regex. Please suggest.
|
|
|
|
|
Visual studio Tag expression is {} and not (). If I use {} instead of (), I get correct values in %1, %2.
Any idea how can I properly indent the inserted brackets. THey are inserted at start of line whereas 'if' can be indented?
|
|
|
|
|
Hi All
Can i save change excel *.xls to *.xlsx?
|
|
|
|
|
Please help me some one..
|
|
|
|
|
yes.. you can change the extension by using as Save As option
|
|
|
|
|
thanks for reply .I know that change the extension by using as Save As option.But how it is possible through code.
|
|
|
|
|
Hi,
I have a interface to interact with MS-Access database file. I m using CODBCRecordset for accessing DB.
CODBCRecordset class[^]
It was working fine untill I added new field in one of the table.
I added new field ("Lock1" - a integer field) in table (called "Quotation_DB").
This table have bunch of data (int,double,strings). I have a button in my interface which will set this "Lock1" field to 0/1 in separate function. when i click this button i get following error.
//==================
Expression too complex
Expression too complex
//==================
yes it is printing same message twice.
any kind of help will be good to me. Please let me know if i have to provide more information.
This is what i m doing in my function.
BOOL LockUnlockQuotation(BOOL flg_lock)
{
CODBCRecordset m_RS_RFQ(&DataBase);
BOOL flg_update = false;
if( !m_RS_RFQ.Open("SELECT * FROM \"Quotation_DB\"") )
{
TRACE("Failed to run query: \"%s\"\n","SELECT * FROM \"Quotation_DB\"");
return false;
}
else
{
if(!m_RS_RFQ.IsEOF())
{
m_RS_RFQ.MoveFirst();
}
CString Quot_revID_db="";
while(!m_RS_RFQ.IsEOF())
{
Quot_revID_db=m_RS_RFQ.GetString("QuotID");
if(Quot_revID.Compare("MyQoute2009")==0)
{
m_RS_RFQ.Edit();
m_RS_RFQ.Field("Lock")=1;
m_RS_RFQ.Update();
flg_update =true;
break;
}
m_RS_RFQ.MoveNext();
}
m_RS_RFQ.Close();
}
return flg_update;
}
modified on Wednesday, September 23, 2009 3:08 PM
|
|
|
|
|
is there any fix for this?
modified on Wednesday, September 23, 2009 2:59 PM
|
|
|
|
|
Hi,
I have a interface to interact with MS-Access database file. I m using CODBCRecordset for accessing DB.
CODBCRecordset class[^]
It was working fine untill I added new field in one of the table.
I added new field ("Lock1" - a integer field) in table (called "Quotation_DB").
This table have bunch of data (int,double,strings). I have a button in my interface which will set this "Lock1" field to 0/1 in separate function. when i click this button i get following error.
//==================
Expression too complex
Expression too complex
//==================
yes its print same message twice.
any kind of help will be good to me. Please let me know if i have to provide more information.
This is what i m doing in my function.
BOOL LockUnlockQuotation(BOOL flg_lock)
{
CODBCRecordset m_RS_RFQ(&DataBase);
BOOL flg_update = false;
if( !m_RS_RFQ.Open("SELECT * FROM \"Quotation_DB\"") )
{
TRACE("Failed to run query: \"%s\"\n","SELECT * FROM \"Quotation_DB\"");
return false;
}
else
{
if(!m_RS_RFQ.IsEOF())
{
m_RS_RFQ.MoveFirst();
}
CString Quot_revID_db="";
while(!m_RS_RFQ.IsEOF())
{
Quot_revID_db=m_RS_RFQ.GetString("QuotID");
if(Quot_revID.Compare("MyQoute2009")==0)
{
m_RS_RFQ.Edit();
m_RS_RFQ.Field("Lock")=1;
m_RS_RFQ.Update();
flg_update =true;
break;
}
m_RS_RFQ.MoveNext();
}
m_RS_RFQ.Close();
}
return flg_update;
}
|
|
|
|
|