|
Hi all,
I've a problem about reading a file. I opened the file using CFile. when I asked for the size of file using CFile::GetLength() it's returing zero. Please help me for the solution.
Code here
-----
CFile pFile;
CFileException e;
if(!pFile.Open("img_1.bmp", CFile::modeRead | CFile::shareDenyWrite, &e))
{
printf("\n Error in opening File\n");
exit(1);
}
DWORD dwStart = pFile->GetPosition();
DWORD dwBitsSize = pFile->GetLength();
printf("\n Size %d\n", dwBitsSize);
BITMAPFILEHEADER fileHeader;
memset(&fileHeader, 0, sizeof(fileHeader));
UINT count = pFile->Read(&fileHeader, sizeof(fileHeader));
printf("\nByte Read %d %d\n", count, pFile->GetPosition());
----
Byte read and the current positon also give me the 'zero' values.
Thanks in Advance
Ardhendu
|
|
|
|
|
here the member access operator is "."
pFile.Open("img_1.bmp", CFile::modeRead | CFile::shareDenyWrite, &e)
and here the member access operator is "->"
pFile->Read(&fileHeader, sizeof(fileHeader));
There is no spoon.
mail
|
|
|
|
|
Sorry, I gave only the pseudo code. Actually the CFile is passed to another funtion. It like:
BOOL GetBitsValue(CFile *pFile)
{
DWORD dwStart = pFile->GetPosition();
DWORD dwBitsSize = pFile->GetLength();
printf("\n Size %d\n", dwBitsSize);
BITMAPFILEHEADER fileHeader;
memset(&fileHeader, 0, sizeof(fileHeader));
UINT count = pFile->Read(&fileHeader, sizeof(fileHeader));
printf("\nByte Read %d %d\n", count, pFile->GetPosition());
}
Even If I check after opening the file in the same function it returns zero. Its like:
---
DWORD dwStart = pFile.GetPosition();
DWORD dwBitsSize = pFile.GetLength();
printf("\n Size %d\n", dwBitsSize);
BITMAPFILEHEADER fileHeader;
memset(&fileHeader, 0, sizeof(fileHeader));
UINT count = pFile.Read(&fileHeader, sizeof(fileHeader));
printf("\nByte Read %d %d\n", count, pFile.GetPosition());
---
Thanks,
Ardhendu
|
|
|
|
|
Cannot see anything wrong with your code.
btw from wot kind of application are you trying to run this code.
There is no spoon.
mail
|
|
|
|
|
Have you tried entering the fully qualified path for the filename e.g. "c:\\graphics\\img_1.bmp" ?
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
I printed the full path using pFile.GetFilePath(), it's giving me the full path (correct) of the file.
|
|
|
|
|
Um, Sorry I can not see anything wrong with what you are attempting to do. GetLength should return the size in bytes of the opened file in question.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
It is hard for us to help you, if you do not tell us whether there is an error when you use CFile::Read(...).
DWORD dwStart = pFile->GetPosition();
DWORD dwBitsSize = pFile->GetLength();
printf("\n Size %d\n", dwBitsSize);
BITMAPFILEHEADER fileHeader;
memset(&fileHeader, 0, sizeof(fileHeader));
TRY
{
UINT count = pFile->Read(&fileHeader, sizeof(fileHeader));
printf("\nByte Read %d %d\n", count, pFile->GetPosition());
}
CATCH(CFileException, e)
{
printf("\nCFileException %d\n", e->m_cause);
}
END_CATCH
|
|
|
|
|
In the calls to printf() , what happens if you change %d to %lu ?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hi there,
can anyone tell me how to stop a link opening in a new window and just use the existing window??
For example: I've got a little explorer app(MFC) with 2 windows. The left side displays the C:/drive
and the right side displays a FTP address. The left window navigates fine, but the right side insists on opening
a new explorer window when I click on a link, instead of changing inside its own window. When the ne window opens... that navigates fine... just the way I want the right side widow to.
Its probably something stupid, knowing me... definately something stupid But I've tried a bunch of stuff for the last
24 hours now and nothing stops it opening in a new window!
Help!
Henry F
|
|
|
|
|
If I understand you correctly, the right pane is actually an HtmlView displaying a web page. In any case, to redirect a link to a specific window you have to use the "target" property. For example:
// somewhere in an HTML file
<a href="http://www.website.com" target="_self">Click here</a>
"target" accepts any of the following:
_blank, which opens the link in a new window
_self, which opens the link in the current window
_parent, which opens the link in the parent window
_top, which opens the link in the top most window
Hope this helps.
|
|
|
|
|
Thanks for the reply man, but(as usual) its not the HTML I need to change.
Basically its an Explorer Window displaying content on a server via FTP:
Naviagte2(_T(ftp://whatever.com),NULL,NULL)
It displays fine but when I want to open a folder - it launches a new explorer window outside the application and displays the info in that window.
Is there some way of controlling this so that all clicked links open inside the application only?
thanks
|
|
|
|
|
handle OnBeforeNavigate2, cancel the navigation if it's to another window, and navigate to the url just cancelled... something like that.
|
|
|
|
|
Clever idea!
Any chance you could scribble the code down? I'll buy u a cup of tea
|
|
|
|
|
I have an important CStatic text-lable in my CDialog class.
How may I change the font and color of the text in a simple way?
_____________________________
...and justice for all
APe
|
|
|
|
|
You need to subclass your static control. Then overwrite the OnPaint() member with the following example:
void CMyStaticCtrl::OnPaint() <br />
{<br />
CPaintDC dc(this);
<br />
CFont newFont;<br />
LOGFONT lf;<br />
<br />
memset(&lf, 0, sizeof(LOGFONT));<br />
lf.lfHeight = 20;<br />
lf.lfWeight=FW_BOLD;<br />
strcpy(lf.lfFaceName, "ARIAL");<br />
newFont.CreateFontIndirect(&lf);<br />
<br />
dc.SetBkMode(TRANSPARENT);<br />
dc.SetTextColor(RGB(255, 0, 0)); <br />
dc.SelectObject(&newFont); <br />
dc.TextOut(0, 0, "Text in Arial, bold, red");<br />
}
Hope this helps
MS
|
|
|
|
|
Thanks!
A little irritating that you need to subclass to just change the color.
Again - Thanks!!
_____________________________
...and justice for all
APe
|
|
|
|
|
That's right, but the "normal" way didn't work for me. It changed the font, but not the color and the background appeared white even though i set it to transparent.
MS
|
|
|
|
|
I Want to create a popup window at my dialog based program,could you tell me how?
Could I register a new window class for it?
If no necessary,how can I get the lpClassName which is used at the follow function ?
HWND CreateWindowEx(
DWORD dwExStyle,
LPCTSTR lpClassName,
LPCTSTR lpWindowName,
DWORD dwStyle,
int x,
int y,
int nWidth,
int nHeight,
HWND hWndParent,
HMENU hMenu,
HINSTANCE hInstance,
LPVOID lpParam
);
Thanks!
free like a bird
|
|
|
|
|
CString sClassName = AfxRegisterWndClass (CS_HREDRAW|CS_VREDRAW);
now use sClassName
There is no spoon.
mail
|
|
|
|
|
lpClassName is either an existing class name
e.g.
Button, Edit, SysTreeView32, ...
or a class that you registered via RegisterClassEx().
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Hello everybody,
I want to paint something outside my app.
like a multimedia keyboard:
when I increase or decrease the volume something
appears on screen.
best wishes.
thanks
|
|
|
|
|
Use GetDesktopWindow() API to get Handle to Desktop Window, Then create a DC with this handle and enjoy
Imagine that you are creating a fabric of human destiny with the object of making men happy in the end, giving them peace and rest at last, but that it was essential and inevitable to torture to death only one tiny creature..and to found that edifice on its unavenged tears, would you consent to be the architect on those conditions? Tell me, and tell me the truth!
-Fyodor Dostoevsky, The Brothers Karamazov
|
|
|
|
|
Dear friends,
I try to develop a program which can hook into IE (toolbar buttons and/or menu items in IE window) to get all text in all text fields in a HTML page being displayed by IE. This will perform when user click on the toolbar button or menu item.
I don't know how to start and from where to begin. Could you please help me on this and thanks in advanced.
|
|
|
|
|
You will have to write a BHO(Browser Helper Object).
You can start from here[^]msdn
Also look for BHO samples here in codeproject also.
There is no spoon.
mail
|
|
|
|
|