[BCB] 攔截關機訊息
怎麼攔截關機中的狀況來結束應用程式
class TForm1 : public TForm
{
__published: // IDE-managed Components
private: // User declarations
public: // User declarations
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_QUERYENDSESSION,TMessage,WindowClose)
END_MESSAGE_MAP(TForm)
};
void __fastcall TForm1::WindowClose(TMessage & Message)
{
// do your code here
Message.Result = WM_QUERYENDSESSION;
}
[BCB] 如何在 ListBox 或是 ComboBox 加入圖示
在 ListBox 或是 ComboBox 加入圖示
需要有 TImageList 和 TListBox 或是 TComboBox 兩個元件
可以在每個選項前畫出小圖示
LB1->Style = lbOwnerDrawVariable;
LB1->ItemHeight = 17;
void __fastcall TForm1::LB1DrawItem(TWinControl *Control, int Index,
TRect &Rect, TOwnerDrawState State)
{
TIcon *t;
t = new TIcon;
ImageList1->GetIcon(0, t);
LB1->Canvas->FillRect(Rect);
LB1->Canvas->Draw(Rect.Left + 15, Rect.Top, t);
LB1->Canvas->TextOut(Rect.Left + t->Width /2 + 16 , Rect.Top + 2, LB1->Items->Strings[Index]);
delete t;
}
[BCB] CheckAppHandle
檢查記憶體裡面是否有同一隻程式在執行
/*************************************************************************/
/* 檢查是否有同一隻程式在跑 */
/*************************************************************************/
Application->Title = "MyName";
HANDLE PrevInstHandle;
HANDLE Mutex = OpenMutex(SYNCHRONIZE,false,Application->Title.c_str());
if (Mutex != NULL)
{
String AppTitle=Application->Title;
SetWindowText(Application->Handle,NULL);
PrevInstHandle = FindWindow("TApplication", AppTitle.c_str());
if (PrevInstHandle != 0)
{
if (IsIconic(PrevInstHandle))
ShowWindow(PrevInstHandle, SW_RESTORE);
else
BringWindowToTop(PrevInstHandle);
SetForegroundWindow(PrevInstHandle);
}
Application->ShowMainForm = false;
Application->Terminate();
}
else
CreateMutex(NULL, false, Application->Title.c_str());
[BCB] POPUP
將目標視窗移到最頂端
void Popup(void *Formhandle)
{
if(IsIconic(Formhandle/*Application->Handle*/)) // 檢查是否最小化
{
ShowWindow(Formhandle/*Application->Handle*/, SW_RESTORE); // 跳起來
}
else
{
// 放到最上層
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, 0, SPIF_SENDCHANGE);
// 取得焦點
SetForegroundWindow(Formhandle);
}
}
[BCB] EasyXml
簡單的 XML Parse For BCB and DELPHI
支援中文
http://windtop.yzu.edu.tw/~visor/bcb/pkg/xmlparser.zip
//For example:
//-- Load the input xml file..
//XmlScanner1->LoadFromFile("c://myfile.xml");
XmlScanner1->LoadFromBuffer(xml.c_str());
//-- Init the scanning.
XmlScanner1->XmlParser->StartScan();
//-- Loop thru the file for each item.
AnsiString tag,cdata;
while (XmlScanner1->XmlParser->Scan())
{
switch (XmlScanner1->XmlParser->CurPartType)
{
case ptStartTag : //-- Got Start tag.
tag = XmlScanner1->XmlParser->CurName;
break;
case ptContent : //-- Got content.
cdata = XmlScanner1->XmlParser->CurContent;
break;
case ptEndTag:
break;
//-- Add other cases here as required..
default :
break;
}
}
March 08, 2003
[BCB] TBase64
http://140.138.2.234/~visor/bcb/class/Class.zip
TBase64Encode
TBase64Decode
可以對檔案,記憶體區塊或文字編碼成 base64 string
也可以反編碼成檔案,記憶體區塊或文字