|
Hello.
These are the codes that I have used to read a bin file and to store in 3 variables.
Most of the files read have 1024 columns, hence iI < 1024. If i try to open a file that is less than 1024, the program will give me unexpected file format error. How can detect the end of the file and break from the loop if a file of less than 1024 column is opened?
Thanks.
<br />
void CVecDoc::Serialize(CArchive& ar)<br />
{<br />
int iI, iK;<br />
unsigned char cDataOne, cDataTwo;<br />
short sSwap, as[3];<br />
<br />
if (ar.IsStoring())<br />
{<br />
}<br />
else<br />
{<br />
for (iI = 0; iI < 1024; iI++)<br />
{<br />
for (iK = 0; iK < 3; iK++)<br />
{<br />
ar >> cDataOne >> cDataTwo;<br />
<br />
sSwap = ((short)cDataTwo << 8) + (short)cDataOne;<br />
as[iK] = sSwap;<br />
<br />
m_a1[iI] = as[0];<br />
m_a2[iI] = as[1];<br />
m_a3[iI] = as[2];<br />
}<br />
}<br />
}<br />
}<br />
|
|
|
|
|
Hi,
There is an end of file function eof() which you can use. It is a boolean function which returns a non-zero number when the end of file is reached otherwise it returns zero (meaning false).
You will have to use a stream variable to use the function.
A very simple article explaining the function is here:
http://www.mathbits.org/MathBits/CompSci/Files/End.htm
Hope this helps.
- Moonis
|
|
|
|
|
Aint wrote: Most of the files read have 1024 columns...
How can...break from the loop if a file of less than 1024 column is opened?
Which is a concept known only to your code. It's up to you to determine if the file contains 1024 columns or not.
Aint wrote: If i try to open a file that is less than 1024, the program will give me unexpected file format error.
Have you stepped through the code to find out at what point this error occurs?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Yes. It shows that the error occur before the loop end, when iI = 300+.
Can I use ar.??? to detect the end of the file?
|
|
|
|
|
Aint wrote: It shows that the error occur before the loop end, when iI = 300+.
How large are m_a1 , m_a2 , and m_a3 ?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
Is this all in same thread?
nave
|
|
|
|
|
No, It´s a different question, the other one is solved. That´s a completely different part of the app.
|
|
|
|
|
garfield185 wrote: It´s a different question, the other one is solved.
different question?I dont understand..
nave
|
|
|
|
|
There are a few questions that you need to answer before you get the answer here
1) How are you creating the dialog (Modal/Modeless)?
2) Are you explicitly trying to set the focus on the Edit Control. If yes,
Do remember one thing - OnInitDialog returns TRUE to indicate that the focus should be set to the first control in the dialog box. So if you are setting the focus explicitly to some other control return FALSE from OnInitDialog.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Ok, lets see.
De dialog is created as Modal with DoModal();
I try to set the focus with this line:
SendDlgItemMessage(IDC_TXTISSI,WM_SETFOCUS);
//Where IDC_TXTISSI is the ID of the EditBox I want to write on
I changed the return value at the OnInitDialog. It doesn´t work. I still have to press TAB key and make a round if I want to write... Could it be some property of the EditBox? I have compared with all the others and have the same properties...
|
|
|
|
|
Hi Anshuman, I have done another little proyect an the same happens.
Check it here.
http://www.megaupload.com/?d=K43YK4CM
Look at the behaviour of the edit box
|
|
|
|
|
_AnShUmAn_ wrote: Do remember one thing - OnInitDialog returns TRUE to indicate that the focus should be set to the first control in the dialog box. So if you are setting the focus explicitly to some other control return FALSE from OnInitDialog.
Whether TRUE or FALSE is returned will have no impact on what garfield185 is seeing. Once a control is selected via the mouse, anything that happened in OnInitDialog() is gone.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Can you show your code how did you try to it(not full code )?
|
|
|
|
|
I don´t know which part of the code is making this...
Anyway, if you see the proyect I uploaded in the previous post, it has only an Edit Box, and it´s impossible to write on it until you reach the edit control with the tab key.
Why is that happening?
|
|
|
|
|
Well it seems I cant use of your upload now.
|
|
|
|
|
Hi members!
I´m using the event PreTranslateMessage to catch the Return Key when it´s pressed in a EditBox.
When the user presses VKRETURN...
BOOL CConfLlamDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->wParam == VK_RETURN) // if enter key pressed return true
{
MessageBox("Error");
}
return CDialog::PreTranslateMessage(pMsg);
}
If the user accepts that message Box clicking with the mouse there is no problem, but when I accept the message box pressing Enter key, it generates another VKRETURN message that calls again the PreTranslateMessageFunction.
Can someone help me?
Thanks everybody!!
|
|
|
|
|
You're not checking the message type!
if(pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_RETURN)
Steve
|
|
|
|
|
I always say the same:
I love using this forum and I love you guys!! You are my salvation!! I´m about to finish my proyect and I have no time left!
I really thank you a lot, Steve.
|
|
|
|
|
In addition to what Stephen said, check whether the message is for edit control
if(pMsg->wParam == VK_RETURN && pMsg->message == WM_KEYDOWN && pMsg->hwnd == m_Edit.m_hWnd )
nave
|
|
|
|
|
That´s perfect. Thank you two!
|
|
|
|
|
hi
Any one tell me, how to compress the text data and decompress the same.
i send the text data through socket ,so before sending the data i have to compress and after receving decompress it.
this is done in vc++
if any one know give sample code or give the suggestion
shakumar
|
|
|
|
|
Try to type Compression on CP article search...
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.
|
|
|
|
|
shakumar_22 wrote: Any one tell me, how to compress the text data and decompress the same.
zlib can do this for you.
Its free and readily available for inclusion in your project.
Failure is not an option - it's built right in.
|
|
|
|
|