Message box is not visible - c++

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?

Related

In MFC how to hide tooltip of CEdit

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;
}

Creating a new base CDialogEx derived class

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.

IN MFC CLISTCTRL a column should have an EDIT feature?

I am a beginner to MFC and C++ I want to have an edit option in one column I tried to overload these functions in the Classes but the Edit Option is not working could any one help me on this what is the mistake I did ?
class CEditableListCtrl : public CListCtrl
{
public:
int GetRowFromPoint( CPoint &point, int *col ) const;
CEdit* EditSubLabel( int nItem, int nCol );
void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
void OnEndLabelEdit(NMHDR* pNMHDR, LRESULT* pResult);
void OnLButtonDown(UINT nFlags, CPoint point);
};
class CInPlaceEdit : public CEdit
{
public:
CInPlaceEdit(int iItem, int iSubItem, CString sInitText);
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CInPlaceEdit)
public: virtual BOOL PreTranslateMessage(MSG* pMsg);
//}}AFX_VIRTUAL
public: virtual ~CInPlaceEdit();
// Generated message map functions
protected:
//{{AFX_MSG(CInPlaceEdit)
afx_msg void OnKillFocus(CWnd* pNewWnd);
afx_msg void OnNcDestroy();
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
int m_iItem;
int m_iSubItem;
CString m_sInitText;
BOOL m_bESC;
};
If you only need one column to be editable, you don't need to do much: make sure your list has an LVS_EDITLABELS style. This will allow you to edit text in column 0. If you need to edit different column - change visible column order using CListCtrl::SetColumnOrderArray()

How to implement #pragma pointers_to_members() for just one class?

I want to use #pragma pointers_to_members() to just one class.
I have other class definitions in my header file but I want to apply the required pragma to only one class and other classes should not be affected. How can this be achieved? There are not many code examples for that.
I have resolved this issue. I used the # pragma directive just before the BEGIN_MESSAGE_MAP() in my .cpp file.
#pragma pointers_to_members(full_generality,virtual_inheritance)
BEGIN_MESSAGE_MAP(CMy4407Dlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, &CMy4407Dlg::OnBnClickedButton1)
END_MESSAGE_MAP()
This is my derived class CMy4407Dlg:
class CMy4407Dlg : public CDialogEx, public virtual ABCD
{
// Construction
public:
CMy4407Dlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
enum { IDD = IDD_MY4407_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedButton1();
};

MFC CView into CDockablePane

I need to place a CView derived class into a CDockablePane. Is there any code example somewhere, or can someone provide such code?
What I tried:
Apparently should be simple, online I found advice like "just create the view and set its parent to be the dialog or the dockable pane or what kind of window you want". But for some reason it doesn't work, maybe is because it needs a CFrameWnd, I don't know.
Anyway, I need to be able to do this without creating another document template class. Just to work with preexisting document and view classes.
Here's an example:
a class derived from CDockablePane:
//CRichEditPane .h
class CRichEditPane : public CDockablePane
{
DECLARE_DYNAMIC(CRichEditPane)
public:
CRichEditPane();
virtual ~CRichEditPane();
protected:
void AdjustLayout();
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSize(UINT nType, int cx, int cy);
};
//CRichEditPane .cpp
IMPLEMENT_DYNAMIC(CRichEditPane, CDockablePane)
CRichEditPane::CRichEditPane()
{
}
CRichEditPane::~CRichEditPane()
{
}
BEGIN_MESSAGE_MAP(CRichEditPane, CDockablePane)
ON_WM_CREATE()
ON_WM_SIZE()
END_MESSAGE_MAP()
// CRichEditPane message handlers
int CRichEditPane::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDockablePane::OnCreate(lpCreateStruct) == -1)
return -1;
CRuntimeClass *pClass = RUNTIME_CLASS(CRichEditViewInPane);
// calling constructor using IMPLEMENT_DYNCREATE macro
CRichEditViewInPane *pView = (CRichEditViewInPane*)pClass->CreateObject();
if (!pView->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, CRect(0,0,0,0), this, AFX_IDW_PANE_FIRST, NULL))
{
return -1;
}
CRichEditCtrl ctrl;
ctrl.Create(WS_CHILD, CRect(0, 0, 0, 0), this, 10991);
return 0;
}
void CRichEditPane::OnSize(UINT nType, int cx, int cy)
{
CDockablePane::OnSize(nType, cx, cy);
AdjustLayout();
}
a view class derived from CView:
//CRichEditViewInPane .h
class CRichEditViewInPane : public CRichEditView
{
DECLARE_DYNCREATE(CRichEditViewInPane)
protected:
CRichEditViewInPane(); // protected constructor used by dynamic creation
virtual ~CRichEditViewInPane();
public:
#ifdef _DEBUG
virtual void AssertValid() const;
#ifndef _WIN32_WCE
virtual void Dump(CDumpContext& dc) const;
#endif
#endif
protected:
DECLARE_MESSAGE_MAP()
};
//CRichEditViewInPane. cpp
IMPLEMENT_DYNCREATE(CRichEditViewInPane, CRichEditView)
CRichEditViewInPane::CRichEditViewInPane()
{
}
CRichEditViewInPane::~CRichEditViewInPane()
{
}
BEGIN_MESSAGE_MAP(CRichEditViewInPane, CRichEditView)
END_MESSAGE_MAP()