我想在我的應用程序中使用氣球類型ui創建一些提示,讓用戶看到有關特定情況下需要採取的某些操作的信息,但吸取了一些代碼,我看着論壇。 我發現的氣球提示的一個例子是在以下網站http://www.tek-tips.com/viewthread.cfm?qid=1611641。我認爲它是在C++ Builder 2009 IDE中創建的,並且 試圖使用C builder 2010 IDE RS編譯它,但我無法獲得任何氣球提示。 首先,當我編譯時,它停止在如下行,如
GetClientRect(hWnd, &ti.rect);
然後我將其更改爲GetWindowRect的原因GetClientRect
不需要任何參數傳遞給此方法,雖然我改變了clint到窗口然後我終於跑了它......認爲它會顯示提示,但沒有任何工具提示。如何創建氣球提示?
另外我已經提供了我提供的鏈接代碼。
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
typedef struct{
unsigned long cbStruct;
PWChar pszTitle;
PWChar pszText;
int ttiIcon;
} tagEDITBALLOONTIP;
tagEDITBALLOONTIP *EDITHINT;
void __fastcall TForm1::ShowBalloonTip(TWinControl *Control,int Icon,char *Title,char *Text,TColor BackCL,TColor TextCL)
{
HWND hWndTip;
TOOLINFO ti;
HWND hWnd;
hWnd = Control->Handle;
hWndTip = CreateWindow(TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_NOPREFIX | TTS_BALLOON | TTS_ALWAYSTIP, 0, 0, 0, 0, hWnd, 0, HInstance, NULL);
if(hWndTip)
{
SetWindowPos(hWndTip, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
ti.cbSize = sizeof(ti);
ti.uFlags = TTF_CENTERTIP | TTF_TRANSPARENT | TTF_SUBCLASS;
ti.hwnd = hWnd;
ti.lpszText = Text;
GetClientRect(hWnd, &ti.rect); // the only problem is here
SendMessage(hWndTip, TTM_SETTIPBKCOLOR, BackCL, 0);
SendMessage(hWndTip, TTM_SETTIPTEXTCOLOR, TextCL, 0);
SendMessage(hWndTip, TTM_ADDTOOL, 1, Integer(&ti));
SendMessage(hWndTip, TTM_SETTITLE, Icon % 4, Integer(Title));
}
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ShowBalloonTip(Button1, 1, "ik0","Example on how to create Balloon Tips in C++ Builder", ColorBox1->Selected,ColorBox2->Selected);
}`
然後我問如何讓它在builder 2010中工作IDE? 我不知道爲什麼它通過使用Windows API funcs中像所提供2個PARAMS,當我編譯它在C++ Builder在Windows 7 2010 IDE它說沒有任何參數預計於2009年IDE工作...
刪除方法ShowBalloonTip之前的名稱空間並且它已經工作。我認爲如果它繼承自TCustomForm類'GetClientRect',它將改變它的方法簽名而不帶參數! :) –
您正嘗試從'TForm'方法中調用Win32 API'GetClientRect()'函數。由於'TForm'從'TControl'繼承了一個單獨的'GetClientRect()'方法,所以你必須告訴編譯器調用哪一個。如果要調用Win32 API函數而不是'TControl :: GetClientRect()'方法,請指定全局名稱空間,例如:':: GetClientRect(parameters here);'。 –
感謝您的澄清! –