I added an edit control to my GUI with the style ES_NUMBER. When I try to enter a character then a tooltip appears with text "Unacceptable Character".
Is there a possibility to hide this tooltip?
You need to derive a class from CEdit and handle EM_SHOWBALLOONTIP message:
Class header:
class CNoTooltipEdit: public CEdit
{
DECLARE_DYNAMIC(CNoTooltipEdit)
public:
CNoTooltipEdit();
virtual ~CNoTooltipEdit();
protected:
DECLARE_MESSAGE_MAP()
public:
LRESULT OnShowTip(WPARAM w, LPARAM l);
};
Class Implementation:
IMPLEMENT_DYNAMIC(CNoTooltipEdit, CEdit)
CNoTooltipEdit::CNoTooltipEdit()
{
}
CNoTooltipEdit::~CNoTooltipEdit()
{
}
BEGIN_MESSAGE_MAP(CNoTooltipEdit, CEdit)
ON_MESSAGE(EM_SHOWBALLOONTIP, &CNoTooltipEdit::OnShowTip)
END_MESSAGE_MAP()
LRESULT CNoTooltipEdit::OnShowTip(WPARAM w, LPARAM l)
{
return TRUE;
}
Related
I have a lot of CDialogEx derived classes that do something like this in OnInitDialog:
CMeetingScheduleAssistantApp::InitialiseResizeIcon(m_bmpResize, m_lblResize, this);
CMeetingScheduleAssistantApp::RestoreWindowPosition(_T("PublisherDB"), this, true);
Then, I have the following added to each derived dialog class:
int CPublishersDatabaseDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialogEx::OnCreate(lpCreateStruct) == -1)
return -1;
// Save Initial window size to m_rcInit
GetWindowRect(&m_rcInit);
return 0;
}
void CPublishersDatabaseDlg::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
{
// Set the minimum window size to initial size.
lpMMI->ptMinTrackSize.x = m_rcInit.Width();
lpMMI->ptMinTrackSize.y = m_rcInit.Height();
CDialogEx::OnGetMinMaxInfo(lpMMI);
}
void CPublishersDatabaseDlg::OnClose()
{
CMeetingScheduleAssistantApp::SaveWindowPosition(_T("PublisherDB"), this);
CDialogEx::OnClose();
}
The only thing that is different for each dialog is the phrase that is used for saving the window position.
I want to have a based CDialogEx class that I can inherit from that will perform the above actions. I have looked on SO and seem some questions and creating a CDialog class and inheriting from another CDialog class. But this class I want to create is more generic. Effectively to be used as a base instead of CDialogEx.
Can this be done? Am I over-complicating this?
Problems
Why I try to create a new class, derived from CDialogEx:
I don't know if it is because it requires a dialog ID as stated here.
Classes such as CDialog, CFormView, or CPropertyPage, which require a dialog ID.
So I can't work out the correct way to create a base CDialogEx class for use in all my other dialog classes.
Update
I created this code and it tells me that CResizingDialog is not a class or a namespace:
#include "ResizingDialog.h"
#include "resource.h"
#include "stdafx.h"
IMPLEMENT_DYNAMIC(CResizingDialog, CDialogEx)
CResizingDialog::CResizingDialog(const CString& strWindowID, UINT nIDTemplate, CWnd* pParent = nullptr)
: m_strWindowID(strWindowID), CDialogEx(nIDTemplate, pParent)
{
}
CResizingDialog::~CResizingDialog()
{
}
void CResizingDialog::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CResizingDialog, CDialogEx)
ON_WM_CREATE()
ON_WM_GETMINMAXINFO()
ON_WM_CLOSE()
END_MESSAGE_MAP()
int CResizingDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialogEx::OnCreate(lpCreateStruct) == -1)
return -1;
// Save Initial window size to m_rcInit
GetWindowRect(&m_rcInit);
return 0;
}
void CResizingDialog::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
{
// Set the minimum window size to initial size.
lpMMI->ptMinTrackSize.x = m_rcInit.Width();
lpMMI->ptMinTrackSize.y = m_rcInit.Height();
CDialogEx::OnGetMinMaxInfo(lpMMI);
}
void CResizingDialog::OnClose()
{
SaveWindowPosition(m_strWindowID, this);
CDialogEx::OnClose();
}
Based on the comments encouraging me to try to create the class manually, I have it working:
#include "stdafx.h"
#include "resource.h"
#include "ResizingDialog.h"
IMPLEMENT_DYNAMIC(CResizingDialog, CDialogEx)
CResizingDialog::CResizingDialog(const CString& strWindowID, UINT nIDTemplate, CWnd* pParent /* nullptr */, bool bOnlyStorePosition /* false */)
: m_strWindowID(strWindowID),
m_bOnlyStorePosition(bOnlyStorePosition), CDialogEx(nIDTemplate, pParent)
{
}
CResizingDialog::~CResizingDialog()
{
}
void CResizingDialog::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CResizingDialog, CDialogEx)
ON_WM_CREATE()
ON_WM_GETMINMAXINFO()
ON_WM_CLOSE()
END_MESSAGE_MAP()
int CResizingDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialogEx::OnCreate(lpCreateStruct) == -1)
return -1;
// Save Initial window size to m_rcInit
GetWindowRect(&m_rcInit);
return 0;
}
void CResizingDialog::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
{
// Set the minimum window size to initial size.
lpMMI->ptMinTrackSize.x = m_rcInit.Width();
lpMMI->ptMinTrackSize.y = m_rcInit.Height();
CDialogEx::OnGetMinMaxInfo(lpMMI);
}
void CResizingDialog::OnClose()
{
SaveWindowPosition(m_strWindowID, this);
CDialogEx::OnClose();
}
void CResizingDialog::OnOK()
{
SaveWindowPosition();
CDialogEx::OnOK();
}
BOOL CResizingDialog::OnInitDialog()
{
CDialogEx::OnInitDialog();
if(!m_bOnlyStorePosition)
InitialiseResizeIcon(m_bmpResize, m_lblResize, this);
RestoreWindowPosition(m_strWindowID, this, true);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
I decided to duplicate the methods that were in the app class into this new dialog class instead. Eventually they can be removed from the app class. The only thing I also had to do was #include my resource file because the image needs to know the value of the resource ID.
This is the ResizingDialog.h header:
#pragma once
#include <afxwin.h>
class CResizingDialog : public CDialogEx
{
DECLARE_DYNAMIC(CResizingDialog)
public:
CResizingDialog(const CString& phrase, UINT nIDTemplate, CWnd* pParent = nullptr, bool bOnlyStorePosition = false); // Constructor
virtual ~CResizingDialog(); // Destructor
protected:
void OnOK() override;
virtual void DoDataExchange(CDataExchange* pDX) override; // DDX/DDV support
void SaveWindowPosition(void) { SaveWindowPosition(m_strWindowID, this); }
public:
BOOL OnInitDialog() override;
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI);
afx_msg void OnClose();
DECLARE_MESSAGE_MAP()
private:
CBitmap m_bmpResize;
CStatic m_lblResize;
CRect m_rcInit;
CString m_strWindowID;
bool m_bOnlyStorePosition;
void RestoreWindowPosition(CString strWindow, CWnd* pWindow, bool bOverrideState = false);
void SaveWindowPosition(CString strWindow, CWnd* pWindow);
void InitialiseResizeIcon(CBitmap& rBmpResize, CStatic& rLblResize, CWnd* pDialog);
};
The actual functions SaveWindowPosition, RestoreWindowPosition and InitialiseResizeIcon are not shown here as they don't directly relate to the issue.
I have modHolder class object
class modHolder : public CWinThread
{
DECLARE_DYNCREATE(modHolder)
protected:
modHolder();
virtual ~modHolder();
public:
CMainWindow * v1;
virtual BOOL InitInstance();
virtual int ExitInstance();
protected:
DECLARE_MESSAGE_MAP()
};
That is created like:
AfxBeginThread(RUNTIME_CLASS(modHolder));
I have frame with button inside of it:
class CMainWindow : public CFrameWnd
{
public:
CMainWindow ();
CButton m_wndPushButton;
protected:
afx_msg LRESULT OnMyMessage1(WPARAM wParam, LPARAM lParam);
afx_msg int OnCreate (LPCREATESTRUCT lpcs) ;
afx_msg void OnPaint ();
afx_msg void OnPushButtonClicked ();
DECLARE_MESSAGE_MAP ()
};
Whenn I push button it no visible messages are shown:
void CMainWindow::OnPushButtonClicked ()
{
MessageBox (_T ("bbb"),_T ("Error"), B_ICONINFORMATION | MB_OK);
//AfxMessageBox("aaaa");
}
But message functions do not returns. Why message is not visible?
Hi I have created a dialog box and it woks.
My question is: how do you retreive the handle for it?
Also, if you get the handle, how would you change the static text control text inside it?
class CStatisticsDlg : public CDialogEx
{
public:
CStatisticsDlg();
// Dialog Data
enum { IDD = IDD_STATISTICS };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
public:
};
CStatisticsDlg::CStatisticsDlg() : CDialogEx(CStatisticsDlg::IDD)
{
}
void CStatisticsDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CStatisticsDlg, CDialogEx)
END_MESSAGE_MAP()
Assuming you're using MFC (as indicated by the tag), then presumably you have a CDialog class instance. CDialog is a subclass of CWnd, so you can retrieve the window handle by one of 3 ways:
Directly accessing its m_hWnd member
Casting it to an HWND with operator HWND()
Calling GetSafeHwnd() on it
Here is how to do it.
First create a member function to the main application class.
Then use the following code (Assuming the class name is CGenericApp, and your Dialog class is CGenericDlg.
CWnd* CGenericApp::GetDlg()
{
return m_pMainWnd;
}
Then when you want to get a handler to the main Dialog box, use:
CGenericApp* app = (CGenericApp*)AfxGetApp();
CGenericDlg* pDlg = (CGenericDlg*)(app->GetDlg());
HWND win = pDlg->GetSafeHwnd();
'win' will hold the HWND you are looking for.
Header:
#pragma once
class AlarmsList : public CVSListBox
{
DECLARE_DYNAMIC(AlarmsList)
public:
AlarmsList();
virtual ~AlarmsList();
void OnAfterAddItem(int index);
void OnSelectionChanged(NMHDR *pNMHDR, LRESULT *pResult);
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnDtnDatetimechangeDatetimepicker1(NMHDR *pNMHDR, LRESULT *pResult);
};
void AlarmsList::OnAfterAddItem(int index)
{
GetParent()->GetDlgItem(IDC_TIMEPICK)->EnableWindow(true);
LOGIC->addAlarm();
LOGIC->changeSelection(index);
}
void AlarmsList::OnSelectionChanged(NMHDR *pNMHDR, LRESULT *pResult)
{
}
OnAfterAddItem gets called when i add a new item but OnSelectionChanged NEVER gets called how much i even try.
Linking it trough a message map neither dosnt work:
IMPLEMENT_DYNAMIC(AlarmsList, CVSListBox)
BEGIN_MESSAGE_MAP(AlarmsList, CVSListBox)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST, OnSelectionChanged)
END_MESSAGE_MAP()
I create the AlarmsList object using the create function.
Source code and project: http://www.filedropper.com/clockmaster
Generally, I think the LVN_ITEMCHANGED notification is sent to the parent window. Put the handler and the message map entry int your dialog/window that is the parent of the list box.
Didnt help :/.
Tried both parent property page and that property pages dialog.
Overloading dosnt work either :/, it does for OnAfterAddItem tough.
And yes I'm then using the same parameters as the virtual function.
You can try overriding the functions in the CVSListBoxBase class.In this class, the signature of OnSelectionChanged function requires no arguments.
You can find the declaration of the CVSListBoxBase class in afxvslistbox.h.
Just had a look at some of my own MFC code that uses list boxes, and the following works;
CMyListBox : public CListBox
{
}
class CMyDialog : public CDialog
{
// Construction
public:
CMyDialog(CFeatureDoc* pFeatureDoc,BOOL SheetLayout = FALSE,CWnd* pParent = NULL); // standard constructor
//{{AFX_DATA(CMyDialog)
enum { IDD = IDD_MY_DIALOG };
CMyListBox m_MyListBox;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyDialog)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CMyDialog)
afx_msg void OnSelChangeListBox();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
void CMyDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDialog)
DDX_Control(pDX, IDC_MY_LIST_BOX, m_MyListBox);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
//{{AFX_MSG_MAP(CMyDialog)
ON_LBN_SELCHANGE(IDC_MY_LIST_BOX, OnSelChangeListBox)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDialog message handlers
void CMyDialog::OnSelChangeListBox()
{
}
If you want to have your own control process messages from a dialog, you may want to subclass it. See this related question What's the correct way to create a subclass of a MFC control?
I am trying to get a context menu to work for a CListCtrl derived class. I just created a method OnContextMenu, but it isn't being called. What am I missing? I am using Visual Studio 2008, to create a CDialog based MFC application.
CustomList.h
class tcCustomListCtl : public CListCtl
{
DECLARE_DYNAMIC(tcCustomListCtl)
public:
tcCustomListCtl();
virtual ~tcCustomListCtl();
protected:
DECLARE_MESSAGE_MAP()
afx_msg void OnContextMenu(CWnd* pWnd,CPoint pos );
};
CustomList.cpp
// tcFaultListCtl
IMPLEMENT_DYNAMIC(tcCustomListCtl, CListCtrl)
tcCustomListCtl::tcCustomListCtl()
{
}
tcCustomListCtl::~tcCustomListCtl()
{
}
BEGIN_MESSAGE_MAP(tcCustomListCtl, CListCtrl)
END_MESSAGE_MAP()
// tcCustomListCtl message handlers
afx_msg void tcCustomListCtl::OnContextMenu(CWnd* pWnd,CPoint pos )
{
TRACE("tcCustomListCtl::OnContextMenu\n");
}
I found out I had to add ON_WM_CONTEXTMENU() to message map.