|
Check for the WM_SIZE event (OnSize() function).
|
|
|
|
|
It sounds like you are just redrawing the control in a new color and not setting it to the new color. In orther words, you should be calling a function that changes the drawing color of the control so that when it is being repainted it uses the new color.
You should not need to define your own OnPaint() function to accomplish this.
The flickering is noramaly caused by the OnEraseBkgnd().
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Hey,
can you please help me. I've created a CustomControl which draws a special table. No I want to implent a scroll-function. So I added the style WS_HSCROLL and handled the message. I'd use the ScrollWindow function. Now the table scrolls, but the "new area" is not filled correctly. There is the last column (before scrolled) smeared. Do I have to code a special OnDraw-function. I thought it is enough when I paint outside the client area and then scroll....
|
|
|
|
|
Hello everybody,
Im new in c++ and i have a problem because i have mfc program (client/server) where the client identidy the USB devices connected and i save this information in a txt file with this information:
{745A17A0-74D3-11D0-B6FE-00A0C90F57DA}
{483K23F8-74D3-11D0-B6FE-00A0C90F57DA}
and i want to know if this two usb devices are registered adn for this i use another text file in the server part whith all the usb registered that i want, for example:
{745A17A0-74D3-11D0-B6FE-00A0C90F57DA}
So if one usb is in the database i want to show a message that is registered. And i have this code but doesnt work, because dont show me the message:
void CIOCPClientDlg::compareFiles(){
char data[40];
std::ifstream fileusb ("GUIDs_found.txt");
char data2[40];
std::ifstream database ("C:\Documents and Settings\Densitet\My Documents\Visual Studio Projects\IOCP-SRC\IOCP-SRC\IOCP\Debug\USBDevices.txt");
bool salida =false;
while (!fileusb.eof() )
{
fileusb.getline(data,40);
while (!database.eof()&&(!salida==false))
{
database.getline(data2,40);
if (data==data2){
AfxMessageBox("USB registered");
}
salida=false;
}
}
}
If somebody can help me with this proble.
Than you for the possible help
|
|
|
|
|
Replace:
if (data==data2){
by that:
if (strcmp(data,data2) == 0){
What you are doing is comparing the two pointers which are of course different (the pointer data points to another location than the pointer data2).
|
|
|
|
|
Thank u for the help. I replaced that but i still can´t see the messagebox with USB registered so is any problem because i know that the information of the first file(data) is in the other file(data2), for sure. So i dont know what to do. Thank u.
|
|
|
|
|
densitet wrote:
std::ifstream database ("C:\Documents and Settings\Densitet\My Documents\Visual Studio Projects\IOCP-SRC\IOCP-SRC\IOCP\Debug\USBDevices.txt");
This won't work with single backslahes in a string literal.
Cedric has already given you a solution, but I have question. Since this is an MFC application, why are you using char instead of CString ? By changing data and data2 to CString , you can then do the more natural if (data == data2) comparison.
Also, for each line that you are reading from the fileusb object, you are looking for that line in the database object. That works fine for the first pass through the database object but I don't see where that object gets reset so that it can be searched again for the next line in the fileusb object.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
ok i understand
so now i have this code:
char data[128];
std::ifstream fileusb ("GUIDs_found.txt");
char data2[128];
std::ifstream database ("C:\\USBDevices.txt");
bool salida2 =false;
while (!fileusb.eof() )
{
fileusb.getline(data,128);
database.getline(data2,128);
while (!database.eof()||(salida2!=true))
{
if (strcmp(data,data2) == 0){
salida2=true;
AfxMessageBox("USB registered");
break;
}
else{
fileusb.getline(data,128);
}
}
salida2=false;
}
fileusb.close();
database.close();
It is only a function that i added to my program, and it works for the first case but how i can reset fileusb because i want that it starts again to compare with all the lines that i have in the database, because when fileusb finish with all the lines comparing with the first element of database, databse changes to the second line, but fileusb doesnt reset.
Thank u for the help
|
|
|
|
|
Try the istream::seekg() method.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
dude I have no ideea why you complicate so much.
in a coule of line you couldcompre very huge txt files
CreateFile()
CreateFileMapping()
MapViewOfFile()
memcmp()
good luck
gabby
|
|
|
|
|
Which would not produce the desired result. Searching through one file for occurrences of strings contained in another file is not as simple as using memcmp() because the files are in no way guaranteed to be the same. They could be different sizes and could be ordered differently.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
if the file is small enough he could use
StrStrI(mapviewoffile1,mapviewoffile2)
otherwise:
if (size(f1)==size(f2))
while (!feof(f1)||!feof(f2))
{
if (fgetc(f1)!=fgetc(f2))
{
resemblance=FALSE;
break;
}
}
if(!resemblance)
{}
all this code in a thread.
gabby
|
|
|
|
|
Go back and read the initial post again. One text file will contain the USB devices for a particular machine. Another text file, the one stored on the server, will contain a much larger list of the registered USB devices to search through. There is no way you can reliably use StrStrI() or fgetc() for this type of comparison.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Extactly, my fileusb can has 2, 3, 4 usb devices plugged. And my database can has maybe 10 usb devices registered. So im getting crazy because i dont know how to use correctly istream::seekg(); and where exctaly, i suposse when i find one usb registered then reset with this function fileusb and i start in the beginning again and i compare with the second od the dataserver??, so i only have to write this function and the rest is ok??.. Thank u very much for the help
void compareFiles(){
char data[40];
std::ifstream fileusb ("GUIDs_found.txt");
char data2[40];
std::ifstream database ("C:\\USBDevices.txt");
bool salida2 =false;
while (!fileusb.eof() )
{
fileusb.getline(data,40);
database.getline(data2,40);
while (!database.eof()||(salida2!=true))
{
if (strcmp(data,data2) == 0){
salida2=true;
//data[40]=0;
AfxMessageBox("USB registered");
break;
}
else{
fileusb.getline(data,128);
}
}
salida2=false;
}
fileusb.close();
database.close();
}
|
|
|
|
|
Sorry but with what parameters i do the seekg because im looking the msdn and i dont have nothing clear.
|
|
|
|
|
look this:
CreateFile()
CreateFileMapping()
MapViewOfFile()
memcmp()
good luck
gabby
|
|
|
|
|
ifstream::seekg() works. If you are reseting to the beginning of the file, you can just close and open the file again.
Danny
|
|
|
|
|
Ok, now i have that, i have changed things that u told me, but now i think it is in a infinitive loop. Im new in c++ but a simple comparation to see if for example 2 elements from one file are in other file with 10 is difficult right now because i can't do a breakpoints to see where is the error. I dont know if u have any ideas for this code that i show here but the idea is that i described. thank u for all the help.
char data[128];
char data2[128];
bool salida2 = false;
ifstream fileusb;
ifstream database;
fileusb.open("GUIDs_found.txt", ios::in);
database.open("USBDevices.txt", ios::in);
fileusb.getline(data,128);
while (!fileusb.eof())
{
database.getline(data2,128);
while ((!database.eof())||(salida2!=true))
{
if (strcmp(data,data2) == 0){
salida2=true;
//database.clear();
database.seekg(0,ios::beg);
database.close();
database.open("USBDevices.txt", ios::in);
database.getline(data2,128);
fileusb.getline(data,128);
}
else{
database.getline(data,128);
}
}
salida2 = false;
}
fileusb.close();
database.close();
|
|
|
|
|
How about:
fileusb.getline(data, 128);
while (! fileusb.eof())
{
database.getline(data2, 128);
while (! database.eof() && salida2 != true)
{
if (strcmp(data, data2) == 0)
salida2 = true;
else
database.getline(data, 128);
}
database.seekg(0, ios::beg);
fileusb.getline(data, 128);
}
database.close();
fileusb.close();
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Ok, think i solved that, but when i find the first elemente and i change for the second in the first file i see a messagebox without nothing and later i start again good and when for example the second element is founded in the file i can't show USB registered i only show nothing but with the first i see USB registered,Maybe is the buffer??
fileusb.open("GUIDs_found.txt", ios::in);
database.open("USBDevices.txt", ios::in);//
while (! fileusb.eof())
{
fileusb.getline(data, 500);
AfxMessageBox(data);
database.getline(data2, 500);
AfxMessageBox(data2);
while (! database.eof() )
{
if (strcmp(data, data2) == 0){
//salida2 = true;
AfxMessageBox("USB registered");
break;
}
else if (strcmp(data,data2) != 0){
database.getline(data2, 500);
AfxMessageBox("USB NOT registered");
AfxMessageBox(data2);
}
}
database.seekg(0, ios::beg);
fileusb.getline(data, 500);
AfxMessageBox(data);
}
database.close();
fileusb.close();
|
|
|
|
|
Too many calls to getline() . Try:
fileusb.open("GUIDs_found.txt", ios::in);
database.open("USBDevices.txt", ios::in);
while (! fileusb.eof())
{
fileusb.getline(data, 500);
AfxMessageBox(data);
while (! database.eof())
{
database.getline(data2, 500);
AfxMessageBox(data2);
if (strcmp(data, data2) == 0)
{
AfxMessageBox("USB registered");
break;
}
}
database.seekg(0, ios::beg);
}
database.close();
fileusb.close();
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
And don't forget to put a check for the existence of the files after the open statement!
<br />
fileusb.open("GUIDs_found.txt", ios::in);<br />
database.open("USBDevices.txt", ios::in);<br />
if(!fileusb){<br />
return;<br />
}<br />
if(!database){<br />
return;<br />
}<br />
Even though it adds many lines of code, you should always check for errors... usually.
Danny
|
|
|
|
|
bugDanny wrote:
Even though it adds many lines of code, you should always check for errors... usually.
Of course, but that's not related to the problem(s) that densitet is having.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-- modified at 17:07 Wednesday 14th September, 2005
|
|
|
|
|
DavidCrow wrote:
Of course, but that's not related to the problem(s) that densitet is having.
Unless, of course, sometime (now or in the future) one of those files (for some unknown reason) does not exist where they were expected to be. In which case, the program would be stuck in an infinite loop, since it will never find eof() of the missing file. And an infinite loop is exactly the problem densitet was having.
Danny
|
|
|
|
|
bugDanny wrote:
And an infinite loop is exactly the problem densitet was having.
At one point in time, yes, but it was not because of a non-existent file.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|