Question

I'm trying to create some tips using balloon type ui in my app for letting users see information about certain actions need to be taken upon specific situations but sucks some codes I looked at a forum. One example of balloon tips I found is in the following site http://www.tek-tips.com/viewthread.cfm?qid=1611641. I think it was created in C++ Builder 2009 IDE and tried to compile it using C builder 2010 IDE RS but I couldn't get any balloon tips. Firstly, when I compiled, it's stopped at the following line such as
GetClientRect(hWnd, &ti.rect); then I changed it to GetWindowRect 'cause GetClientRect does not require any parameters to be passed to this method though I changed clint-to-window then I finally ran it... thought it would show tips but no any tooltips.

In addition I've presented the code which I've provided the link to it.

#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 );

}`

then I'm asking how to make it work in builder 2010 IDE??? I wonder why it's worked at 2009 IDE by using Windows API funcs like GetClientRect() that provided 2 params and when I compile it in C builder 2010 IDE in windows 7 it said no parameters expected...

Was it helpful?

Solution

You are trying to call the Win32 API GetClientRect() function from inside a TForm method. Since TForm inherits a separate GetClientRect() method from TControl, you have to tell the compiler which one to call. Specify the global namespace if you want to call the Win32 API function and not the TControl::GetClientRect() method, eg:

::GetClientRect(hWnd, &ti.rect);

On the other hand, since the HWND is coming from a TWinControl, you could (and should) use the control's ClientRect property instead:

ti.rect = Control->ClientRect;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top