|
Thanks very much, Pallini! Your code is very useful for me.
In case of trouble, I'll come back to you again.
Many thanks,
Ing LengIeng
Software Developer
|
|
|
|
|
You're welcome.
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]
|
|
|
|
|
Hi again!
Now I still have problem concerning reading its content. Can you guide me on that? The following is my code:
BITMAPFILEHEADER bmpHeader;
BITMAPINFO bmpInfo;
FILE *fp = fopen("C:\\test.bmp","rb");
fread((char*)&bmpHeader,sizeof(BITMAPFILEHEADER),1,fp);
fread((char*)&bmpInfo,sizeof(BITMAPINFO),1,fp);
WORD bmpWidth = (WORD)bmpInfo.bmiHeader.biWidth;
WORD bmpHeight = (WORD)bmpInfo.bmiHeader.biHeight;
int counter=0;
fseek(fp,bmpHeader.bfOffBits,SEEK_SET);
BYTE *data = new BYTE[bmpWidth*bmpHeight];
while(!feof(fp))
{
for(int i=0; i<bmpwidth;> {
if(!feof(fp))
{
fread((BYTE*)&data[counter], sizeof(BYTE), 1, fp);
counter++;
}
else
{
break;
}
}
}
fclose(fp);
Here I got an error message saying that "Array index out of bound". What is the correct way of reading it?
Ing LengIeng
Software Developer
|
|
|
|
|
Here again you're doing a mistake on computing the memory required.
For a monochrome bitmap, the size required is bit more elaborate than
(Width * Height ), since the file holds 8 pixels in each byte , and the horizontal line is padded (if I remember well) to have a 32-bit multiple length. Hence
int bytesPerLine = Width / 8;
if (Width % 8) bytesPerLine++;
if (bytesPerLine % 4 ) bytesPerLine += 4 - (bytesPerLine % 4);
int iSize = bytesPerLine * Height;
I hope the above is correct (I haven't tested it). You may verify it comparing the result with the actual size of the file minus the bfOffBits offset.
Two final notes:
- If you allocate memory of a given
size don't trust any other counter (you're using EOF ) while filling it: check always you're not exceeding the allocated size (in your code try to read until the allocated buffer is filled and not until the end of the file: if the file contains more bytes your application crashes). - If you need to read a block, the read it directly, don't read a
byte at time.
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]
|
|
|
|
|
Thank you very much! I'll check that.
You are very helpful.
Best regards,
Ing LengIeng
Software Developer
|
|
|
|
|
Hi all,
Wat is the difference between closing a dialog by using CDIalog::OnOK() or PostQuitMessage(0).
Can I use both at a time?
Regards
Babu
|
|
|
|
|
Both have different usage. What do you want to do? To close a dialog, why not use EndDialog()? which is straight forward.
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
Babu@codeproject wrote: Wat is the difference between closing a dialog by using CDIalog::OnOK() or PostQuitMessage(0).
PostQuitMessage will quit your entire application always.
But OnOk will close only the dialog it is called for ( if it is not main dialog)
Also OnOK will call UpdateData().
I hope it helps.
Regards,
Sandip.
|
|
|
|
|
|
|
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
Please Stop posting same question.
You have got answers to previous posts Try and do something based on those answers...
Regards,
Sandip.
|
|
|
|
|
|
Instead, read carefully the posting guidelines (even if they are no more at the top of the forum... ) before posting.
No one here will help you if you:
- post again and again the same question.
- make such stupid and rude replies.
BTW probably *any* idea is a surplus for your brain.
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]
|
|
|
|
|
|
The good answer is:
"Be polite, study harder, check previous answers (see, for instance [^] ), use profitably Google and CodeProject's article search engine."
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]
|
|
|
|
|
I want to add a button to my app, I am thinking, a function call to create an area that when clicked would jump to some callback function. I could use this to change the image in the area just clicked, and perform what ever action I want due to the button press.
I think I need to use CreateWindow() to do this, but I'm not figuring much else about this.
I have not been able to find an example that is simple and straightforward for C on a WM5 device.
If anyone knows of an example or simple explanation that would help, I'd appreciate it.
|
|
|
|
|
Hi, I am still a newbie in MFC
I 've got a problem with my console application program
I use one thread in there , which is I use CWinThread
and it terminates when time is equal to timeout
but I need to handle if the user want to terminate immediately in the console application
so the way I did is
I create this function
BOOL WINAPI ConsoleHandler(DWORD CEVENT)
{
switch(CEVENT)
{
case CTRL_CLOSE_EVENT:
myClass.CleanUpThread();
break;
}
return TRUE;
}
so when the user want to immediatelly, it will go to that function and clean up the thread
however, everytime, I test and debug, I always windows ballon said that "windows cannot end this program, it may need more time to complete an operation"
How to disable that ballon? so i dont want user to see that one, and the program will wait until the thread is cleared.
Thanks so much,
|
|
|
|
|
Clean up thread? I think you are trying to clean up a live wire with your wet hands. Are you trying to terminate() your thread by force? if yes never do it. Just come out of the loop with a boolean condition check like.
<br />
while(bRunThread)<br />
{<br />
}<br />
When the user wants to come out, just set bRunThread =false.. and you can also use events to make sure the thread has really exited.
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
thanks I've fixed that one
|
|
|
|
|
What was the problem?
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
I changed the way my program works.
instead, waiting for period of time, then shutdown
I keep it loop until keyboard event occurs or user press close
and I discovered that there were some memory leaks in my program.
I fixed the memory leak, change the program flow and done
Anyway, thanks for your help
Regards,
Arif Liminto
|
|
|
|
|
Are there any rules of thumb, guidelines, issues with, etc... about having a return in a catch block?
For example:
try {
// Some code...
} catch (std::exception &) {
// log error
return -1;
}
Also try this test using VC with VS 2005 SP1 (Microsoft Visual C++ 2005 77626-009-0000007-41138)
1) Create standard MFC dialog based application
2) Add new method with signature: int foo();
3) in foo add the following code:
std::vector<int> v;
try {
v.push_back(1);
} catch (std::exception &;) {
return 1;
}
// Just some code that does something...
if (v.size()) {
}
return 0;
4) Step through the code in debugger. On several systems, I see the debug statement indicator move onto the line with "return 1". The disassembly code is very strange indeed.
Any comments from the guru's out there?
Thanks!
|
|
|
|
|
clawton wrote: Are there any rules of thumb, guidelines, issues with, etc... about having a return in a catch block
Should be fine.
clawton wrote: Step through the code in debugger. On several systems, I see the debug statement indicator move onto the line with "return 1".
Yeah, that happens - it all depends how the debug information's been distributed through the code. Is it in Release or Debug mode? Debugging in Release mode is...interesting.
clawton wrote: The disassembly code is very strange indeed
In what sense?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote:
Is it in Release or Debug mode?
Debug mode.
Stuart Dootson wrote:
clawton wrote:
The disassembly code is very strange indeed
In what sense?
Well, I see the line with "return 1" in there twice...
Pasting from the dissassembly output window:
std::vector<int> v;
004131C6 lea ecx,[ebp-34h]
004131C9 call std::vector<int,std::allocator<int> >::vector<int,std::allocator<int> > (4110C3h)
004131CE mov dword ptr [ebp-4],0
try {
004131D5 mov byte ptr [ebp-4],1
v.push_back(1);
004131D9 mov dword ptr [ebp-118h],1
004131E3 lea eax,[ebp-118h]
004131E9 push eax
004131EA lea ecx,[ebp-34h]
004131ED call std::vector<int,std::allocator<int> >::push_back (4119B5h)
004131F2 jmp $LN5 (413211h)
} catch (std::exception &) {
return 1;
004131F4 mov dword ptr [ebp-10Ch],1
004131FE mov dword ptr [ebp-4],0
00413205 mov eax,offset $LN9 (41321Ah)
0041320A ret
void CCatchTestDlg::OnBnClickedOk()
{
Test(1,0);
}
int CCatchTestDlg::Test(int foo, unsigned char * goo)
{
std::vector<int> v;
try {
v.push_back(1);
} catch (std::exception &) {
return 1;
}
0041320B mov eax,offset $LN5 (413211h)
00413210 ret
} catch (std::exception &) {
return 1;
00413211 mov dword ptr [ebp-4],0
00413218 jmp $LN9+17h (413231h)
$LN9:
0041321A mov dword ptr [ebp-4],0FFFFFFFFh
00413221 lea ecx,[ebp-34h]
00413224 call std::vector<int,std::allocator<int> >::~vector<int,std::allocator<int> > (41192Eh)
00413229 mov eax,dword ptr [ebp-10Ch]
0041322F jmp $LN9+54h (41326Eh)
if (v.size()) {
00413231 lea ecx,[ebp-34h]
00413234 call std::vector<int,std::allocator<int> >::size (4115A5h)
|
|
|
|
|