Keep window derived from CView always on top





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I want to emulate the behaviour of a modal diaolg in my propertysheet so that it will always remain on top, and no other action out of the propertysheet can be taken untill the sheet is closed.
I have the following class structure;



class ViewPSheet : public CView
{
protected:
ViewPSheet();
DECLARE_DYNCREATE(ViewPSheet)

// Overrides
public:
virtual void WinHelp(DWORD dwData, UINT nCmd = HELP_CONTEXT);
protected:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
virtual void OnInitialUpdate(); // called first time after construct
virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
virtual void OnActivateFrame(UINT nState, CFrameWnd* /*pFrameWnd*/);

// Generated message map functions
protected:
afx_msg void OnDestroy();
afx_msg void OnSetFocus(CWnd* pOldWnd);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
DECLARE_MESSAGE_MAP()
};


class SheetDim : public ViewPSheet
{
protected:
SheetDim(); // protected constructor used by dynamic creation
DECLARE_DYNCREATE(SheetDim)

// Operations
public:
protected:
virtual void OnInitialUpdate(); // called first time after construct
virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint);

protected:
virtual ~SheetDim();

public:
void OnApplyNow();
void OnCancel();
void OnOK();

// Generated message map functions
protected:
DECLARE_MESSAGE_MAP()
};


The SheetDimclass acts as a property page holder and has several CPropertyPage classes added in the OnInitialUpdate().
I tried using the following methods to get the propertysheet ontop, including trying out the commented lines.



void SheetDim::OnActivateView(
BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
ViewPSheet::OnActivateView(bActivate, pActivateView, pDeactiveView);
if (bActivate == WA_INACTIVE)
{
::SetWindowPos( this->GetParent()->m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE );
//::SetWindowPos( this->GetParent()->m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
//::SetWindowPos( this->m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
}
}


But couldn't get the propertysheet to act like a modeless dialog. Is there a way to achieve this without changing ViewPSheet parent class?










share|improve this question




















  • 1





    You cannot derive a class from CView and turn it in to CPropertySheet. You have to derive from CPropertySheet. Then add CPropertyPage objects to it, and open in modal mode with DoModal. See example. Or maybe you want to put a CView object in to a modal dialog or something?

    – Barmak Shemirani
    Jan 4 at 3:23


















0















I want to emulate the behaviour of a modal diaolg in my propertysheet so that it will always remain on top, and no other action out of the propertysheet can be taken untill the sheet is closed.
I have the following class structure;



class ViewPSheet : public CView
{
protected:
ViewPSheet();
DECLARE_DYNCREATE(ViewPSheet)

// Overrides
public:
virtual void WinHelp(DWORD dwData, UINT nCmd = HELP_CONTEXT);
protected:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
virtual void OnInitialUpdate(); // called first time after construct
virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
virtual void OnActivateFrame(UINT nState, CFrameWnd* /*pFrameWnd*/);

// Generated message map functions
protected:
afx_msg void OnDestroy();
afx_msg void OnSetFocus(CWnd* pOldWnd);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
DECLARE_MESSAGE_MAP()
};


class SheetDim : public ViewPSheet
{
protected:
SheetDim(); // protected constructor used by dynamic creation
DECLARE_DYNCREATE(SheetDim)

// Operations
public:
protected:
virtual void OnInitialUpdate(); // called first time after construct
virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint);

protected:
virtual ~SheetDim();

public:
void OnApplyNow();
void OnCancel();
void OnOK();

// Generated message map functions
protected:
DECLARE_MESSAGE_MAP()
};


The SheetDimclass acts as a property page holder and has several CPropertyPage classes added in the OnInitialUpdate().
I tried using the following methods to get the propertysheet ontop, including trying out the commented lines.



void SheetDim::OnActivateView(
BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
ViewPSheet::OnActivateView(bActivate, pActivateView, pDeactiveView);
if (bActivate == WA_INACTIVE)
{
::SetWindowPos( this->GetParent()->m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE );
//::SetWindowPos( this->GetParent()->m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
//::SetWindowPos( this->m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
}
}


But couldn't get the propertysheet to act like a modeless dialog. Is there a way to achieve this without changing ViewPSheet parent class?










share|improve this question




















  • 1





    You cannot derive a class from CView and turn it in to CPropertySheet. You have to derive from CPropertySheet. Then add CPropertyPage objects to it, and open in modal mode with DoModal. See example. Or maybe you want to put a CView object in to a modal dialog or something?

    – Barmak Shemirani
    Jan 4 at 3:23














0












0








0








I want to emulate the behaviour of a modal diaolg in my propertysheet so that it will always remain on top, and no other action out of the propertysheet can be taken untill the sheet is closed.
I have the following class structure;



