|
No probs. And yes, it's brilliant wow if he's only 10 and sticks with it he should be amazing by the time he's about 15. I find playing guitar very therapeutic, unlike other instruments I've played in the past, and it's a good way of relaxing and thinking and brainstorming about programming so definitely a good combo
Regards,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
|
Hi i am new to the conecetps of vc++.
In my application i am using a combobox(dropdown box) where user can either select the value from tha available list or he can write a value in to it,now i want to limie the text he is entering in it to certaim characters.
Can anybosy suggest me the right approach for doing this????
Thanks in advance...
|
|
|
|
|
You'd have to handle the CBN_EDITUPDATE notification (documentation here) - which is sent when the text in the edit box is changed - then get the text in the edit control portion of the combo box, using either the ComboBox_GetText() or GetWindowText() function (documentation here and here respectively).
Then you can check for unwanted characters in the text retrieved from the edit control by looping through the char s.
Regards,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
I'm using the timerqueuetimers that MFC provides in my app. No problems at the moment with them but I do have one puzzling question I can't answer.
With TimerQueueTimers you are allowed to supply context or user specified data as a parameter which can be used when the callback gets invoked. Now if I want to stop the timer (ie delete it) I call DeleteTimerQueueTimer(). All well and good but how do I delete any user data I've attached as a parameter when I created the timer? The documentation says nothing. Does it automatically delete the parameter?
Appreciate any input.
|
|
|
|
|
jbem wrote: the timerqueuetimers that MFC provides
That's Win32
jbem wrote: Does it automatically delete the parameter?
No! You are responsible for cleaning up any resources
associated with the user param if necessary.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote:
No! You are responsible for cleaning up any resources
associated with the user param if necessary.
That's what I feared. So how does one delete the parameter one supplied at timer creation. Surely we don't have to keep track of a map that maps handles to parameters to delete?! I'd be interested in hearing a confirmation that I need to keep track of it all myself but in the meantime I'll start making the changes to keep track of it because I have a feeling that's the way it's headed. It's be nice if the documentation mentioned these things..
modified on Monday, September 1, 2008 3:29 PM
|
|
|
|
|
Hi all
I need to read some data from binary file that it's structure like the following:
record size, record...
Reading the size, then the record etc. not efficiently.
Which of the ways more efficient:
1)Reading to fixed size buffer block of data, and any time the part of the record was cut I'm using fseek and rewind position indicator associated with the stream backward.
Example: I have 16K buffer, and each record has arount 2.5K, so I process about 6 records, then calling fssek(fp, total_processed_bytes, SEEK_SET);
2)Doing the same with two buffers but without fseek calls.
3)Some other idea?
Thanks.
|
|
|
|
|
Evgeni57 wrote:
Which of the ways more efficient:
1)Reading to fixed size buffer block of data...
2)Doing the same with two buffers...
Neither.
I don't think you will get better performance by reading into your own buffer (although you might want to read up on the Stream I/O[^] functions you are using).
Your calls to fread() /fseek() (or whatever you are using) are already buffered. So, not only does the library call have to read data from the disk and into its internal buffer, but then it has to copy it out of that internal buffer and into a buffer that you specify.
The reading sequence you described is always linear and forward reading (not a whole bunch of random access). Creating and managing an explicit, home-brew buffering system is actually likely to be less efficient, more error-prone, and take longer to code/test than just reading the information you need and moving on that way. Your first call to fread() will buffer up a block of memory internally. Subsequent calls will then read from the buffered data (for performance) and get new data from the device (when needed).
Of course, the best way to proceed is to code it in the simplest manner to get it working; test it for accuracy; then determine if you need better performance and then looking for alternatives.
Enjoy,
Robert C. Cartaino
|
|
|
|
|
Why do you need to do any seeking/rewinding?
You should be able to read that data entirely
sequentially.
If you're adding your own buffering on top of the buffering
already being done, then that's probably just making the process
less efficient.
You may be able to find a more efficient buffer size for your data
than the default 4K, but beyond that I would think just reading
record size and record pairs would be most efficient.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi, thanks for your replay.
Why do you need to do any seeking/rewinding?
Because data's size not fixed. Once record may be 60 bytes long, and once 2847 bytes long.
If I read any time 8192 bytes - size of disk's cluster, that I'm working with, then some records will be missed and seeking/rewinding or using my own buffering is essential. That's how it looks like for me.
I would think just reading record size and record pairs would be most efficient.
It will increase the number of the disk's accesses so I don't think it will be more efficient.
|
|
|
|
|
Evgeni57 wrote: It will increase the number of the disk's accesses so I don't think it will be more efficient.
No, it won't.
If you're using the fopen/fseek/etc. family of I/O functions, then
data is being read in 4K (by defult) chunks.
Evgeni57 wrote: If I read any time 8192 bytes - size of disk's cluster, that I'm working with, then some records will be missed and seeking/rewinding or using my own buffering is essential.
Assuming doing your own buffering (which currently is an
inefficient solution) you would parse records from your buffer until
there's not a complete record left. Then you shift the remaining contents
of the buffer to the beginning of the buffer and read more bytes from
disk. There's no rewinding or seeking backward required, and to do so
would be inefficient - you'd be reading the same data multiple times.
Given what you've described as your file spec, this is completely unnecessary.
If you intend to do your own buffering, then you should use UNBUFFERED I/O,
not fopen/fread/fseek/etc.
You've got a good file format for sequential reading, which is always the fastest.
Why are you trying to complicate that?
Do some benchmarks - I would bet simply looping using fread to read a record length
followed by an fread to read the record data will be more efficient than anything
you come up with involving random access (seeking backward).
You can then tune the default buffer size (see setvbuf()) to something more appropriate
for your typical record size. For example, reading 20 byte records with the default 4K
buffer is pretty efficient. Reading 8K size records would do better with a larger buffer,
maybe 32K.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
void OpenFiles(char ch, float gpa);
void initialize(int fcout, int mcout, float fgpa, float mgpt);
void sumGrades( int fcout, int mcout, float fgpa, float mgpa);
void averageGrades(float avfgpa, float avmgpa);
void printResults(int fcout, int mcout, float avfgpa, float avmgpa);
void main()
{
ofstream out;
ifstream in;
char ch;
float gpa;
float avfgpa;
float avmgpa;
int fcout, mcout;
float fgpa; //define female GPA
float mgpa; //define male GPA
initialize (fcout, mcout, fgpa, mgpa);
OpenFiles(ch, gpa);
while(!in.eof())
{
sumGrades(fgpa,mgpa,fcout,mcout);
in>>ch>>gpa;
averageGrades(avfgpa, avmgpa);
}
printResults(fcout, mcout, avfgpa, avmgpa);
return;
}
void OpenFiles(char ch, float gpa)
{
ofstream out;
ifstream in;
in.open("k:\\prob-7.txt",ios::in);
if (!in)
{
cout<<"Can not open input file"<<endl;
cout<<"program terminates!!"<<endl;
}
in.get(ch);
in>>gpa;
in.eof();
out.open("k:\\out.txt", ios::out);
out<<fixed<<showpoint;
out<<setprecision(2);
//out<<"Female" <<ch<<endl;
}
void initialize(int fcout, int mcout, float fgpa, float mgpa)
{
fgpa = 0.0;
mgpa= 0.0;
fcout = 0;
mcout = 0;
}
void sumGrades(int fcout, int mcout, float fgpa, float mgpa)
{
char ch;
float gpa;
OpenFiles(ch, gpa);
switch (ch)
{
case 'F':
case 'f': fgpa = fgpa+gpa;
fcout++;
//avfgpa = fgpa/fcout;
break;
case 'M':
case 'm': mgpa = mgpa + gpa;
mcout++;
//avmgpa = mgpa/mcout;
break;
default: cout<<"invalid gender"<<endl;
return;
}
}
void averageGrades(float avfgpa, float avmgpa)
{
float fgpa, mgpa;
int fcout, mcout;
sumGrades(fcout, mcout, fgpa, mgpa);
avfgpa = fgpa/fcout;
avmgpa = mgpa/mcout;
}
void printResults(int fcout, int mcout, float avfgpa, float avmgpa)
{
ofstream out;
out<<"Number of female ="<<fcout<<endl;
out<<"Average female GPA = "<<avfgpa<<endl;
out<<"Number of male ="<<mcout<<endl;
out<<"Average male GPA ="<<avmgpa<<endl;
out.close();
}
give a lots of error vs warning, I think that having trouble with function calls, and passing to main function, but i have no idea to fix cause the book i am studying hasnt clear out much.
summerize what program will do :
open a file with 2 columes; one is letter of f or m (represent for female and male), the other colume is GPA (grade).
read it and sum the gpa of female , sum the gpa of male, and display the everage of female and male gpa.
the function calls need to have 5 of them:
initialize variable
open and format output
sum gpa of female and male
find the average of female male gpa
print the rerults.
|
|
|
|
|
Please read the posting guidelines here[^] because your post is almost unreadable.
|
|
|
|
|
In the sample code below,
when an exception is catched,
e.what() always returns ios_base::failbit set .
Is there any built in way that can tell more detailed information about the exception?
ifstream infile;
infile.exceptions(ios_base::failbit|ios_base::badbit);
try {
infile.open(L"c:\\data1.txt");
int i,j,k;
infile>>i>>j>>k;
wcout<<i<<L' '<<j<<endl;
} catch (exception &e) {
cout<<e.what()<<endl;
return -1;
}
system
|
|
|
|
|
What if you catch ifstream::failure instead of exception?
...
} catch (ifstream::failure e) {
...
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
try {
...
} catch (ifstream::failure &e) {
cout<<e.what()<<endl;
return -1;
}
I tried this, but the same result.
system
|
|
|
|
|
//suppose data.txt is like this:
//11 22
int i,j;
ifstream infile(L"data.txt")
infile>>i>>j;
//what if data.txt is like this:
//aa bb
string a,b;
infile>>a>>b;
Any STL way to do this?
system
|
|
|
|
|
What is the most efficient way to invert the RGB portion of an ARGB without effecting the alpha byte?
For simplicity, I'm assuming the alpha byte is the most significant byte, followed by the Red, Green, and Blue (at least for the sake of discussion)
My best guess at this point is something like...
color ^= 0x00FFFFFF;
modified on Saturday, August 30, 2008 1:41 PM
|
|
|
|
|
bob16972 wrote: My best guess at this point is something like...
color ^= 0x00FFFFFF;
I don't know how you'd flip the bits more efficiently than that.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks. I wasn't sure if there was a machine code or assembly guru who would pouce on that with something faster.
|
|
|
|
|
Maybe on the looping but a 32-bit XOR is a single instruction.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
In C#, when calling a GUI control from another thread, you can use Control.IsInvokeRequired and Control.Invoke.
I am looking for the C++ equivalent (when using CWnd).
Any ideas?
|
|
|
|
|
Typically UI processing is all done on one thread.
You can post messages from another thread to windows created
on the UI thread. The posted messages will be queued and processed
on the UI thread.
I've personally never needed a "IsInvokeRequired" since I generally
know if I'm writing UI thread code or not.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi all,
I want to open network connection dialog, how can i do so?
thanks in advance
|
|
|
|
|