|
There are two methods,
Use CListCtrl instead of CListBox and do the following
Using LoadImage API (or CImage), you can load images from file. Add the Images to CImageList class using CImageList:Add interface and Set the image list using CListCtrl::SetImageList function.
Otherwise, create an owner-drawn CListBox and keep the list of Images in your class (You can use the previous methods mentioned to load images) and in DrawItem function, draw it inside each cell's rect.
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Hi,
Thanks for your replay .I am using LoadImage API. In our project we having images in one directory.Where should I place Image files. Will it load image from anywhere in the disk?
Rekha.
|
|
|
|
|
You can load from anywhere from a valid path. It's better to keep images in a separate folder under the executable's current directory.
Here's the sample code to load bmp using LoadImage API[^]
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
thanks for your replay.I am able to print images in ListBox
Rekha.
|
|
|
|
|
See Image List Box[^].
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
I have a created a SDI Application and 4 toolbar buttons are there, in that one button is PAUSE/RESUME button(Like a Toggle button). So when clikced PAUSE button means I have to change to RESUME image and Vice-versa. I have done it by using CImagList::Replace(index, IC_PASUSE).
Now i have created the modeless dialog and it contains one CButton. Her my aim to change the image of the Toolbar PAUSE/RESUEME button when i cliked that CButton in the Modeless dialog. For that I wrote same code that is CImageList::Replace(), But when i cliked that CButton in the modeless dialog , the image is not changing in the Toolbar PAUSE/RESUME button, but when i moves the mouse on the ToolBar PASU/RESUME button, that image is replacing perfectly.
provide me the solution.
|
|
|
|
|
You need to inform the main frame (or something) that the state of that command button has changed - maybe this page[^] can help?
You should probably not change the image list directly, instead send a message to the main frame telling it about the state change. Then it can manage the change to its UI.
|
|
|
|
|
CRect rText( 0, 0, 0, 0 );
pDC->;DrawText( str, rText, DT_CENTER |DT_CALCRECT |DT_WORDBREAK);
szText = rText.Size();
in rText i dnt get values at all they ramain same as 0 0 0 0 ny body help
thankz
|
|
|
|
|
(I hope str is not empty... )
_T("No name") wrote: pDC->;DrawText( str, rText, DT_CENTER |DT_CALCRECT |DT_WORDBREAK);
Shouldn't be
pDC->DrawText( str, &rText, DT_CENTER |DT_CALCRECT |DT_WORDBREAK);
?
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]
|
|
|
|
|
no that i have checked already string is nt empty
|
|
|
|
|
Have you added the address of operator to your function call?
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]
|
|
|
|
|
Isn't the problem that you are telling DrawText to break the lines with DT_WORDBREAK and you specify an empty rectangle, so how can DrawText know where to break the lines if it does not know the original width?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
thanks it helped
|
|
|
|
|
Hai !
I have developed an application which downloads a binary file to a device.
If i download the binary at a baud rate of 115200, i can see all controls of my dialog box, but when i download at lower baud rates such as 9600 and press a mouse button or a key from key board while download is under process, all my controls like buttons, radio buttons disapppear only the frame of my dialog is visible. when download is compplete, i can again see all the controls.
why do these controls dissappear when a key is pressed during download at lower baud rates?
Is there any way to overcome this issue?
Thanks !
|
|
|
|
|
I guess by 'disappearing' you mean that your dialog becomes unresponsive (and probably not repainted, that's why your control 'disapear'). This is probably because your are downloading in the main thread, which completely blocks your application while you are processing the download (and your application is not able to process windows messages which makes it unresponsive). To solve your problem, one option would be to to your download stuff in a separate worker thread.
I suggest this article[^] to get started.
|
|
|
|
|
Sorry, by disappearing means the dialog box turns white in colour except at the borders, the application must be non resposive while downloading, but the controls present like progress bar, buttons , radio buttons must be visible.
|
|
|
|
|
Possibly you should use a worker thread for the serial communication, leaving the main thread free of updating the GUI .
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]
|
|
|
|
|
In general, it is bad design to have your dialog not responding to windows messages. Instead what you could do when starting the download is to show a modal dialog (with eventually a progress control and a cancel button) that disappear when the download is complete (butyou still have to put your download code in a separate worker thread). This way you still keep a responsive UI and avoid that the user presses on all the buttons .
|
|
|
|
|
Hi All,
I have a query related to virtual methods and access specifiers in C++ class. I have a two classes and their definition is as shown below
class Base
{
public:
virtual void PrintMethod()
{
cout << "Base class method called";
}
};
class Derived : public Base
{
private:
virtual void PrintMethod()
{
cout << "Derived class method called";
}
};
in main method
int main()
{
Derived der;
Base *ptr = &der;
ptr->PrintMethod(); ------------ (1)
// der.PrintMethod(); ------------ (2)
return 0;
}
When I execute the program the output I get is "Derived class method called" and this confused me a bit. I could not figure out properly why the derived class method was called when it is private in class Derived?
My guess is that the public function in class Base is inherited in Derived class and when the call was made the through the pointer the linker could only find the private definition of the function PrintMethod and hence it called it through the pointer which is actually pointing to the Derived class object.
If I try to call the function through the derived class object (as shown in 2), I get compilation error saying the private method is not accessible which is true.
So overall I was not satisfied with the reasoning I arrived at for the derived class method being called.
Can someone give me more insight into what actually is happening here?
Thanks and Regards
|
|
|
|
|
When you have a virtual function, the compiler will create a virtual table (also called vtable) in your class which contains the address of all virtual functions (in this case, the address of the Derived::PrintMethod). At that point, it doesn't make any difference if the derived virtual function is private or not. You are calling the function on a base pointer, and there's no way for the compiler to know if the derived function is public or not (the compiler has no way to know what is the real type of your pointer at compile time). The compiler just access the virtual table and redirect the call to the derived method.
|
|
|
|
|
The compiler may do just a static check on your function calls, on the other hand, polymorphism is a dynamic feature of the language.
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]
|
|
|
|
|
|
Dear All,
I have an issue with floating point precision with Visual Studio 2005 (2008 as well)
See the sample code.
const float f = 0.2f * 3;
CString str;
str.Format(_T( "%f"), f );
When you check the watch window, the variable will be having value 0.60000002(I expected 0.6). To confirm this again, I tried running with WinDBG, it has given a value 0.6000000238 in it's watch window
I doubt this may affect my calculation which should be very precise. I tried different floating point models using /fp compiler option. But always it has the same output. But the formatted string below gives 0.600000 as the result.
What could be the reason for this issue? Any solutions?
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
I don't understand where is your problem exactly: only with the precision or when formating the string ?
For the precision problem, you can use a double instead of a float, you'll gain much more precision.
For the formating, you can supply the number of decimal points you want to show in the format string (just add a number before the 'f').
|
|
|
|
|
OK
try this code. then things will be more clear.
float f = 0.2f 0.6f;
f -= 0.2f;
f -= 0.2f;
f -= 0.2f;
if( f == 0.0f )
{
}
In this case, after subtracting 0.2 three times, the value should reach to 0.0f. But it's fails. because of the trailing additional digits in the floating point representation. The same case exists for double type as well.
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
modified on Tuesday, February 3, 2009 6:59 AM
|
|
|
|