class ViewPSheet : public CView
{
protected:
ViewPSheet();
DECLARE_DYNCREATE(ViewPSheet)

// Overrides
public:
virtual void WinHelp(DWORD dwData, UINT nCmd = HELP_CONTEXT);
protected:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
virtual void OnInitialUpdate(); // called first time after construct
virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
virtual void OnActivateFrame(UINT nState, CFrameWnd* /*pFrameWnd*/);

// Generated message map functions
protected:
afx_msg void OnDestroy();
afx_msg void OnSetFocus(CWnd* pOldWnd);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
DECLARE_MESSAGE_MAP()
};


class SheetDim : public ViewPSheet
{
protected:
SheetDim(); // protected constructor used by dynamic creation
DECLARE_DYNCREATE(SheetDim)

// Operations
public:
protected:
virtual void OnInitialUpdate(); // called first time after construct
virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint);

protected:
virtual ~SheetDim();

public:
void OnApplyNow();
void OnCancel();
void OnOK();

// Generated message map functions
protected:
DECLARE_MESSAGE_MAP()
};


The SheetDimclass acts as a property page holder and has several CPropertyPage classes added in the OnInitialUpdate().
I tried using the following methods to get the propertysheet ontop, including trying out the commented lines.



void SheetDim::OnActivateView(
BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
ViewPSheet::OnActivateView(bActivate, pActivateView, pDeactiveView);
if (bActivate == WA_INACTIVE)
{
::SetWindowPos( this->GetParent()->m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE );
//::SetWindowPos( this->GetParent()->m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
//::SetWindowPos( this->m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
}
}


But couldn't get the propertysheet to act like a modeless dialog. Is there a way to achieve this without changing ViewPSheet parent class?










share|improve this question
















I want to emulate the behaviour of a modal diaolg in my propertysheet so that it will always remain on top, and no other action out of the propertysheet can be taken untill the sheet is closed.
I have the following class structure;



class ViewPSheet : public CView
{
protected:
ViewPSheet();
DECLARE_DYNCREATE(ViewPSheet)

// Overrides
public:
virtual void WinHelp(DWORD dwData, UINT nCmd = HELP_CONTEXT);
protected:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
virtual void OnInitialUpdate(); // called first time after construct
virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
virtual void OnActivateFrame(UINT nState, CFrameWnd* /*pFrameWnd*/);

// Generated message map functions
protected:
afx_msg void OnDestroy();
afx_msg void OnSetFocus(CWnd* pOldWnd);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
DECLARE_MESSAGE_MAP()
};


class SheetDim : public ViewPSheet
{
protected:
SheetDim(); // protected constructor used by dynamic creation
DECLARE_DYNCREATE(SheetDim)

// Operations
public:
protected:
virtual void OnInitialUpdate(); // called first time after construct
virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint);

protected:
virtual ~SheetDim();

public:
void OnApplyNow();
void OnCancel();
void OnOK();

// Generated message map functions
protected:
DECLARE_MESSAGE_MAP()
};


The SheetDimclass acts as a property page holder and has several CPropertyPage classes added in the OnInitialUpdate().
I tried using the following methods to get the propertysheet ontop, including trying out the commented lines.



void SheetDim::OnActivateView(
BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
ViewPSheet::OnActivateView(bActivate, pActivateView, pDeactiveView);
if (bActivate == WA_INACTIVE)
{
::SetWindowPos( this->GetParent()->m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE );
//::SetWindowPos( this->GetParent()->m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
//::SetWindowPos( this->m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
}
}


But couldn't get the propertysheet to act like a modeless dialog. Is there a way to achieve this without changing ViewPSheet parent class?







c++ mfc dialog modal-dialog propertysheet






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 11:20







Madz

















asked Jan 3 at 11:14









MadzMadz

66021131




66021131








  • 1





    You cannot derive a class from CView and turn it in to CPropertySheet. You have to derive from CPropertySheet. Then add CPropertyPage objects to it, and open in modal mode with DoModal. See example. Or maybe you want to put a CView object in to a modal dialog or something?

    – Barmak Shemirani
    Jan 4 at 3:23














  • 1





    You cannot derive a class from CView and turn it in to CPropertySheet. You have to derive from CPropertySheet. Then add CPropertyPage objects to it, and open in modal mode with DoModal. See example. Or maybe you want to put a CView object in to a modal dialog or something?

    – Barmak Shemirani
    Jan 4 at 3:23








1




1





You cannot derive a class from CView and turn it in to CPropertySheet. You have to derive from CPropertySheet. Then add CPropertyPage objects to it, and open in modal mode with DoModal. See example. Or maybe you want to put a CView object in to a modal dialog or something?

– Barmak Shemirani
Jan 4 at 3:23





You cannot derive a class from CView and turn it in to CPropertySheet. You have to derive from CPropertySheet. Then add CPropertyPage objects to it, and open in modal mode with DoModal. See example. Or maybe you want to put a CView object in to a modal dialog or something?

– Barmak Shemirani
Jan 4 at 3:23












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54021214%2fkeep-window-derived-from-cview-always-on-top%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54021214%2fkeep-window-derived-from-cview-always-on-top%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith