<

Main
  Main/About
  Recent news
  Rott info
  WinRott info
  GlRott info
  Game Info/FAQs
  Forum
  Links
  Interviews
  C Programming
  Jonathan's page
  Send News
  Contact Info


Downloads
  Rott
  WinRott
  GlRott
  Levels
  Utilities
  Graphics
  Sounds


Google Ad's



C and C++ programming


Here is the code of the CoolTip Class.


In the 'Winmain' section you create a thread like this

hTimerThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)TIM_TimerProc,NULL,0,&iID);


//here is the global stuffs
HWND hWndtool;
HFONT hfonttool;
HDC hdctooltip;
HPEN hBluePen;
int iToolwndIsShown = 0;
void TIM_CreateToolwnd(int id);



long WINAPI TIM_TimerProc(long lParam)
{
MSG msg;
// message structure
long TimerID_1 = 0,TimerID_2 = 0;
int is, iOnButton = -1;



//create the tooltip font
hfonttool = CreateFont(14, 0, 0, 0, FW_NORMAL, 0, 0, 0, 0, 0, 0, 0, DEFAULT_PITCH , "MS Sans Serif");
hWndtool = CreateWindowEx (WS_EX_PALETTEWINDOW,
"STATIC", "editor tooltip window",
WS_POPUP|SS_OWNERDRAW|WS_CHILD |WS_CLIPSIBLINGS,
0 ,0, 0, 0,
hMainWnd, NULL, hInst, NULL);
hdctooltip = GetDC(hWndtool);
SelectObject(hdctooltip, hfonttool);
hBluePen = CreatePen(PS_SOLID, 1, crDARKBLUE);
TimerID_1 = SetTimer(0, 0, 200, (TIMERPROC)NULL);

while (GetMessage(&msg,
// message structure
NULL,
// handle to window to receive the message
NULL,
// lowest message to examine
NULL))
// highest message to examine
{

// Post WM_TIMER messages to the hwndTimer procedure.
if (msg.message == WM_TIMER)
{ if (iToolwndIsShown == 0){
//toolwindow is not shown
if (msg.wParam == TimerID_1) {

//do we have the curson on a toolbutton
for (is=0;is<16;is++){
if (WIN_IsCursorInRect (ToolbarInfo[is].rc)==TRUE){

//cursor is on but, set the 1.5 sec timer
if (is != iOnButton){
TimerID_2 = SetTimer(0, 0, 1000, (TIMERPROC)NULL);
iOnButton = is;
break;
}
}
}
}else if (msg.wParam == TimerID_2) {

//is cursor stil on button
if (WIN_IsCursorInRect (ToolbarInfo[iOnButton].rc)==TRUE){
Extra:
iToolwndIsShown = 1;
TIM_CreateToolwnd(iOnButton);
}else
KillTimer(NULL,TimerID_2);
}
}else{

//toolwindow is shown

//is cursor stil on button
if (WIN_IsCursorInRect (ToolbarInfo[iOnButton].rc)==FALSE){

//test if we stil are on another button

//that is, if we just move cursor right or left
for (is=0;is<16;is++){
if (WIN_IsCursorInRect (ToolbarInfo[is].rc)==TRUE){
iOnButton = is;
goto Extra;
}
}
iToolwndIsShown = 0;
iOnButton = -1;
KillTimer(NULL,TimerID_2);
ShowWindow(hWndtool,SW_HIDE);
}
}
}

TranslateMessage(&msg);
// translates virtual-key codes
DispatchMessage(&msg);
// dispatches message to window
}

}



void TIM_CreateToolwnd(int id)
{
POINT pt;
HDC hdc;
HICON hIcon;
RECT rc,rcText;


HWND h = GetForegroundWindow();
if ((h!=hMainWnd)&&(h!=hWndtool)){
return;
}
memset(&rcText,0,sizeof(rcText));
hIcon = ImageList_GetIcon(menu_himl,ToolbarInfo[id].iBitmap,ILD_TRANSPARENT);


// compute size of text: use DrawText with DT_CALCRECT
DrawText(hdctooltip,ToolbarInfo[id].tiptext,-1, &rcText, DT_CALCRECT);

//add the width of icon
rcText.right += CX_ICON;

//add a small gab
rcText.right += 14;

//make a bit higher
rcText.bottom += 12;


GetCursorPos(&pt);

// Get mouse pos in client coords
ScreenToClient(GetDesktopWindow(),&pt);
SetWindowPos(hWndtool,HWND_TOPMOST,pt.x ,pt.y +24,rcText.right,rcText.bottom,SWP_SHOWWINDOW);

GetClientRect(hWndtool,&rc);

(HPEN)SelectObject(hdctooltip, hBluePen);
SetTextColor(hdctooltip, crRED1);
RoundRect(hdctooltip,rc.left,rc.top,rc.right,rc.bottom,6,6 );

DrawIconEx(hdctooltip,
// handle to device context
4,
// x-coord of upper left corner
4,
// y-coord of upper left corner
hIcon,
// handle to icon
CX_ICON,
// icon width
CY_ICON,
// icon height
(UINT)NULL,
// frame index, animated icons
NULL,
// handle to background brush
DI_NORMAL
// icon-drawing flags
);
rc.left+=22;
rc.top+=6;
DrawText(hdctooltip,ToolbarInfo[id].tiptext,-1,&rc,DT_LEFT );


//ShowWindow(hWndtool,SW_SHOW);
DestroyIcon(hIcon);

}




BOOL WIN_IsCursorInRect (RECT rc)
{
POINT pt;

GetCursorPos(&pt);

// checks if mouse is on a rc

// Get mouse pos in client coords
ScreenToClient(hMainWnd,&pt);
return (PtInRect(&rc,pt));
}