Bug api section Tooltips

Fermé
Sivaller Messages postés 124 Date d'inscription dimanche 1 juillet 2007 Statut Membre Dernière intervention 13 mai 2011 - 17 mai 2010 à 19:29
Bonjour,
Je vous joint un listing de code source qui est censer d'afficher un info-bulle.
Rien ne s'affiche ! Windows n'est pas infaillible !

aline.cpp
#include "stdafx.h"
#include "aline.h"
#include "al.h"
#include < Commctrl.h>

/*#include <vector>
using namespace std;

vector <TGH> letters;*/

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name

// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);

HWND hletter;
HWND hWnd_i;

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;

// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_ALINE, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_ALINE));

// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return (int) msg.wParam;
}



//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage are only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ALINE));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_ALINE);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

return RegisterClassEx(&wcex);
}

//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;

hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}


ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

return TRUE;
}

//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
static bool tt=false;

switch (message)
{
case WM_CREATE:
{
SetTimer(hWnd,50,2000,NULL);
}
break;
case WM_TIMER:
{
if (!tt)
{
tt=true;
InitCommonControls();
initAL();

RECT rc;
hWnd_i=hWnd;
GetClientRect(hWnd,&rc);
HWND h=CreateWindow(szWindowClassAL,"",WS_CHILD,0,0,rc.right,rc.bottom,hWnd,NULL,hInst,NULL);
SetWindowPos(h,NULL,0,0,rc.right,rc.bottom,SWP_SHOWWINDOW);
hletter=h;
}
}
break;
case WM_SIZE:
SetWindowPos(hletter,0,0,0,LOWORD(lParam),HIWORD(lParam),SWP_SHOWWINDOW);
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}

al.cpp

#include <stdafx.h>
#include <windows.h>
#include <Commctrl.h>
#include "al.h"
#include "resource.h"



#define ML 9

extern HINSTANCE hInst;


extern HWND hWnd_i;

HBITMAP letterok,lettererr;


static HWND htooltip=NULL;

TOOLINFO ti = { 0 };


void CreateToolTipForRect(HWND hwndParent,HWND hid,char *s)
{
// Create a tooltip.
/* HWND hwndTT = CreateWindowEx(WS_EX_TOPMOST,
TOOLTIPS_CLASS, NULL,
WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
hwndParent, NULL, hInst,NULL);*/

HWND hwndTT = CreateWindowEx(WS_EX_TOPMOST,
TOOLTIPS_CLASS, NULL,
WS_POPUP|TTS_NOPREFIX |TTS_ALWAYSTIP,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
hwndParent, NULL, hInst,NULL);

/* SetWindowPos(hwndTT, HWND_TOPMOST,
0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);*/

// Set up "tool" information.
// In this case, the "tool" is the entire parent window.

ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE;
ti.hwnd = hwndParent;
ti.hinst = hInst;
ti.lpszText = s;
ti.uId=(UINT_PTR)hid;
GetClientRect (hid, &ti.rect);

// Associate the tooltip with the "tool" window.
SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
//SendMessage( hwndTT, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti);
//SendMessage(hwndTT, TTM_SETMAXTIPWIDTH, 0,200);
htooltip=hwndTT;
//SendMessage(hwndTT, TTM_SETMAXTIPWIDTH, 0, strlen(s));
//ShowWindow(hwndTT, SW_SHOW);
}





LRESULT CALLBACK WndProcAL(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
static bool g_TrackingMouse=false;
PAINTSTRUCT ps;
HDC hdc;
static WORD oldx=0,oldy=0;
WORD x,y;
static int sec=0;

switch (message)
{
case WM_CREATE:

CreateToolTipForRect(hWnd_i,hWnd,"essaintoto");
break;
case WM_TIMER:
{
sec++;
if (sec==3)
{

//if (htooltip==NULL)

}
}
break;
case WM_MOUSELEAVE:
// The mouse pointer has left our window.
// Deactivate the tooltip.
SendMessage(htooltip, TTM_TRACKACTIVATE, (WPARAM)FALSE, (LPARAM)&ti);
g_TrackingMouse = FALSE;
return FALSE;

case WM_MOUSEMOVE:
{

if (!g_TrackingMouse)
// The mouse has just entered the window.
{
// Request notification when the mouse leaves.
TRACKMOUSEEVENT tme = { sizeof(TRACKMOUSEEVENT) };
tme.hwndTrack = hWnd;
tme.dwFlags = TME_LEAVE;
TrackMouseEvent(&tme);

// Activate the tooltip.
SendMessage(htooltip, TTM_TRACKACTIVATE,
(WPARAM)TRUE, (LPARAM)&ti);
g_TrackingMouse = TRUE;
}


x=LOWORD(lParam)/1;
y=HIWORD(lParam)/1;
if ((x!=oldx) || (y!=oldy))
{
sec=0;
//oldxy=lParam;
if (htooltip!=NULL)
{
// DestroyWindow(htooltip);
// htooltip=NULL;
}

// Activate the tooltip.


ti.lpszText = "trucntoto";
SendMessage(htooltip, TTM_SETTOOLINFO, 0, (LPARAM)&ti);

// Position the tooltip.
// The coordinates are adjusted so that the tooltip does not
// overlap the mouse pointer.
POINT pt = { x, y };
ClientToScreen(hWnd, &pt);
SendMessage(htooltip, TTM_TRACKPOSITION,
0, (LPARAM)MAKELONG(pt.x + 10, pt.y - 20));

oldx=x;
oldy=y;
}
//SetFocus(hWnd);
return FALSE;

}
break;
case WM_PAINT:
{
hdc = BeginPaint(hWnd, &ps);
RECT rc;
GetClientRect(hWnd,&rc);
DWORD cl=RGB(0xd0,0xd0,0xe0);
HBRUSH hbr=CreateSolidBrush(cl);
FillRect(hdc,&rc,hbr);

EndPaint(hWnd, &ps);
}
break;

default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

void initAL()
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProcAL;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInst;
wcex.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ALINE));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_ALINE);
wcex.lpszClassName = szWindowClassAL;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

RegisterClassEx(&wcex);
}

void doneAL()
{
}

Aidez-moi à contourner le bug !

Merci