全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:929
推到 Plurk!
推到 Facebook!

Icons and Bitmaps in the StatusBar

 
axsoft
版主


發表:681
回覆:1056
積分:969
註冊:2002-03-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-03-31 13:49:27 IP:61.218.xxx.xxx 未訂閱
Icons and Bitmaps in the StatusBar  -------------------------------------------------------------------------------- http://www.hobbypages.net/snip13.html It's pretty common now to see glyphs and icons in the status window. Microsoft has even animated them in IExplorer 4.0. While this example won't get that deep, I will show you the code two ways. Loading an icon and bitmap from a TImageList, and calling one from a resource. One of the things I found was after the function to load the image, you must invalidate the status window, so Windows will repaint it. Here's an example of displaying a glyph in the StatusBar, to match an active MenuItem that's been selected (Menu - Format / Paragraph / Align Left) The glyph is stored in an ImageList component, index[5]. If you use a tool bar that's optionally displayed, you could store a glyph for every one, in the same order, so you can remmember which ones to call on. Don't forget to define the glyph's int symbol in the form's header (int SBImage;)

 void __fastcall TForm1::AlignLeft1Click(TObject *Sender)
 {
 SBImage = 5; /* sets the glyph's int */
 StatusBar1->Invalidate(); /* causes the repaint */
 RichEdit1->Alignment = taLeftJustify;
}    When you look at the events for the StatusBar, you'll see one called OnDrawPanel. DBL-Click it and add: 
void __fastcall TForm1::StatusBar1DrawPanel(TStatusBar *StatusBar,
        TStatusPanel *Panel, const TRect &Rect)
{
ImageList1->Draw (StatusBar1->Canvas, Rect.Left  2, Rect.Top  2, SBImage);
}
Rect.Left 2 to get it away from the panel divider. Also, the status bar height defaults at 19, and I make it 20 to center the 16x16 glyphs). The SBImage is the last parameter. I worked on having several "ownerdrawn" panels, but I couldn't diferenciate between them.(Then I read my Oct 97 Cobb Journel and found out how!) You can also have more than one image per panel, even to DrawText between them, by making the ownerdrawn panel larger, and add to the Rect.Left integer. And you won't be using the SBImage int, but the actual ImageList.Index[#]

ImageList1->Draw(StatusBar1->Canvas, Rect.Left  2, Rect.Top  2, 5);
ImageList1->Draw(StatusBar1->Canvas, Rect.Left   22, Rect.Top  2, 3);
ImageList1->Draw(StatusBar1->Canvas, Rect.Left   42, Rect.Top  2, 2);
StatusBar1->Canvas->DrawText(Rect.Left   82, Rect.Top,
                        "This is an owner drawn line.");
Resizing icons is no fun. I'd rather put them into an imagelist, stretched to fit, then call it. Here's a call from an included resource file:

Graphics::TBitmap *MySBImage = new Graphics::TBitmap();
MySBImage = LoadFromResourceName(0, "MyBitmap");
StatusBar1->Canvas->Draw( Rect.Left   62, Rect.Top  2, MySBImage);
And that about wraps up the easy part. Doing it the API way takes about 3 pages of code.... Hoary for C Builder Ideas : You could set a document glyph for each open child window, and work with the mouse coordinates, using an OnMouseOver event to show a hint about the glyph's owner, and an OnClick event , whereby giving the StatusBar a hotspot, to bring that child window to the top. That sure would be easier knowing how many were open, and switching between them. Just a concept... 聯盟----Visita網站http://www.vista.org.tw ---[ 發問前請先找找舊文章 ]---
系統時間:2024-05-03 9:11:23
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!