|
Are you making the newly-created bitmap with CreateCompatibleBitmap() ? A memory DC starts out with a 1-bit bitmap in it, so maybe the bitmap you create is also ending up 1-bit?
--Mike--
"I'd rather you just give me a fish today, because even if you teach me how to fish, I won't do it. I'm lazy." -- Nish
Just released - 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Hey Mike, yes i was using that and yes they were 1-bit black & white bitmap copies.
i don't have the time to go digging through MSDN for all the steps it will take to copy the bitmap through a DC........sooooo....i found another way --
<br />
void CopyPicture(IPicture *pOrig, IPicture **pCopy)<br />
{<br />
HRESULT hr;<br />
<br />
*pCopy = NULL;<br />
IPicturePtr spOrig(pOrig);<br />
IPicturePtr spCopy;<br />
<br />
IPersistStreamPtr spPS(spOrig);<br />
<br />
IStreamPtr spStream;<br />
hr = CreateStreamOnHGlobal(NULL, TRUE, &spStream);<br />
<br />
hr = spPS->Save(spStream, FALSE);<br />
<br />
hr = OleCreatePictureIndirect(NULL, IID_IPicture, TRUE, (void**)&spCopy);<br />
<br />
LARGE_INTEGER li;<br />
li.QuadPart = 0;<br />
hr = spStream->Seek(li, STREAM_SEEK_SET, NULL);<br />
spPS = spCopy;<br />
hr = spPS->Load(spStream);<br />
<br />
hr = spCopy->QueryInterface(pCopy);<br />
}<br />
(i know i don't do anything with 'hr', it's mostly for when i step through the code in a debugger, it would be very strange for any of this to actually not work)
...this proved much easier to wrap my mind around in the short run, avoiding the complexities of GDI. This way even the palette is copied from one image to the other.
thanks,
nebbish
Smart, Sexy, Sane. Pick two.
|
|
|
|
|
If i do the folowing:
class CMyListBox : public CListBox
{
DrawItem(LPDRAWITEMSTRUCT lpDIS){ }
MeasureItem(LPMEASUREITEMSTRUCT lpMIS){}
};
I can use the ownerdraw mechanism to create the display and keep the drawing code encapsulated inside the CMyListBox object. However if I want to do thie in SDK i'm screwed...cuz WS_OWNERDRAW must be handled by the controls parent window procedure...
Is there any way I can get around this...?
I guess I could handle the parent WM_DRAWITEM and just re-direct the message back to the control...but this doesn't seem very elegant...
Suggestions...???
Thanx!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
|
Thanx Ravi!
I'll look into forsure...however I thought reflection was a MFC mechanism...?
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Yes it is - sorry I replied in a hurry!
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Sorry for my English , it is not my own English.
I write a program which draw and move a triangels. When i move i must a redraw area. I use double buffering. I use MDI.
OnDraw(CDC *pDC)
{
CClientDC lpDC(this);
lpPen = new CPen(PS_SOLID,1,RGB(0,0,0));
lpDC.SelectObject(lpPen);
CDC MemDC;
CBitmap MemBitmap;
MemDC.CreateCompatibleDC(pDC);
MemBitmap.CreateCompatibleBitmap(pDC,rWinRect.right,rWinRect.bottom);
CBitmap *pOldBitmap = MemDC.SelectObject(&MemBitmap);
// Draw all
lpDC.BitBlt (0,0,rWinRect.right,rWinRect.bottom,&MemDC,0,0,SRCCOPY);
MemDC.SelectObject(pOldBitmap);
}
And then i move a triangel i use for example
OnMouseMove(..)
{
// Do something
CClientDC lpDC(this);
OnDraw(&lpDC);
}
BUT AFTER A SEVERAL TIME PROGRAM CRASH WITH MESSAGE:
" A require resource was unavaliable"
PLEAZE HELP.
|
|
|
|
|
u need release ur dc;
code should be:
1. create a function:
DrawDC(CDC*pDC)
{
//put memory dc etc here
//do not use CClientDC lpDC(this);
//use pDC directly
}
2. OnMouseMove()
{
CDC pDC=GetDC();
DrawDC(pDC);
ReleaseDC(pDC);
}
3.OnDraw(CDC *pDC)
{
DrawDC(pDC);
}
includeh10
|
|
|
|
|
|
I am writing a program that provides the cost depending on weight. If the item weighs less than 16 ounces, the cost is $3.00. If more than 16 ounces the cost increases by .50 for each additinal 4 ounces. Here is what I have so far. It give me the 3 (not showing current format of $3.00) for weights <=16. But >16 shows a negative number.
Can some edit my code so it'll work? URGENT
#include <iostream.h>
#include <stdlib.h>
#include<stdio.h>
int main()
{
int wgt;
int x=0;
double cost;
int n = 4;
double i = 0.50;
double y;
cout <<"Enter the weight" <<endl;
cin="">> wgt;
if (wgt <16)
cost = 3.00;
cout <<"The cost is" <<cost <<endl;
="" {
="" if
="" (wgt="">16)
wgt = wgt +x;
x= n++;
y= i++;
cost = cost +y;
cout <<"Do you want to calculate the delivery";
cout <<" cost for another package?" <
|
|
|
|
|
sounds like homework, to me
so, here's a hint: if weight > 16, find out how much greater, then multiply the difference by $.50.
-c
"[it was..] one of those evenings when you feel that not only will there definitely be a revolution, but that the Association of Manufacturers will foot the bill."
-- Umberto Eco, Foucault's Pendulum
|
|
|
|
|
As I see it this will only work if the cost is $.50 per amount >16. I need to figure out that amount at $.50 per increments of 4. (4 for .50, 8 for 1.00, etc.)
How can I do this?
|
|
|
|
|
I might be that's Friday and I'm already into the brew or else you are code adds zero to 'x' then does the x=n++ .. etc... am i missing something here(mind you.. i've only glanced at your code so far)
---------------------------------------------
The greenest grass is NOT on the other side of the fence, its the grass you take care of. Have you watered your lawn lately?
|
|
|
|
|
Hi
In my current project the auto-completion suddenly does not work anymore. Usually if you type e.g.
CString foo<br />
foo.
a list of all available functions should appear, but that's not the case anymore. I already deleted the class-wizard file, but that didn't help
Any suggestions?
thanks in advance
modified 12-Sep-18 21:01pm.
|
|
|
|
|
try deleting the .ncb file, too
sometimes that helps
-c
"[it was..] one of those evenings when you feel that not only will there definitely be a revolution, but that the Association of Manufacturers will foot the bill."
-- Umberto Eco, Foucault's Pendulum
|
|
|
|
|
Thanks, this was the solution
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I want to insert my own warnings into code, to leave a fixed
record of things I have delayed doing. For example, I have
a function that converts a block of data into ASCII text, for
storage. However, the first quick and nasty implementation does
not get very good compression performance. So I want to insert
a line in the function saying something like:
#pragma message(__FILE__ " (" __LINE__ "): warning C1234: " \
"Need to improve the compression here.")
However I cann't get it to work right (__LINE__ is a number,
and #__LINE__ doesn't seem to work in this context.)
I seem to remember something here about this, but I couldn't find
it.
Any suggestions would be most helpful.
|
|
|
|
|
The # operator only works in a macro definition, not a #pragma , so do something like:
#define MAKESTR(x) #x
#pragma message "foo" MAKESTR(__LINE__) "bar"
--Mike--
"I'd rather you just give me a fish today, because even if you teach me how to fish, I won't do it. I'm lazy." -- Nish
Just released - 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
None of the suggestions offered worked, so I asked the
same question on comp.lang.c++.moderated, and they
pointed out that you need to double expand the __LINE__
macro for some subtle reasons. Anyways, for future
readers interested in how to do it, here is what I
now use:
#define STRINGIZE(x) #x
#define EVAL_STRINGIZE(x) STRINGIZE(x)
#define WARN(warning) message(__FILE__ "("EVAL_STRINGIZE(__LINE__)"): warning C1000: " warning)
Put these macros in a general project header included
everywhere (I guess you could even put them in stdafx.h
if you are so inclined, personally, all my projects have
a file called Project.h that is the first included in every
header.)
Then whenever you want to issue a warning during compile
time just use this:
#pragma WARN("Using bubble sort here, a better algorithm is required")
which will appear on your compiler output (and task list if
using VC .Net), which you can F4 through. When you fix the
error, just remove the pragma.
|
|
|
|
|
ASSERT(0 && "I have to improve this code");
|
|
|
|
|
I have a dialog based app that I want to start maximized but it just doesn't want to happen. I'm using the following code:
BOOL CToolTabsDlg::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style &= WS_MAXIMIZE;
return CDialog::PreCreateWindow(cs);
} Does this not work on dialogs or am I doing something completely wrong?
Something I just tried was putting a breakpoint on the cs.style statement just to see if the value changed and my program didn't even break. Obviously I'm doing something wrong but I'm not sure what it is.
Any help would be much appreciated.
- monrobot13
|
|
|
|
|
Add this to your OnInitDialog() :
PostMessage (WM_SYSCOMMAND, SC_MAXIMIZE);
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Thanks Ravi!
Is there a reason why the PreCreateWindow function wouldn't work? I'm wondering.
- monrobot13
|
|
|
|
|
use ::IsWindow(m_hWnd) to see if the window is OK in PreCreateWindow()
includeh10
|
|
|
|
|
Don't do it in precreate window.
write the following code in OnInitDialog function
BOOL MyDialog::OnInitInstance()
{
//Some code generated by the framework
ShowWindow(SW_MAXIMIZE);
return TRUE;
}
This will work.
|
|
|
|