c++ - How do I get a multi line tooltip in MFC -
right now, have tool tip pops when hover on edit box. problem tool tip contains multiple error messages , in 1 long line. need have each error message on own line. error messages contained in cstring new line seperating them.
my existing code below.
bool ontooltiptext(uint, nmhdr* pnmhdr, lresult* presult) { assert(pnmhdr->code == ttn_needtexta || pnmhdr->code == ttn_needtextw); // need handle both ansi , unicode versions of message tooltiptexta* pttta = (tooltiptexta*)pnmhdr; tooltiptextw* ptttw = (tooltiptextw*)pnmhdr; // tchar szfulltext[256]; cstring strtiptext=_t(""); uint nid = pnmhdr->idfrom; if (pnmhdr->code == ttn_needtexta && (pttta->uflags & ttf_idishwnd) || pnmhdr->code == ttn_needtextw && (ptttw->uflags & ttf_idishwnd)) { // idfrom hwnd of tool nid = ::getdlgctrlid((hwnd)nid); } //m_errprojaccel[ch] contains 1 or more error messages each seperated new line. if((int)nid >= id_projected_accel1 && (int)nid < id_projected_accel1 + projected_rows -1 ) { int ch = nid - id_projected_accel1; strtiptext = m_errprojaccel[ch]; } #ifndef _unicode if (pnmhdr->code == ttn_needtexta) lstrcpyn(pttta->sztext, strtiptext, sizeof(pttta->sztext)/sizeof(pttta->sztext[0])); else _mbstowcsz(ptttw->sztext, strtiptext, sizeof(pttta->sztext)/sizeof(pttta->sztext[0])); #else if (pnmhdr->code == ttn_needtexta) _wcstombsz(pttta->sztext, strtiptext, sizeof(pttta->sztext)/sizeof(pttta->sztext[0])); else lstrcpyn(ptttw->sztext, strtiptext, sizeof(pttta->sztext)/sizeof(pttta->sztext[0])); #endif *presult = 0; // bring tooltip window above other popup windows ::setwindowpos(pnmhdr->hwndfrom, hwnd_top, 0, 0, 0, 0, swp_noactivate|swp_nosize|swp_nomove|swp_noownerzorder); return true; // message handled }
creating multiline tooltips explained here in msdn library - read "implementing multiline tooltips" section. should send ttm_setmaxtipwidth message tooltip control in response ttn_getdispinfo notification force use multiple lines. in string should separate lines \r\n.
also, if text more 80 characters, should use lpsztext member of nmttdispinfo structure instead of copying sztext array.
Comments
Post a Comment