I still learn mfc, i want to create application like webbrowser. it have seperate page that can call anytime. I try to implement that. But i can't implement the 2nd page and so on. in the code only have 2 pages. login and logout page. i put login in render method. but i dont know how to implement 2nd page (logout). for now i just directly put it inside login method. can u show me in mfc ways to achieve this?
#include <afxwin.h>
#define LOGIN_BTN 5
#define LOGOUT_BTN 6
class CMainFrame: public CFrameWnd
{
CPoint mCoordinate;
CSize mDimension;
public:
CMainFrame()
{
// Get primary screen resolution
int widthScreen = GetSystemMetrics(SM_CXSCREEN);
int heightScreen = GetSystemMetrics(SM_CYSCREEN);
// Set size and position to middle screen
mDimension.cx = 280;
mDimension.cy = 133;
mCoordinate.x = (widthScreen / 2) - (mDimension.cx / 2);
mCoordinate.y = (heightScreen / 2) - (mDimension.cy / 2);
Create(
NULL,
"Pandora",
WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU,
CRect(mCoordinate, mDimension));
};
void render()
{
CButton* loginBtn = new CButton();
loginBtn->Create(
"Login",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
CRect(CPoint(100, 60), CSize(150, 25)),
this, LOGIN_BTN);
};
void removeAllChild()
{
CWnd* pChild = nullptr;
while(true)
{
pChild = GetWindow(GW_CHILD);
if(pChild == NULL) { break; }
delete pChild;
};
};
protected:
afx_msg int OnCreate(LPCREATESTRUCT);
afx_msg void login();
afx_msg void logout();
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CREATE()
ON_COMMAND(LOGIN_BTN, &CMainFrame::login)
ON_COMMAND(LOGOUT_BTN, &CMainFrame::logout)
END_MESSAGE_MAP()
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
render();
return 0;
};
void CMainFrame::login()
{
// delete all child
removeAllChild();
// How to make this logout button such it in 2nd page?
CButton* logoutBtn = new CButton;
logoutBtn->Create(
"Logout",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
CRect(CPoint(40, 32), CSize(200, 70)),
this, LOGOUT_BTN);
};
void CMainFrame::logout()
{
removeAllChild();
render();
};
class CApplication : public CWinApp {
BOOL InitInstance() {
CMainFrame* mainWnd = new CMainFrame();
m_pMainWnd = mainWnd;
mainWnd->ShowWindow(SW_NORMAL);
mainWnd->UpdateWindow();
return TRUE;
}
};
CApplication app;
You could refer to the document : Adding Multiple Views to a Single Document. Also here is a similar thread may help: How to change MFC View by clicking a Button inside the MainFrame.
You could use the code below to switch the view:
pActiveView->ShowWindow(SW_HIDE);
pNewView->ShowWindow(SW_SHOW);
((CFrameWnd *)m_pMainWnd)->SetActiveView(pNewView);
((CFrameWnd *)m_pMainWnd)->RecalcLayout();
pNewView->Invalidate();
Related
At first I called the Create method of the CFrameWnd within another class.
Then I continued with the Create method of CDockablePane with the FrameWnd as the pParentWnd parameter.
The second Create was not successful, an assertion occured in the following code:
void CMFCDragFrameImpl::Init(CWnd* pDraggedWnd)
{
ASSERT_VALID(pDraggedWnd);
m_pDraggedWnd = pDraggedWnd;
CWnd* pDockSite = NULL;
if (m_pDraggedWnd->IsKindOf(RUNTIME_CLASS(CPaneFrameWnd)))
{
CPaneFrameWnd* pMiniFrame = DYNAMIC_DOWNCAST(CPaneFrameWnd, m_pDraggedWnd);
pDockSite = pMiniFrame->GetParent();
}
else if (m_pDraggedWnd->IsKindOf(RUNTIME_CLASS(CPane)))
{
CPane* pBar = DYNAMIC_DOWNCAST(CPane, m_pDraggedWnd);
ASSERT_VALID(pBar);
CPaneFrameWnd* pParentMiniFrame = pBar->GetParentMiniFrame();
if (pParentMiniFrame != NULL)
{
pDockSite = pParentMiniFrame->GetParent();
}
else
{
pDockSite = pBar->GetDockSiteFrameWnd();
}
}
m_pDockManager = afxGlobalUtils.GetDockingManager(pDockSite);
if (afxGlobalUtils.m_bDialogApp)
{
return;
}
ENSURE(m_pDockManager != NULL); <-----------------------
}
Somehow a docking manager seems to be missing. Is it possible that CFrameWnd is not suitable for CDockablePane? Or the docking manager needs to be initialized?
Thanks for your help (code snippets are welcome)!
To add a dockable pane to your project, the first step is to derive a new class from CDockablePane and you must add two message handlers for OnCreate and OnSize, and add a member child window as the main content. Your simple CTreePane class should look like this:
class CTreePane : public CDockablePane
{
DECLARE_MESSAGE_MAP()
DECLARE_DYNAMIC(CTreePane)
protected:
afx_msg int OnCreate(LPCREATESTRUCT lp);
afx_msg void OnSize(UINT nType,int cx,int cy);
private:
CTreeCtrl m_wndTree ;
};
int CTreePane::OnCreate(LPCREATESTRUCT lp)
{
if(CDockablePane::OnCreate(lp)==-1)
return -1;
DWORD style = TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT|
WS_CHILD|WS_VISIBLE|TVS_SHOWSELALWAYS | TVS_FULLROWSELECT;
CRect dump(0,0,0,0) ;
if(!m_wndTree.Create(style,dump,this,IDC_TREECTRL))
return -1;
return 0;
}
In the OnSize handler, you should size your control to fill the entire dockable pane client area.
void CTreePane::OnSize(UINT nType,int cx,int cy)
{
CDockablePane::OnSize(nType,cx,cy);
m_wndTree.SetWindowPos(NULL,0,0,cx,cy, SWP_NOACTIVATE|SWP_NOZORDER);
}
To support a dockable pane in your frame, you must first derive from the Ex family of frames (CFrameWndEx, CMDIFrameWndEx, ..) and in the OnCreate handler, you should initialize the docking manager by setting the allowable docking area, general properties, smart docking mode, …etc.
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...
CDockingManager::SetDockingMode(DT_SMART);
EnableAutoHidePanes(CBRS_ALIGN_ANY);
...
}void CMainFrame::OnTreePane()
{
if(m_treePane && m_treePane->GetSafeHwnd())
{
m_treePane->ShowPane(TRUE,FALSE,TRUE);
return ;
}
m_treePane = new CTreePane;
UINT style = WS_CHILD | CBRS_RIGHT |CBRS_FLOAT_MULTI;
CString strTitle = _T("Tree Pane");
if (!m_treePane->Create(strTitle, this,
CRect(0, 0, 200, 400),TRUE,IDC_TREE_PANE, style))
{
delete m_treePane;
m_treePane = NULL ;
return ;
}
m_treePane->EnableDocking(CBRS_ALIGN_ANY);
DockPane((CBasePane*)m_treePane,AFX_IDW_DOCKBAR_LEFT);
m_treePane->ShowPane(TRUE,FALSE,TRUE);
RecalcLayout();
}
For some reasons I have a parent window. This window contains normal controls. But it also takes child controls that again have controls in it. The real application is more complex. In the real version I also use WS_EX_CONTROLPARENT to allow navigation in the dialog between the nested controls.
For simplicity I created a dialog base application. In there is a normal edit control and a static control with an edit control in it. I just created the edit control inside my code.
I enabled the tool tips. In the normal way. Tooltips are shown for the buttons and the normal edit control. But the control inside the static doesn't show a tooltip.
How to get the tools tips for the nested controls too inside my handler?
Here the code for the CPP.
// ToolTipTestDlg.cpp : implementation file
#include "pch.h"
#include "framework.h"
#include "ToolTipTest.h"
#include "ToolTipTestDlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CToolTipTestDlg dialog
CToolTipTestDlg::CToolTipTestDlg(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_TOOLTIPTEST_DIALOG, pParent)
{
EnableToolTips();
}
void CToolTipTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_CONTAINER, m_container);
}
BEGIN_MESSAGE_MAP(CToolTipTestDlg, CDialogEx)
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
END_MESSAGE_MAP()
// CToolTipTestDlg message handlers
BOOL CToolTipTestDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
m_edit1.Create(WS_CHILD | WS_BORDER | WS_VISIBLE, CRect(10, 10, 110, 30), this, 1);
m_edit2.Create(WS_CHILD | WS_BORDER | WS_VISIBLE, CRect(10, 10, 110, 30), &m_container, 1);
return TRUE; // return TRUE unless you set the focus to a control
}
BOOL CToolTipTestDlg::OnToolTipText(UINT nId, NMHDR* pNMHDR, LRESULT* pResult)
{
// For all keyboard messages we need to know the target of the message
ASSERT(pNMHDR->code == TTN_NEEDTEXTA || pNMHDR->code == TTN_NEEDTEXTW);
TOOLTIPTEXTW* pTTTW = reinterpret_cast<NMTTDISPINFO*>(pNMHDR);
CString strTipText = _T("Test");
wcsncpy_s(pTTTW->szText, _countof(pTTTW->szText), CT2W(strTipText), _countof(pTTTW->szText));
*pResult = 0;
return TRUE; // message was handled
}
The header file:
// ToolTipTestDlg.h : header file
#pragma once
// CToolTipTestDlg dialog
class CToolTipTestDlg : public CDialogEx
{
// Construction
public:
CToolTipTestDlg(CWnd* pParent = nullptr); // standard constructor
// Dialog Data
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_TOOLTIPTEST_DIALOG };
#endif
CEdit m_edit1, m_edit2;
CStatic m_container;
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
// Generated message map functions
virtual BOOL OnInitDialog();
DECLARE_MESSAGE_MAP()
afx_msg BOOL OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult);
};
And the RC file with the container:
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_TOOLTIPTEST_DIALOG DIALOGEX 0, 0, 321, 96
STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_THICKFRAME
EXSTYLE WS_EX_APPWINDOW
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
DEFPUSHBUTTON "OK",IDOK,79,75,50,14
PUSHBUTTON "Cancel",IDCANCEL,134,75,50,14
LTEXT " ",IDC_CONTAINER,7,39,168,25,SS_NOTIFY
END
My investigation showed that this MFC tooltip implementation is only designed for controls that are direct children for the control that called EnabledToolTips.
I found an solution that works. It may not be the best but it is easy to implement.
I use an own container class (in my real world code this class already exists)
class CStaticContainer : public CStatic
{
public:
DECLARE_MESSAGE_MAP()
afx_msg BOOL OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult);
};
I made sure that this container class is used and subclassed the existing CStatic (here the code for the sample in the dialog class):
// In the dialog class
CStaticContainer m_container;
...
void CToolTipTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_CONTAINER, m_container);
}
I enabled tooltips for the container too in OnInitDialog.
m_container.EnableToolTips();
For the container class I added a TTN_NEEDTEXT handler. It just forwards the message to the outer parent.
BEGIN_MESSAGE_MAP(CStaticContainer, CStatic)
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
END_MESSAGE_MAP()
BOOL CStaticContainer::OnToolTipText(UINT nId, NMHDR* pNMHDR, LRESULT* pResult)
{
GetParent()->SendMessage(WM_NOTIFY, nId, reinterpret_cast<LPARAM>(pNMHDR));
return TRUE; // message was handled
}
Now the tool tips show up for all controls.
I am not sure what code to show you here. I have a CDialogEx derived resource in my MFC application:
It supports the dynamic resize layout controls so the user can resize the window. But I would like to add a vertical gripper (indicated in red) so the user can make the width of the names column larger.
I have done some research on this and all the articles are nearly 10 years old and don't factor in the newer dynamic resizing controls.
Having researched this more I see that the "resize gripper" term is not what I mean. That is the icon in the bottom right. I don't mean this.
I am sure you know what I mean though. Is it possible?
Adding a custom gripper control can be relatively easy. See CMySplitter class below.
But if all the controls are in one dialog, it will be very difficult reposition/resize individual controls one by one.
Ideally, use two child dialogs. Set the resize/reposition properties for individual controls in resource editor. Put the grip control in between the two dialogs and resize in response.
Class for gripper control:
#include <functional>
class CMySplitter : public CStatic
{
public:
class CPopup : public CWnd
{
public:
CMySplitter *parent;
int offset;
void OnMouseMove(UINT flag, CPoint pt);
void OnLButtonUp(UINT flag, CPoint pt);
DECLARE_MESSAGE_MAP()
};
std::function<void(int)> callback;
CRect boundary;
CPopup popup;
void OnLButtonDown(UINT flag, CPoint point);
void PreSubclassWindow();
void SetRange(int left, int right);
DECLARE_MESSAGE_MAP()
};
//create splitter control from a static control in dialog
void CMySplitter::PreSubclassWindow()
{
CStatic::PreSubclassWindow();
//modify static control's style (must have SS_NOTIFY)
SetWindowLongPtr(m_hWnd, GWL_STYLE, WS_VISIBLE | SS_GRAYRECT | WS_CHILD | SS_NOTIFY);
//create a popup window with transparency
static CString classname =
AfxRegisterWndClass(0, 0, (HBRUSH)GetStockObject(BLACK_BRUSH));
popup.CreateEx(WS_EX_LAYERED | WS_EX_PALETTEWINDOW | WS_EX_NOACTIVATE,
classname, NULL, WS_POPUP, CRect(0, 0, 0, 0), this, 0);
popup.SetLayeredWindowAttributes(0, 128, LWA_ALPHA);
popup.parent = this;
}
//when user click the static control, show a popup window
void CMySplitter::OnLButtonDown(UINT flag, CPoint pt)
{
CStatic::OnLButtonDown(flag, pt);
GetCursorPos(&pt);
CRect rc;
GetWindowRect(&rc);
popup.offset = pt.x - rc.left;
popup.SetWindowPos(NULL, rc.left, rc.top, rc.Width(), rc.Height(), SWP_SHOWWINDOW);
popup.SetCapture();
}
//how far to the left and right the splitter can go
void CMySplitter::SetRange(int left_, int right_)
{
CRect rc;
GetParent()->GetWindowRect(&rc);
boundary.left = rc.left + left_;
boundary.right = rc.right - right_;
}
//move this popup window
void CMySplitter::CPopup::OnMouseMove(UINT flag, CPoint pt)
{
CWnd::OnMouseMove(flag, pt);
GetCursorPos(&pt);
CRect rc;
GetWindowRect(&rc);
int x = pt.x - offset;
if (x > parent->boundary.left && x < parent->boundary.right)
SetWindowPos(NULL, x, rc.top, 0, 0, SWP_NOSIZE);
}
//hide popup window, let the parent dialog know
void CMySplitter::CPopup::OnLButtonUp(UINT flag, CPoint pt)
{
CWnd::OnLButtonUp(flag, pt);
ReleaseCapture();
ShowWindow(SW_HIDE);
CRect rc;
GetWindowRect(&rc);
parent->callback(rc.left);
}
BEGIN_MESSAGE_MAP(CMySplitter::CPopup, CWnd)
ON_WM_CREATE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()
BEGIN_MESSAGE_MAP(CMySplitter, CWnd)
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
Usage:
Add a static control with IDC_STATIC1 to the dialog and use as follows.
The code below has a main dialog CMyDialog with IDD_DIALOG, normal dialog
It has two child dialogs, child1 and child2 with IDD_PAGE1 and IDD_PAGE2
IDD_PAGE1 and IDD_PAGE2 are dialog resources with "child" style (not popup)
class CMyDialog : public CDialogEx
{
public:
class CChild1 : public CDialogEx
{
};
class CChild2 : public CDialogEx
{
};
CChild1 child1;
CChild1 child2;
//respond to gripper resize
void respond(int position)
{
CRect rs;
m_splitter.GetWindowRect(&rs);
rs.MoveToX(position);
ScreenToClient(&rs);
CRect rc;
GetClientRect(&rc);
CRect r1(0, 0, rs.left, rc.bottom);
CRect r2(rs.right, 0, rc.right, rc.bottom);
child1.MoveWindow(r1, TRUE);
child2.MoveWindow(r2, TRUE);
m_splitter.MoveWindow(rs, TRUE);
m_splitter.Invalidate(TRUE);
}
CMySplitter m_splitter;
BOOL OnInitDialog()
{
CDialogEx::OnInitDialog();
child1.Create(IDD_PAGE1, this);
child2.Create(IDD_PAGE2, this);
m_splitter.SubclassDlgItem(IDC_STATIC1, this);
m_splitter.SetRange(50, 50);
m_splitter.callback = std::bind(&CMyDialog::respond, this, std::placeholders::_1);
//width for splitter
int dx = 10;
CRect rc;
GetClientRect(&rc);
CRect r1(0, 0, 200, rc.bottom);
CRect r2(r1.right + dx, 0, rc.right, rc.bottom);
CRect rs(r1.right, 10, r2.left, rc.bottom - 10);
child1.MoveWindow(r1);
child2.MoveWindow(r2);
m_splitter.MoveWindow(rs);
child1.ShowWindow(SW_SHOW);
child2.ShowWindow(SW_SHOW);
return TRUE;
}
...
};
The code
#include "stdafx.h"
#include "TestClass.h"
IMPLEMENT_DYNAMIC(TestClass, CStatic)
TestClass::TestClass()
{
}
void TestClass::Ini(CWnd* parent)
{
Create(L"hello world",WS_CHILD|WS_VISIBLE|SS_CENTER | SS_NOTIFY ,
CRect(0,0,50,50), parent, 200);
}
void TestClass::OnMouseMove(UINT nFlags, CPoint point)
{
CStatic::OnMouseMove(nFlags, point);
}
void TestClass::OnMouseLeave()
{
CStatic::OnMouseLeave();
}
TestClass::~TestClass()
{
}
BEGIN_MESSAGE_MAP(TestClass, CStatic)
ON_WM_MOUSEMOVE()
ON_WM_MOUSELEAVE()
END_MESSAGE_MAP()
As you can see I'm using SS_NOTIFY and I can not get the OnMouseLeave event, but OnMouseMove working without any problems.
Note:
I creating a custom window so I removed the title bar.
If you want to handle the mouse leave and mouse hover event you have to call TrackMouseEvent in the OnMouseMove function.
void TestClass::OnMouseMove(UINT nFlags, CPoint point)
{
TRACKMOUSEEVENT MouseBehaviour;
CStatic::OnMouseMove(nFlags, point);
MouseBehaviour.cbSize = sizeof(TRACKMOUSEEVENT);
MouseBehaviour.dwFlags = TME_HOVER | TME_LEAVE;
MouseBehaviour.hwndTrack = GetSafeHwnd();
MouseBehaviour.dwHoverTime = HOVER_DEFAULT;
TrackMouseEvent(&MouseBehaviour);
}
I've created a new dialog in my MFC dialog based application. the new dialog contains 5 control buttons.
the following happens and I don't understand why?
click on buttonX. (result ok, OnBnClicked message is sent)
click on on any place of the application, but not on the dialog.(removing focus from dialog)
click again on buttonX (FAILED, OnBnClicked message is NOT sent). but if instead I click on any other button in the dialog (result ok, OnBnClicked message is sent).
and when I do:
...
...
click on the dialog area just to set focus on the dialog again
click again on buttonX. (result ok, OnBnClicked message is sent)
**I need to do step 3 only if I want to click again on the buttonX! why??
I think it related to SetFocus() but I m not sure how.
the buttons IDC are:
IDC_BACK_MEDIA_PRESS_BUTTON 1180
IDC_TOOLS_LEFT_RIGHT 1024
IDC_MEDIA_FOREWARD_BUTTON 1103
IDC_MEDIA_BACKWARD_BUTTON 1104
IDC_TOOLS_HOOD_BUTTON 2346
the dialog properties is:
IDD_TOOLS_DIALOG DIALOGEX 0, 0, 51, 218
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Tools"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
PUSHBUTTON "Media &Foreward",IDC_MEDIA_FOREWARD_BUTTON,7,79,37,36,BS_MULTILINE
PUSHBUTTON "&Media &BackWard",IDC_MEDIA_BACKWARD_BUTTON,7,43,37,36,BS_MULTILINE
PUSHBUTTON "Back Media Press",IDC_BACK_MEDIA_PRESS_BUTTON,7,127,37,36,BS_MULTILINE | NOT WS_VISIBLE
PUSHBUTTON "Hood",IDC_TOOLS_HOOD_BUTTON,7,7,37,36
PUSHBUTTON "Left Right",IDC_TOOLS_LEFT_RIGHT,7,175,37,36
END
I've tried different style like, tool windows, overlapped, popup. it happens in all the cases.
Thanks for the help.
.h
class CToolsDlg : public CBDialog
{
DECLARE_DYNAMIC(CToolsDlg)
public:
CToolsDlg(CWnd* pParent = NULL); // standard constructor
virtual ~CToolsDlg();
CToolTipCtrl m_ToolsTips;
// Dialog Data
enum { IDD = IDD_TOOLS_DIALOG };
protected:
virtual void OnCancel();
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
public:
CMFCButton m_HoodButton;
CMFCButton m_MediaForewardButton;
CMFCButton m_MediaBackwardButton;
CMFCButton m_LeftRightButton;
virtual BOOL OnInitDialog();
virtual BOOL PreTranslateMessage(MSG* pMsg);
afx_msg void OnTimer(UINT_PTR nIDEvent);
afx_msg void OnBnClickedCancel();
afx_msg void OnBnClickedToolsHoodButton();
afx_msg void OnBnClickedMediaForewardButton();
afx_msg void OnBnClickedMediaBackwardButton();
afx_msg void OnBnClickedLeftRightButton();
afx_msg void OnBnClickedBackMediaPressButton();
};
.cpp
IMPLEMENT_DYNAMIC(CToolsDlg, CBDialog)
CToolsDlg::CToolsDlg(CWnd* pParent /*=NULL*/)
: CBDialog(CToolsDlg::IDD, pParent)
{
}
CToolsDlg::~CToolsDlg()
{
}
void CToolsDlg::DoDataExchange(CDataExchange* pDX)
{
CBDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_TOOLS_HOOD_BUTTON, m_HoodButton);
DDX_Control(pDX, IDC_MEDIA_FOREWARD_BUTTON, m_MediaForewardButton);
DDX_Control(pDX, IDC_MEDIA_BACKWARD_BUTTON, m_MediaBackwardButton);
DDX_Control(pDX, IDC_TOOLS_LEFT_RIGHT, m_LeftRightButton);
}
BEGIN_MESSAGE_MAP(CToolsDlg, CBDialog)
ON_WM_CLOSE()
ON_WM_DESTROY()
ON_WM_TIMER()
ON_BN_CLICKED(IDC_TOOLS_HOOD_BUTTON, &CToolsDlg::OnBnClickedToolsHoodButton)
ON_BN_CLICKED(IDC_MEDIA_FOREWARD_BUTTON, &CToolsDlg::OnBnClickedMediaForewardButton)
ON_BN_CLICKED(IDC_MEDIA_BACKWARD_BUTTON, &CToolsDlg::OnBnClickedMediaBackwardButton)
ON_BN_CLICKED(IDC_TOOLS_LEFT_RIGHT, &CToolsDlg::OnBnClickedLeftRightButton)
ON_BN_CLICKED(IDC_BACK_MEDIA_PRESS_BUTTON, &CToolsDlg::OnBnClickedBackMediaPressButton)
END_MESSAGE_MAP()
// CToolsDlg message handlers
BOOL CToolsDlg::OnInitDialog()
{
CBDialog::OnInitDialog();
// Window position
//////////////////////////////////////////////////////////////////////////
CMainFrame* mf = (CMainFrame*)AfxGetMainWnd();
RECT MFwinRect;
RECT ThiswinRect;
CWnd* fv = mf->m_wndSplitter.GetView( mf->m_wndSplitter.GetCurrentViewIndex(0,0) );
fv->GetWindowRect(&MFwinRect);
GetWindowRect(&ThiswinRect);
MoveWindow(
MFwinRect.right - (ThiswinRect.right - ThiswinRect.left) - 14, // X
MFwinRect.top + 14, // Y
(ThiswinRect.right - ThiswinRect.left), // nWidth
(ThiswinRect.bottom - ThiswinRect.top) ); // nHeight
// Set controls state
//////////////////////////////////////////////////////////////////////////
m_ToolsTips.Create(this);
m_ToolsTips.AddTool(&m_HoodButton, TOOLTIP_HOOD_BUTTON);
m_ToolsTips.AddTool(&m_MediaForewardButton, TOOLTIP_MEDIA_FOREWARD_BUTTON);
m_ToolsTips.AddTool(&m_MediaBackwardButton, TOOLTIP_MEDIA_BACKWARD_BUTTON);
m_ToolsTips.AddTool(&m_LeftRightButton, TOOLTIP_LEFT_RIGHT_BUTTON);
m_ToolsTips.SetDelayTime(1000);
m_ToolsTips.Activate(BARAK_PREFS->m_Params.m_bShowToolTips);
// Main timer loop (no need for now)
// SetTimer( 1, 1000, NULL );
return TRUE;
}
BOOL CToolsDlg::PreTranslateMessage(MSG* pMsg)
{
m_ToolsTips.RelayEvent(pMsg);
return CBDialog::PreTranslateMessage(pMsg);
}
void CToolsDlg::OnCancel()
{
// When closing the window, destroy it and not only hide (its a floating window).
DestroyWindow();
}
void CToolsDlg::OnTimer(UINT_PTR nIDEvent)
{
CBDialog::OnTimer(nIDEvent);
}
void CToolsDlg::OnBnClickedToolsHoodButton()
{
...
}
void CToolsDlg::OnBnClickedMediaForewardButton()
{
...
}
void CToolsDlg::OnBnClickedMediaBackwardButton()
{
...
}
void CToolsDlg::OnBnClickedLeftRightButton()
{
...
}
void CToolsDlg::OnBnClickedBackMediaPressButton()
{
...
}
I see that you are filling view with dialog content. Have you put focusing to your dialog? I think this mystic behavior happening only on first mouse click in your dialog (then dialog gets the focus). I'm just guessing :)