|
how can i display the bitmap on ListView using CreateBitmap function?
<br />
void CThumbBmpView::OnPaint()<br />
{<br />
CPaintDC dc(this);
<br />
<br />
CRect r;<br />
GetClientRect(&r);<br />
<br />
CXTPBufferDC memDC(dc, r);<br />
memDC.FillSolidRect(r, (RGB(255,255,255)));<br />
<br />
OnPrepareDC(&memDC);<br />
OnDraw(&memDC);<br />
<br />
<br />
<br />
}<br />
<br />
<br />
<br />
void CThumbBmpView::OnDraw(CDC* pDC)<br />
{<br />
<br />
HANDLE hFile;<br />
DWORD dwNumberOfBytesToRead;<br />
DWORD dwNumberOfBytesRead;<br />
<br />
<br />
<br />
hFile = CreateFile( "D:\\preview.bmp",<br />
GENERIC_READ, <br />
FILE_SHARE_READ,<br />
NULL,<br />
OPEN_EXISTING,<br />
FILE_ATTRIBUTE_NORMAL,<br />
NULL );<br />
<br />
if( hFile == INVALID_HANDLE_VALUE )<br />
{ <br />
MessageBox( "Invalid Handle", "ERROR", MB_ICONERROR);<br />
<br />
}<br />
else<br />
{<br />
BYTE *Buffer;<br />
DWORD p=SetFilePointer( hFile, 0x000, NULL, FILE_BEGIN );<br />
<br />
Buffer = new BYTE [2363392+1];<br />
<br />
BOOL bResult = ReadFile( hFile,<br />
Buffer,<br />
2363392,<br />
&dwNumberOfBytesRead,
NULL<br />
);<br />
<br />
if(!bResult)<br />
MessageBox("Error");<br />
<br />
<br />
<br />
<br />
<br />
if(!bitmap.CreateBitmap(1000,500,1,32,Buffer))<br />
MessageBox("cant Create Bitmap");<br />
<br />
}<br />
CDC dcCompatible;<br />
if ( !dcCompatible.CreateCompatibleDC( pDC ) )<br />
{<br />
return;<br />
}<br />
CBitmap* pOld = dcCompatible.SelectObject( &bitmap );<br />
<br />
BITMAP bmInfo;<br />
if ( bitmap.GetObject( sizeof( bmInfo ), &bmInfo ) != 0 )<br />
{<br />
pDC->BitBlt( 0,0, bmInfo.bmWidth, bmInfo.bmHeight, &dcCompatible, 0,0, SRCCOPY );<br />
<br />
}<br />
<br />
dcCompatible.SelectObject( pOld );<br />
<br />
}<br />
<br />
<br />
Regards,
Srinivas
|
|
|
|
|
vasu_sri wrote: CDC dcCompatible;
if ( !dcCompatible.CreateCompatibleDC( pDC ) )
this will not work. Yous should pass the pointer of original device context. it can be modified as follows
CClientDc dc(this)<br />
CDC dcCompatible;<br />
if ( !dcCompatible.CreateCompatibleDC( &dc ) )
nave
|
|
|
|
|
I don't think this is the problem. Actually I don't think it is a problem.
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.
|
|
|
|
|
I bet itwill not work unless you change it.
nave
|
|
|
|
|
And why?
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.
|
|
|
|
|
|
Good (though empirical) point. I will try...
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.
|
|
|
|
|
In addition to the above post, you must bitblit the content from memdc to dc in the CThumbBmpView::OnPaint()function after the statement OnDraw(&memDC);
nave
|
|
|
|
|
I agree only on this (see my reply above). Additionally, the OP have to first select the bitmap inside the memDC. To summarize, the OP has to:
(1) Create a compatible (memory) DC
(2) Select the bitmap inside the memory DC.
(3) Preform Perform BitBlt from the MemDC to the actual one.
Hope that helps
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.
|
|
|
|
|
CPallini wrote: (1) Create a compatible (memory) DC
(2) Select the bitmap inside the memory DC.
I think the CXTPBufferDC will be hadling this.
nave
|
|
|
|
|
i did all what u asked me to do. i converted CDC to CClientDc. But still it doesn't work. i am doing this for the first time and so can u please explain me a little more clearly?? or can u give me any related link that can help me???
Regards,
Srinivas
|
|
|
|
|
if(!bitmap.CreateBitmap(1000,500,1,32,Buffer))
The bitmap file not only contains the pixel data information. It also contain a file header. But the CreateBitmap funtion only need bufffer information. So you must remove the header information from the buffer before passing it to CreateBitmap function.
But still I dont understand why you directly read the bitmap. My suggestion is to use the LoadImage() instead of this.
nave
|
|
|
|
|
Naveen R wrote: But still I dont understand why you directly read the bitmap. My suggestion is to use the LoadImage() instead of this.
its because i don't have the File name or the file path with me. i just have the addresses of the starting sector and ending sector of the image file to work with. i am then reading the data between those sectors (which is nothing but the data of the image file) into a buffer. now i want to show the preview of that image by just using the data in the buffer before storing it as a file. i am still not able to succeed in what i am trying to do.
Regards,
Srinivas
|
|
|
|
|
|
Can anybody tell me how to place a seprator in toolbar
example..
if i m making 2 buttons in serial n then i want a line to be displayed and then after that 2 more buttons...
How to make this line in between buttons
thanxs in advance
|
|
|
|
|
wrote: Can anybody tell me how to place a seprator in toolbar
If you are using the resource editor then slightly drag a button to the right then leave. You will see a separator.
Else through code use
TBSTYLE_SEP .
|
|
|
|
|
Got good help last week for changing text of listCtrl-header and I thougth, my problem is solved. I've the following code:
void koarkstewView::alterheadercontent()<br />
{<br />
LVCOLUMN lvc;<br />
CString titel;<br />
CListCtrl &listCtrl = GetListCtrl();<br />
koarkstewDoc* pDoc = GetDocument();<br />
<br />
karkst *karkstanz;<br />
karkstanz = pDoc->karkstanz;<br />
pDoc->SetTitle("KAR->KST");<br />
int i = 3;<br />
if (karkstanz->wdfirst())<br />
do<br />
{<br />
i++;<br />
titel = karkstanz->wdgetkarnr() + "\n";<br />
titel = titel + gettitel(0, karkstanz->wdgetdatenart(), karkstanz->wdgetvon(), karkstanz->wdgetbis());<br />
listCtrl.GetColumn(i, &lvc);<br />
lvc.pszText = titel.GetBuffer(0);<br />
titel.ReleaseBuffer(); <br />
listCtrl.SetColumn(i, &lvc);<br />
}<br />
while(karkstanz->wdnext());<br />
<br />
}
Works fine - but only in debug-mode!! In release-mode, the text doesn't change
But how to debug the code, if it work's in debug-mode
Any proposals?? Thanks, Gerhard
|
|
|
|
|
ensger wrote: listCtrl.GetColumn(i, &lvc);
lvc.pszText = titel.GetBuffer(0);
titel.ReleaseBuffer();
listCtrl.SetColumn(i, &lvc);
Modify this to,
LVCOLUMN lvc= {0};
listCtrl.GetColumn(i, &lvc);
lvc.mask = LVCF_TEXT ;
lvc.pszText = titel.GetBuffer(0);
titel.ReleaseBuffer();
listCtrl.SetColumn(i, &lvc);
Read this[^] article for better understanding of difference betn release and debug configuration.
|
|
|
|
|
Many thanks, it work's. And thank's for the link. I'll have to read cause I didn't recognice till yet, that programs that work in debug-mode maybe will not work in release-mode.
|
|
|
|
|
ensger wrote: didn't recognice till yet, that programs that work in debug-mode maybe will not work in release-mode
On broader level, in debug mode, lots of things would be taken care of. One of them is variable initialization.
In your case though, you did miss to mention mask. And its always good practice to initialize variables.
|
|
|
|
|
ensger wrote: lvc.pszText = titel.GetBuffer(0);
Why are you calling GetBuffer() unnecessarily? I don't see that you are modifying titel .
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Because
lvc.pszText = titel;
results in an error-message like 'no operator defined, that accepts a right-sided operator of type 'class CString''. I didn't even know the existence of 'GetBuffer()' till last week - but it works
|
|
|
|
|
ensger wrote: ...but it works
Of course it does, but GetBuffer() exposes the underlying char* object to possible (unwanted) changes. Try:
lvc.pszText = (LPTSTR) ((LPCTSTR) titel); Now titel cannot be accidentally changed.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I tried and it works. And the sense of this statement is even more obvious for me.
So, many thanks
|
|
|
|
|
Hi all,
Again i m having a problem related to multi threading....
Actually now what i m trying to do is i want to start a thread within a timer that is that thread shold run in particular time intervals...
this i have done it n its workin fi9...
Now my problem is if i have to run this timer for multiple processes like
one timer for that thread s'ld run within 4s sec n other in 5sec like this.......
can anybody plz help me in this.........
thanxs in advance
|
|
|
|