|
wow,
it seems that you don't know well what you're doing...
you create c with the value 0, but you never reassign it... so it will always display 0 !!!
moreover, you declare it as a char , that means that it will take a maximum value of 127 (char range is [-128; 127])... declare it as unsigned char instead.
then, why do you need to display the code * 100 ???
another thing : you never delare n ; what is it? i ?
i suggest you this :
std::ofstream file;
file.open("Test.dat", std::ios::out | std::ios::trunc | std::ios::binary);
unsigned char c = 0;
for( c = 0; c < 256; c++ ) {
file << c << c;
}
because a char is also an integer (not a character as in VB for example)...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Hello,
I guess that I wasn't paying much attention when I was stripping the code of obsolete stuff. Here is the code as it now is:
<br />
std::ofstream file;<br />
file.open("Test.dat", std::ios::out | std::ios::trunc | std::ios::binary);<br />
<br />
for( unsigned int i = 0; i < 256; i++ )<br />
{<br />
file << static_cast<unsigned char>(i) << i * 100;<br />
}<br />
toxcct wrote:
moreover, you declare it as a char, that means that it will take a maximum value of 127 (char range is [-128; 127])... declare it as unsigned char
This doesn't matter very much since the bits that are written to the stream are always the same. On the application side, where the raw value is interpreted, it makes a difference, but on the disk its doesn't. Example:
A byte can take 256 diffenrent values 0x00 to 0xFF. If I write a 128 to the disk, it writes 0x80. If I overflow a signed char with one (0x7F + 0x01) this becomes a negative value (0x80 == -0). So the same value gets written to the disk.
I agree with you using code like that is very bad practice, but my little mistake in the code example doesn't affect the program at all.
Blog[^]
|
|
|
|
|
Bob Stanneveld wrote:
0x80 == -0
no : -128. there is no -0, even in signed integers
however, i don't know why i*100 is written as a string...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
toxcct wrote:
no : -128. there is no -0, even in signed integers
Oh yeah, thats right. I should have studied more hard on that subject.. . I guess that I got confused with negative and positive infinity from doubles and floats...
Blog[^]
|
|
|
|
|
hi bob,
could you post a sample of the file generated please ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Hello,
Here is a part of the view:
00000000h: 00 30 01 31 30 30 02 32 30 30 03 33 30 30 04 34 ; .0.100.200.300.4
00000010h: 30 30 05 35 30 30 06 36 30 30 07 37 30 30 08 38 ; 00.500.600.700.8
00000020h: 30 30 09 39 30 30 0A 31 30 30 30 0B 31 31 30 30 ; 00.900.1000.1100
00000030h: 0C 31 32 30 30 0D 31 33 30 30 0E 31 34 30 30 0F ; .1200.1300.1400.
00000040h: 31 35 30 30 10 31 36 30 30 11 31 37 30 30 12 31 ; 1500.1600.1700.1
00000050h: 38 30 30 13 31 39 30 30 14 32 30 30 30 15 32 31 ; 800.1900.2000.21
00000060h: 30 30 16 32 32 30 30 17 32 33 30 30 18 32 34 30 ; 00.2200.2300.240
00000070h: 30 19 32 35 30 30 1A 32 36 30 30 1B 32 37 30 30 ; 0.2500.2600.2700
00000080h: 1C 32 38 30 30 1D 32 39 30 30 1E 33 30 30 30 1F ; .2800.2900.3000.
00000090h: 33 31 30 30 20 33 32 30 30 21 33 33 30 30 22 33 ; 3100 3200!3300"3
000000a0h: 34 30 30 23 33 35 30 30 24 33 36 30 30 25 33 37 ; 400#3500$3600%37
Blog[^]
|
|
|
|
|
against
file << static_cast<unsigned char>(i) << i * 100;<br /> , can you try the following and return the result here please ?
file << static_cast<unsigned char>(i) << (int)(i * 100);
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
I tried that a few times, no luck... The result is the same.
Blog[^]
|
|
|
|
|
Not sure why that happens, but for a workaround you could use ofstream's write() method. It seems to work the way you want:
<code>
unsigned int t = i*100;
file.write((const char*)&t, sizeof(unsigned int));
</code>
|
|
|
|
|
I currently use that method, but it's marked as deprecated in VS 2005.
Thanks for your reply
Blog[^]
|
|
|
|
|
I created two horizontal panes using CSplitterWnd. The top pane is from CView and the bottom pane from CScrollView. The splitter windows are static. My doubt is how to make the size of the panes to be fixed such that the user cannot resize the panes. Can anyone please help me out?
|
|
|
|
|
|
What's the easiest way to display a DIB when I have its handle which is a HBITMAP ? I found some functions which display it (the DIB) but for those I need some parameters which I don't have. I need a function, or member function of some class which would display it taking as argument the handle to the DIB (the HBITMAP), and the position .
|
|
|
|
|
Create a memory device context and then select the bitmap into it using SelectObject. You can then use BitBlt to copy it to the DC of your window to display it.
Have a look at the Windows GDI section of MSDN, that might help.
|
|
|
|
|
Well that's what I did ,basically . As you can see bellow I also have a function which makes my DIB from a DDB(the funnction is ConvertToDIB).I called this function before the SelectObject call .I don't know why I can't display the DIB (I see a white window when I try to open an image).
I transformed the DDB into DIB so I can modify it (for now I don't know how to modify it , but I just want to display it first ).Here's the code :
void CDoiView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
sizeTotal.cx = sizeTotal.cy = 0;
CleanUp();
CDoiDoc* pDoc = GetDocument();
CString strPath = pDoc->GetPathName();
if (!strPath.IsEmpty())
m_handlerToBMP = GetBitmapFromFile(strPath);
if (m_handlerToBMP){
GetBitmapDimensionEx(m_handlerToBMP, &sizeTotal);
}
SetScrollSizes(MM_TEXT, sizeTotal);
CDC* pDC=GetDC();
HDC hMemDC;
hMemDC=CreateCompatibleDC(pDC->GetSafeHdc());
if (hMemDC)
{
if (m_handlerToBMP){
bool aa;
if ( (aa=ConvertToDIB(m_handlerToBMP))==false )
{ AfxMessageBox("eroare ConvertToDIB");}
// select new bitmap into memory DC
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC, m_handlerToBMP);
//alocam memorie pentru tabloul ce contine informatia despre culoarea pixelilor
GetBitmapDimensionEx(m_handlerToBMP, &sizeTotal);
//transfer din memorie in fereastra
::BitBlt(pDC->GetSafeHdc(),0,0,sizeTotal.cx,sizeTotal.cy,hMemDC,0,0,SRCCOPY);
// select old bitmap back into memory DC and get handle to bitmap
SelectObject(hMemDC, hOldBitmap);
DeleteObject(hOldBitmap);
DeleteDC(hMemDC);
}
Invalidate();
UpdateWindow();
}
}
|
|
|
|
|
Hi
I am using a VC DLL in VB application and my DLL function is
void __stdcall ShowMainDialog( HWND hwnd,LPCTSTR lpStr_Title,
LPCTSTR lpStr_ExePath
LPCTSTR lpStr_ID, LPCTSTR lpStr_URL1,
LPCTSTR lpStr_URL2,
LPCTSTR lpStr_URL3,
LPCTSTR lpStr_URL4,
LPCTSTR lpStr_URL5,
LPCTSTR lpStr_URL6, int nDLG_ID))
{
//some code here
}
this dll is working perfectly in VC application but in VB application i am recving wrong arguments and order of parameters are not sequentially
e.g. hwnd recvd a junk long value
lpStr_URL1 is recving lpStr_ExePath
please tell me how can i solve this problem
Manoj Jangid
|
|
|
|
|
Hi all,
I am trying to load a image(GIF,JPEG or BMP) from file into a specific control in Win32 SDK.I have tried using LoadImage function.Is there any other method for doing this?Also i want to strech and compress the image according to window size.
Amruta
|
|
|
|
|
amrutajoshi wrote:
LoadImage
LoadImage only loads BMP files, it's has no support for JPEG and Gif images
amrutajoshi wrote:
there any other method for doing this
You can use IPictureDisp Interface to load Image File or
Could use Open Source Library like CXimage for loading different graphics format.
amrutajoshi wrote:
Also i want to strech and compress the image according to window size.
Method describe above give you BITAMP HANDLE To image and using BitBlt and StretchBlt, you can Stretch and compress the IMAGE on FlY!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Damned! You were faster than me!
|
|
|
|
|
Stlan wrote:
You were faster than me
Sorry, Next Time I will type Little Slow
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Yes please. But make also use of your left little finger only. Thanks in advance.
|
|
|
|
|
But i dont know anything about OLE.Is there any API for it?
|
|
|
|
|
HI Amruta,
Download this demo application from Microsoft,it's explain every thing about loading and displaying Images
LOADPIC.exe[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Hi,
Thanks Alok it's working.
Whether it is possible to stretch and compress such an image(means created using IPicture Interface) using StretchBlt function or I've to use any other functio?
|
|
|
|
|
amrutajoshi wrote:
using StretchBlt function or I've to use any other functio?
yes it's possible,look for IPicture::get_Handle Method
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|