|
fantasy1215 wrote: How to show a bitmap in a CStatic control?
Why dont you use a Picture control?
|
|
|
|
|
Use SetBitmap() method of static control.
|
|
|
|
|
I just want to try GDI, Please tell me what wrong with my code. When I first show the CAboutDlg I see the bitmap show as a flash in the right place.
|
|
|
|
|
fantasy1215 wrote: Please tell me what wrong with my code
You're drawing on the dialog window.
The static control, being higher in the z-order, is then drawn on top of your drawing.
You need to subclass the static control and paint on it instead.
With MFC, simply derive a class from CStatic and handle WM_PAINT just like you did on
the dialog, except you don't have to convert coordinates.
In the dialog class, use an object of your CStatic-derived class instead of a CStatic object.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery
Thanks very much for reply. You just unlock my mind. Before you give me the answer, I am so confused.
BTW, Except for subclassing a CStatic class, Can I draw the bitmap in the CStatic control just in the CAboutDlg class? And how?
|
|
|
|
|
fantasy1215 wrote: Can I draw the bitmap in the CStatic control just in the CAboutDlg class? And how?
You can, but there's a slight problem.
Getting a dc to the client or window area of the control is no problem.
That makes drawing simple.
The problem is when to draw.
You can draw any time you want to, but you also need to draw in response to WM_PAINT,
to refresh windows overdrawn in instances like when the user drags another window over
the top of yours then moves it away.
From the dialog (parent) window's WM_PAINT handler, there's no reliable way I know of to
know when the child windows are finished drawing themselves, at which time it would be safe
to draw on top of them.
MFC does subclassing for you, and makes handling the messages consistent regardless of
window/control class, so it's definitely IMO the easier way to go.
Besides, painting from the window class itself instead of from a window's parent class
just makes for a better object-oriented implementation.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Its better to use a picture control, but I would like to know how do you compiled the code,
fantasy1215 wrote: this->WindowToScreen(&rcWnd);
Is This function available.
fantasy1215 wrote: m_bitmap.SelectObject(&bm);
Is this compilable.
Part from these compilation errors, "m_ctlPic.GetWindowRect(&rcWnd);" already the screen coordinate and drawing on to Dialog DC which expects a client dc of dialog.
|
|
|
|
|
i have a static control in my application. when i click on a particular position i want to show the value in a static text. i need to show this on the static control itself. like (x1,y1).
take for example in excel when u make a graph and point to a location it reads out the value in a box. i want to do it the same way. what needs to be done for this?
|
|
|
|
|
WM_LBUTTONDOWN or OnLButtonDown will give you the mouse position either in lParam or a CPoint for MFC (check msdn).
Not sure what you're asking....
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Chandrasekharanp wrote: take for example in excel when u make a graph and point to a location it reads out the value in a box. i want to do it the same way. what needs to be done for this?
Handle click event on Mouse and GetCursorPos will return you exact cursor position with respect with screen!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
Hello,
can I play a piece of sound using DSound, while a stream file (.mp3 or .avi) plays with DShow?
with regards,
mwolf122
|
|
|
|
|
Yes. As long as nobody takes control of the primary buffer,
all secondary DirectSound buffers should be mixed by the
system.
Works fine on XP and Vista I know for sure.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I want my COleClientItem derived items to draw with the DVASPECT_OPAQUE flag but COleClientItem::Draw doesn't support the DVASPECT2 enumeration.
I think I need to check if my COleClientItem supports IViewObject2 and then call IViewObject2::Draw, but I don't really know how to go about it.
Can anyone help me?
Is this even the correct method?
Cheers
|
|
|
|
|
I have two questions. The first one is regarding the conversion from int to string. I can successfully convert a numeric string to int with the follwing code (particularly useful if you need to make mathematical operations on the numeric values contained in a string):
string VALUE_AS_STRING = "1234";
int VALUE_AS_INT = atof (VALUE_AS_STRING.c_str());
cout << "The numeric value of the string is: " << VALUE_AS_INT;
...but I am not able to do the opposite, eg convert an int into a string. Any help please?
Second question :
How come the condition below results in an error? How should it rather be written?
char CHARACTER = "1";
if (CHARACTER == "1") {cout << "True";}
Many thanks
|
|
|
|
|
J_E_D_I wrote: int VALUE_AS_INT = atof (VALUE_AS_STRING.c_str());
Should use atoi ().
J_E_D_I wrote: I am not able to do the opposite, eg convert an int into a string.
sprintf ()
J_E_D_I wrote: char CHARACTER = "1";
if (CHARACTER == "1") {cout << "True";}
Use single quote.
if(character == 'a') {
cout << "It is a";
}
Maxwell Chen
|
|
|
|
|
J_E_D_I wrote: but I am not able to do the opposite, eg convert an int into a string. Any help please?
Another method in addition to Maxwell's sprintf()...
#include <sstream>
...
int SomeInt = 5;
std::ostringstream NumericStringStream;
NumericStringStream << SomeInt;
std::string NumericString = NumericStringStream.str();
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
itoa
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
For Question One :-
would wsprintf or CString::format is of any use!
J_E_D_I wrote: Second question :
How come the condition below results in an error? How should it rather be written?
char CHARACTER = "1";
if (CHARACTER == "1") {cout << "True";}
use ' instead of "
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
I have a 32bit int that I'm trying to stuff into an array of bytes.
Is it okay to do this?
CharArray = new unsigned char [4];
CharArray = (unsigned char *)&IntegerValue
ByteArray[Length-4] = CharArray[3]
ByteArray[Length-3] = CharArray[2]
ByteArray[Length-2] = CharArray[1]
ByteArray[Length-1] = CharArray[0]
|
|
|
|
|
Yes it's ok (to cast from int * to unsigned char *).
Also is that a typo? You overwrite the allocated CharArray...
should that have been:
ByteArray = new unsigned char [Length];
CharArray = (unsigned char *)&IntegerValue
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
No, that's not a typo.
The ByteArray is actually a different array type, but is still an array of unsigned char.
If it is okay to get the IntegerValue into the unsigned char[4] then I'm okay.
so...
CharArray = new Unsigned Char [4];
CharArray = (unsigned char*)&IntegerValue ;
That should still be fine. The 4 Unsigned Char bytes will then be populated with the bytes from the integer.
|
|
|
|
|
ChemmieBro wrote: No, that's not a typo
In that case you have a problem ...
CharArray = new unsigned char [4];
CharArray = (unsigned char *)&IntegerValue //<--- overwrites the pointer allocated above!!
The storage has already been allocated - it is the 4 bytes used by the
IntegerValue variable.
You only need the second line above...
CharArray = (unsigned char *)&IntegerValue;
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I see that, now.
Thank you. I just needed a quick answer and got it.
I'm just re-using some code and they had done this same thing using an integer and a two shorts. I figured if it worked that way, it would work using an integer and four unsigned chars. Now I'll have to change the old stuff, too.
Thanks again.
|
|
|
|
|
Have you considered using a union ?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: using a union
I like your solution!
Maxwell Chen
|
|
|
|