api的一个hint,看不懂来请教大家。 - C++ Builder / Windows SDK/API
在坛子里乱窜,看到Y___Y(一叶障目) 回答的一个帖子。仔细研究了下。有很多还是没看懂,API我知道的太少了。大家帮我解释一下吧。
原帖地址:
http://community.csdn.net/Expert/TopicView3.asp?id=5149893
代码内容:
Unit1.h
//---------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------
class TForm1 : public TForm
{
__published:// IDE-managed Components
TButton *Button1;
TButton *ButtonClose;
void __fastcall FormCreate(TObject *Sender);
private:// User declarations
public:// User declarations
__fastcall TForm1(TComponent* Owner);
int Flags;
void ToolTip( HWND , wchar_t* wcText, TColor clBackCol,TColor clTextCol);
};
//---------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------
#endif
//---------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h "
//---------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm "
TForm1 *Form1;
//---------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------
void TForm1::ToolTip( HWND hWnd, wchar_t* wcText, TColor clBackCol,
TColor clTextCol )
{
HWND hWndToolTip;
TOOLINFOW ti;
hWndToolTip = CreateWindow( TOOLTIPS_CLASS,
NULL,
WS_POPUP | TTS_NOPREFIX | 0x40 |
TTS_ALWAYSTIP,
0, 0, 0, 0,
hWnd,
0,
HInstance,
NULL );
if( hWndToolTip != 0 )
{
SetWindowPos( hWndToolTip,
HWND_TOPMOST,
0, 0, 0, 0,
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE );
memset(&ti,0,sizeof(ti));
ti.cbSize = sizeof(ti);
ti.uFlags = Flags;
ti.hwnd = hWnd;
ti.lpszText = wcText;
ti.rect = Form1-> GetClientRect();
SendMessage( hWndToolTip, TTM_ADDTOOLW, 0, (LPARAM)&ti );
}
}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Flags = TTF_TRANSPARENT | TTF_SUBCLASS;
ToolTip( Button1-> Handle , L "Button1 ", clWhite, clBlack );
ToolTip( ButtonClose-> Handle , L "Program exit! ", clWhite, clBlack );
}
//---------------------------------------
主要是ToolTip这个函数中的程序。
我想问几个问题
如果我想更改HINT的内容,如何更改。
比如说:如果我这样写:
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Flags = TTF_TRANSPARENT | TTF_SUBCLASS;
ToolTip( Button1-> Handle , L "Button1 ", clWhite, clBlack );
ToolTip( Button1-> Handle , L "Program exit! ", clWhite, clBlack );
}
这样的话,当我显示Hint时会出现2个,一个是 "Button1 "一个是 "Program exit! "是不是应该先判断句柄若存在DestoryWindow()后在 CreateWindow()
.有没有更好的方法。如果我想销毁这个hint不让其显示。怎么能实现呢?
[解决办法]
SendMessage( hWndToolTip, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti );