Click here to Skip to main content
15,917,061 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: iSeries AS400 APIs Pin
Camron12-Aug-05 5:03
Camron12-Aug-05 5:03 
GeneralRe: iSeries AS400 APIs Pin
David Crow12-Aug-05 5:14
David Crow12-Aug-05 5:14 
Questionsend/recv help? Pin
KellyR11-Aug-05 10:55
KellyR11-Aug-05 10:55 
AnswerRe: send/recv help? Pin
fakefur11-Aug-05 13:46
fakefur11-Aug-05 13:46 
GeneralRe: send/recv help? Pin
KellyR11-Aug-05 14:20
KellyR11-Aug-05 14:20 
GeneralRe: send/recv help? Pin
KellyR11-Aug-05 15:52
KellyR11-Aug-05 15:52 
GeneralRe: send/recv help? Pin
Jose Lamas Rios11-Aug-05 15:53
Jose Lamas Rios11-Aug-05 15:53 
GeneralPrevent CDialog activation. Pin
mintguy11-Aug-05 10:51
mintguy11-Aug-05 10:51 
In an MFC application, how can I prevent a modeless CDialog from becoming the active window?

Look at the example code - I'm fading in a CWnd, and it fades away unless the user hovers over it. if the user ignores it the window fades away and the program exits. I want to acheive the same thing but with a CDialog so that I can use a dialog template but I can't find a way of preventing the dialog from becomming active. If there is a way to use a dialog template for a vanilla CWnd this would serve the same purpose.

<code>
#include <afxwin.h>         // MFC core and standard components
#include <afxext.h>         // MFC extensions

#include "resource.h" // defines IDR_MAINFRAME 

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

class CTinyApp : public CWinApp
{
public:
     virtual BOOL InitInstance();
     BOOL RegisterWNDCLASS();
};

CTinyApp theApp;

BOOL CTinyApp::RegisterWNDCLASS()
{
     WNDCLASS wndclass;

     wndclass.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
     wndclass.lpfnWndProc = ::DefWindowProc;
     wndclass.cbClsExtra = 0;
     wndclass.cbWndExtra = 0;
     wndclass.hInstance = AfxGetInstanceHandle();
     wndclass.hIcon = LoadIcon(IDR_MAINFRAME);
     // or load a different icon
     wndclass.hCursor = LoadCursor( IDC_ARROW );
     wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
     wndclass.lpszMenuName = NULL;
     wndclass.lpszClassName = "MyTinyWnd";

     if( !AfxRegisterClass( &wndclass ))
     {
          TRACE("Window class MyTinyWnd could not be registered.\n");
          return FALSE;
     }
     return TRUE;
}

class CTinyWnd : public CWnd
{
     DECLARE_DYNAMIC(CTinyWnd)
public:
     CTinyWnd();
     void ComeAlive();

protected:
     DECLARE_MESSAGE_MAP();
public:
     afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
     afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
     afx_msg void OnTimer(UINT nIDEvent);
     afx_msg void OnBnClickedOk();
     afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
     afx_msg void OnMouseMove(UINT nFlags, CPoint point);
     afx_msg void OnNcMouseMove(UINT nHitTest, CPoint point);

     int m_nTimer;
     int m_nLevel;

     CButton m_cOKButton;
     CFont m_Font;
};
IMPLEMENT_DYNAMIC(CTinyWnd, CWnd)

BEGIN_MESSAGE_MAP(CTinyWnd, CWnd)
ON_WM_TIMER()
ON_WM_SHOWWINDOW()
ON_WM_ACTIVATE()
ON_WM_CREATE()
ON_WM_NCMOUSEMOVE()
ON_WM_MOUSEMOVE()
ON_BN_CLICKED(IDOK, OnBnClickedOk)
END_MESSAGE_MAP()

CTinyWnd::CTinyWnd() : m_nTimer(-1), m_nLevel(3)
{     
}

void CTinyWnd::ComeAlive()
{
     if (m_nTimer != -1)
     {
          KillTimer(m_nTimer);
          m_nTimer = -1;
     }

     ModifyStyleEx(WS_EX_LAYERED,0);
}

void CTinyWnd::OnBnClickedOk()
{
     KillTimer(m_nTimer);
     m_nTimer = -1;
     DestroyWindow();
     delete this;
}

void CTinyWnd::OnTimer(UINT nIDEvent)
{
     CWnd::OnTimer(nIDEvent);

     static bool bDir = true;

     if (m_nTimer == nIDEvent)
     {
          if (bDir)
               m_nLevel+=2; // fade in quick
          else
               m_nLevel--; // fade out slow

          if (m_nLevel > 3)
          {
               if (m_nLevel > 254)
                    bDir = !bDir;

               SetLayeredWindowAttributes(0, m_nLevel, LWA_ALPHA);
               RedrawWindow(NULL, NULL, RDW_ERASE|RDW_INVALIDATE|RDW_FRAME|RDW_ALLCHILDREN);
          }
          else
          {
               KillTimer(m_nTimer);
               m_nTimer = -1;
               DestroyWindow();
               delete this;
          }
     }
}

int CTinyWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
     if (CWnd::OnCreate(lpCreateStruct) == -1)
          return -1;

     m_cOKButton.Create("OK",
          WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_TEXT,
          CRect(60,20,140,60),
          this,
          IDOK);

     m_Font.CreatePointFont(80,"MS Shell Dlg");
     m_cOKButton.SetFont(&m_Font);

     return 0;
}

void CTinyWnd::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
     CWnd::OnActivate(nState, pWndOther, bMinimized);
     ComeAlive();
}

void CTinyWnd::OnShowWindow(BOOL bShow, UINT nStatus)
{
     CWnd::OnShowWindow(bShow, nStatus);

     static bool bFirst = true;

     if (bFirst)
     {
          bFirst = false;
          m_nLevel = 3;
          SetLayeredWindowAttributes(0, m_nLevel, LWA_ALPHA);

          m_nTimer = (int)SetTimer(1,50, NULL);
     }
}

void CTinyWnd::OnMouseMove(UINT nFlags, CPoint point)
{
     static bool bFirst = true;
     if (bFirst)
     {
          ComeAlive();
          bFirst = false;
     }
}

void CTinyWnd::OnNcMouseMove(UINT nHitTest, CPoint point)
{
     static bool bFirst = true;
     if (bFirst)
     {
          ComeAlive();
          bFirst = false;
     }
}


BOOL CTinyApp::InitInstance()
{
     RegisterWNDCLASS();

     CTinyWnd* pWnd = new CTinyWnd;

     BOOL bCreate = pWnd->CreateEx(WS_EX_TOOLWINDOW|WS_EX_LAYERED,
               "MyTinyWnd",
               "Popup Message",
               WS_BORDER|WS_POPUP|WS_CAPTION,
               CRect(200,200,400,300),
               NULL, 
               0, 0);

     if (!bCreate)
     {
          delete pWnd;
          return FALSE;
     }

     m_pMainWnd = pWnd;

     m_pMainWnd->ShowWindow(SW_SHOWNA);     
     m_pMainWnd->UpdateWindow();
     return TRUE;
}    
</code> 

GeneralRe: Prevent CDialog activation. Pin
Jose Lamas Rios11-Aug-05 15:39
Jose Lamas Rios11-Aug-05 15:39 
GeneralRe: Prevent CDialog activation. Pin
ThatsAlok11-Aug-05 18:26
ThatsAlok11-Aug-05 18:26 
GeneralRe: Prevent CDialog activation. Pin
mintguy11-Aug-05 20:21
mintguy11-Aug-05 20:21 
GeneralRe: Prevent CDialog activation. Pin
ThatsAlok11-Aug-05 20:34
ThatsAlok11-Aug-05 20:34 
GeneralRe: Prevent CDialog activation. Pin
mintguy11-Aug-05 20:56
mintguy11-Aug-05 20:56 
GeneralRe: Prevent CDialog activation. Pin
ThatsAlok11-Aug-05 22:45
ThatsAlok11-Aug-05 22:45 
GeneralRe: Prevent CDialog activation. Pin
mintguy11-Aug-05 20:23
mintguy11-Aug-05 20:23 
GeneralRe: Prevent CDialog activation. Pin
Jose Lamas Rios11-Aug-05 20:46
Jose Lamas Rios11-Aug-05 20:46 
GeneralRe: Prevent CDialog activation. Pin
mintguy11-Aug-05 20:54
mintguy11-Aug-05 20:54 
GeneralApplication crash due to change in compiler settings Pin
ComplexLifeForm11-Aug-05 10:01
ComplexLifeForm11-Aug-05 10:01 
GeneralRe: Application crash due to change in compiler settings Pin
geo_m13-Aug-05 21:58
geo_m13-Aug-05 21:58 
GeneralWaiting for a command to complete Pin
jet91511-Aug-05 8:46
jet91511-Aug-05 8:46 
GeneralRe: Waiting for a command to complete Pin
David Crow11-Aug-05 9:01
David Crow11-Aug-05 9:01 
GeneralRe: Waiting for a command to complete Pin
Garth J Lancaster11-Aug-05 12:34
professionalGarth J Lancaster11-Aug-05 12:34 
Generalneed help with windbg Pin
valerie9911-Aug-05 7:45
valerie9911-Aug-05 7:45 
GeneralRe: need help with windbg Pin
David Crow11-Aug-05 8:15
David Crow11-Aug-05 8:15 
GeneralRe: need help with windbg Pin
valerie9911-Aug-05 8:50
valerie9911-Aug-05 8:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.