Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
3.20/5 (2 votes)
See more:
i update 1 function for create\use ToolTip:
C++
HWND CreateToolTip(HWND hwndTool, string text)
{

	/*INITCOMMONCONTROLSEX icc;

	icc.dwSize = sizeof(INITCOMMONCONTROLSEX);
	icc.dwICC = ICC_BAR_CLASSES | ICC_TAB_CLASSES | ICC_WIN95_CLASSES;

	InitCommonControlsEx(&icc);*/
	if (text=="")
	{
		return FALSE;
	}
	// Get the window of the tool.
	//HWND hwndTool = GetDlgItem(hDlg, toolID);

	// Create the tooltip. g_hInst is the global instance handle.
	HWND hwndTip = CreateWindowEx(0, TOOLTIPS_CLASS, NULL,
		TTS_ALWAYSTIP|WS_POPUP , //| TTS_BALLOON,
		CW_USEDEFAULT, CW_USEDEFAULT,
		CW_USEDEFAULT, CW_USEDEFAULT,
		GetParent(hwndTool), NULL,
		hinstance, NULL);

	if (!hwndTool || !hwndTip)
	{
	    MessageBox(NULL, "Couldn't create the ToolTip control.", "Error", MB_OK);
		return (HWND)NULL;
	}



	// Associate the tooltip with the tool.
	TOOLINFO toolInfo = { 0 };
	toolInfo.cbSize =sizeof (TOOLINFO);// TTTOOLINFOA_V1_SIZE;
	toolInfo.hwnd = GetParent(hwndTool);
	toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
	toolInfo.uId = (UINT_PTR)hwndTool;
	toolInfo.lpszText =(LPSTR) text.c_str();



	if (!SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &toolInfo)) //Will add the Tool Tip on Control
    {
		int err = GetLastError();
		MessageBox(NULL,to_string(GetLastError()).c_str(), "Error", MB_OK);
	}

    if (SendMessage(hwndTip, TTM_ACTIVATE, TRUE,0)) //Will add the Tool Tip on Control
    {
		int err = GetLastError();
		MessageBox(NULL,to_string(GetLastError()).c_str(), "Error", MB_OK);

	}

	return hwndTip;
}


how is used:
C++
HWND tootip= CreateToolTip( lbltest , "hello");

these code works fine. but if i use WM_PAINT, with a child control, the ToolTip isn't showed or after several time is showed...
my question is(maybe can resolve the problem): what i must return with WM_PAINT?
i have read the MSDN documentation and they said for do:
C++
return 0;

but don't belive that it's corrected, because it can block the ToolTip :(
Posted
Comments
[no name] 1-May-15 19:28pm    
Make sure the parent window style includes WS_CLIPCHILDREN.
Member 11545824 2-May-15 8:25am    
i have it.
please see these function:
<pre lang="c++">BYTE* Get24BitPixels(HBITMAP pBitmap, WORD *pwWidth, WORD *pwHeight)
{
// a bitmap object just to get bitmap width and height
BITMAP bmpBmp;

// pointer to original bitmap info
LPBITMAPINFO pbmiInfo;

// bitmap info will hold the new 24bit bitmap info
BITMAPINFO bmiInfo;

// width and height of the bitmap
WORD wBmpWidth, wBmpHeight;

// ---------------------------------------------------------
// get some info from the bitmap
// ---------------------------------------------------------
GetObject(pBitmap, sizeof(bmpBmp),&bmpBmp);
pbmiInfo = (LPBITMAPINFO)&bmpBmp;

// get width and height
wBmpWidth = (WORD)pbmiInfo->bmiHeader.biWidth;
wBmpWidth -= (wBmpWidth%4); // width is 4 byte boundary aligned.
wBmpHeight = (WORD)pbmiInfo->bmiHeader.biHeight;

// copy to caller width and height parms
*pwWidth = wBmpWidth;
*pwHeight = wBmpHeight;
// ---------------------------------------------------------

// allocate width * height * 24bits pixels
BYTE *pPixels = new BYTE[wBmpWidth*wBmpHeight*3];
if (!pPixels) return NULL;

// get user desktop device context to get pixels from
HDC hDC = GetWindowDC(NULL);

// fill desired structure
bmiInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmiInfo.bmiHeader.biWidth = wBmpWidth;
bmiInfo.bmiHeader.biHeight = -wBmpHeight;
bmiInfo.bmiHeader.biPlanes = 1;
bmiInfo.bmiHeader.biBitCount = 24;
bmiInfo.bmiHeader.biCompression = BI_RGB;
bmiInfo.bmiHeader.biSizeImage = wBmpWidth*wBmpHeight*3;
bmiInfo.bmiHeader.biXPelsPerMeter = 0;
bmiInfo.bmiHeader.biYPelsPerMeter = 0;
bmiInfo.bmiHeader.biClrUsed = 0;
bmiInfo.bmiHeader.biClrImportant = 0;

// get pixels from the original bitmap converted to 24bits
int iRes = GetDIBits(hDC,pBitmap,0,wBmpHeight,(LPVOID)pPixels,&bmiInfo,DIB_RGB_COLORS);

// release the device context
ReleaseDC(NULL,hDC);

// if failed, cancel the operation.
if (!iRes)
{
delete pPixels;
return NULL;
};

// return the pixel array
return pPixels;
}</pre>
do you see a memory leak with new\delete?
why? because 1 external program test the code and give me an error

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900