How to display tooltip and display the control on the status bar on the control of the dialog box with VC ++.

zhaozj2021-02-11  240

How to display Tooltip on the control on the dialog box and display the control on the status bar, Hunan Post and Telecommunications Wuxi, Xiao Tianpeng ---- Using VC AppWizard, you can easily implement tooltip and menu item Tooltip Or displays help information on the status bar, but to display Tooltip on the control of the dialog and display control information on the status bar is not so easy, in fact, using the WM_SETCURSOR in VC with the TTN_NeedText message to achieve the purpose. The specific operation is as follows: ---- One ---- MFC AppWizard with VC Generates an SDI or MDI application ---- II ---- Edit the string resources of the dialog control ---- For example: --- idc_dbbutton1 = "THIS IS Xiao Tianpeng's First Homemade Buttons / N Tianpeng", in which the string "this is Xiao Tianpeng's first homemade button" will be displayed on the status bar when the mouse is moved on the control. Tianpeng "will be displayed as Tooltip. ---- Three ---- Establish a message mapping. ---- Add the following code in the header file (* .h) of the dialog: protected:

Void setStatustext (uint nid = 0);

// {{AFX_MSG (cfileop1)

AFX_MSG void onDestroy ();

AFX_MSG BOOL ONSETCURSOR (CWND * PWND,

Uint nhittest, uint message);

//}} AFX_MSG

AFX_MSG BOOL ONTIPNOTIFY (UINT ID, NMHDR *

PNMHDR, LRESULT * PRESULT);

Declare_message_map ()

---- Add the following code to the implementation file (* .cpp) of the dialog: Begin_Message_Map (CFileOp1, CDialog)

// {{AFX_MSG_MAP (cfileop1)

ON_WM_DESTROY ()

ON_WM_SETCURSOR ()

//}} AFX_MSG_MAP

ON_NOTIFY_EX (TTN_NEEDTEXT, 0, ONTIPNOTIFY)

END_MESSAGE_MAP ()

---- Four ---- Edit Message Processing Function. Bool cfileop1 :: OnsetCursor

(CWND * PWND, UINT NHITTEST, UINT MESSAGE)

{

// Todo: Add your message handler

Code Here and / or Call Default

IF (PWND == this)

SetStatustext ();

Else

{

Tooltiptext m_pstt;

m_psttt.hdr.hwndfrom = m_hwnd;

m_psttt.hdr.idfrom = pwnd-> getdlgctrlid ();

m_psttt.hdr.code = TTN_NEEDTEXT;

m_psttt.uflags = ttf_idishwnd;

SetStatustext (pwnd-> getdlgctrlid ());

this-> sendMessage (WM_NOTIFY,

m_psttt.hdr.idfrom, (lparam) & m_pstt);

}

Return CDIALOG :: Onsetcursor

(PWND, NHITTEST, MESSAGE);

}

Void cfileop1 :: overdestroy ()

{

SetStatustext ();

CDIALOG :: ONDESTROY ();

}

Void cfileop1 :: setStatustext (uint nid) {

IF (NID == 0)

NID = AFX_IDS_IDLEMESSAGE;

CWND * PWND = AFXGETMAINWND () -> getDescendantWindow

(AFX_IDW_STATUS_BAR);

IF (PWND)

{

AFXGETMAINWND () -> SendMessage

(WM_SetMessageString, NID);

PWND-> SendMessage (WM_IdleUpdatecmdui);

PWND-> UpdateWindow ();

}

}

Bool cfileop1 :: ONTIPNOTIFY (UINT ID, NMHDR *

PNMHDR, LRESULT * PRESULT)

{

Tooltiptext * pttt = (tooltiptext *) PNMHDR;

UINT NID = PNMHDR-> IDFROM;

IF (PTTT-> UFLAGS & TTF_IDISHWND)

{

NID = :: getdlgctrlid ((hwnd) NID);

IF (NID)

{

Tchar SzfullText [256];

CString Strtiptext;

AfxLoadString (NID, SZFULLTEXT);

AFXTRACTSUBSTRING (Strtiptext,

SZFULLTEXT, 1, '/ N');

IF (! strtiptext.isempty ())

STRCPY (PTTT-> LPSZTEXT, STRTIPTEXT);

Pttt-> hinst = afxgetresourcehandle ();

Return (TRUE);

}

}

Return (False);

}

---- Five ---- Add the following instructions in the stdafx.h file: #include

#include

---- Six ---- The dialog box as a sub-window of a SDI or MDI application, generates such a dialog, move the mouse to a control (must have the corresponding string When the resource is on, the ToolTip and status bar information of the control will appear.

转载请注明原文地址:https://www.9cbs.com/read-3991.html

New Post(0)