【发布时间】:2012-10-31 10:44:09
【问题描述】:
我正在尝试在我的应用程序中使用气球类型 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-to-window然后我终于运行它...以为它会显示提示,但没有任何工具提示。
此外,我还展示了我提供了链接的代码。
#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 中工作???
我想知道为什么它在 2009 IDE 中通过使用提供 2 个参数的 Windows API 函数(如 GetClientRect())来工作,当我在 Windows 7 的 C builder 2010 IDE 中编译它时,它说没有预期的参数......
【问题讨论】:
-
在 ShowBalloonTip 方法之前删除了命名空间,它已经工作了。我认为如果它继承自 TCustomForm 类
GetClientRect会更改它的方法签名而没有参数! :) -
您正试图从
TForm方法内部调用 Win32 APIGetClientRect()函数。由于TForm从TControl继承了一个单独的GetClientRect()方法,因此您必须告诉编译器要调用哪个方法。如果要调用 Win32 API 函数而不是TControl::GetClientRect()方法,请指定全局命名空间,例如:::GetClientRect(parameters here);。
标签: c++builder c++builder-2010