Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
4.9 KiB

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "shimgvwr.h"
  5. #include "MainFrm.h"
  6. #include "imagedoc.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. extern CPreviewApp theApp;
  13. static const TCHAR c_szDDEAppName[]= TEXT("ShellImageView");
  14. static const TCHAR c_szDDETopic[] = TEXT("ViewImage");
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CMainFrame
  17. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  18. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  19. //{{AFX_MSG_MAP(CMainFrame)
  20. // NOTE - the ClassWizard will add and remove mapping macros here.
  21. // DO NOT EDIT what you see in these blocks of generated code !
  22. ON_WM_CREATE()
  23. ON_MESSAGE(WM_DDE_INITIATE, OnDDEInitiate)
  24. ON_MESSAGE(WM_DDE_EXECUTE, OnDDEExecute)
  25. ON_MESSAGE(WM_DDE_TERMINATE, OnDDETerminate)
  26. //}}AFX_MSG_MAP
  27. END_MESSAGE_MAP()
  28. static UINT indicators[] =
  29. {
  30. ID_SEPARATOR, // status line indicator
  31. ID_INDICATOR_CAPS,
  32. ID_INDICATOR_NUM,
  33. ID_INDICATOR_SCRL,
  34. };
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CMainFrame construction/destruction
  37. CMainFrame::CMainFrame()
  38. {
  39. m_atomApp = m_atomTopic = NULL;
  40. }
  41. CMainFrame::~CMainFrame()
  42. {
  43. }
  44. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  45. {
  46. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  47. return -1;
  48. /* if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  49. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  50. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  51. {
  52. TRACE0("Failed to create toolbar\n");
  53. return -1; // fail to create
  54. }
  55. */
  56. if (!m_wndStatusBar.Create(this) ||
  57. !m_wndStatusBar.SetIndicators(indicators,
  58. sizeof(indicators)/sizeof(UINT)))
  59. {
  60. TRACE0("Failed to create status bar\n");
  61. return -1; // fail to create
  62. }
  63. /* m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  64. EnableDocking(CBRS_ALIGN_ANY);
  65. DockControlBar(&m_wndToolBar);
  66. */
  67. HWND *phwnd = reinterpret_cast<HWND*>(MapViewOfFile (theApp.m_hFileMap, FILE_MAP_WRITE, 0, 0, sizeof(HWND)));
  68. if (phwnd )
  69. {
  70. if (!*phwnd)
  71. {
  72. *phwnd = m_hWnd;
  73. }
  74. UnmapViewOfFile (phwnd);
  75. }
  76. return 0;
  77. }
  78. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  79. {
  80. m_atomApp = GlobalAddAtom(c_szDDEAppName);
  81. m_atomTopic = GlobalAddAtom(c_szDDETopic);
  82. if( !CFrameWnd::PreCreateWindow(cs) )
  83. return FALSE;
  84. // TODO: Modify the Window class or styles here by modifying
  85. // the CREATESTRUCT cs
  86. return TRUE;
  87. }
  88. /////////////////////////////////////////////////////////////////////////////
  89. // CMainFrame message handlers
  90. LRESULT
  91. CMainFrame::OnDDEInitiate(WPARAM wParam, LPARAM lParam)
  92. {
  93. // if we care about DDE then we have registered our atoms:
  94. if (m_atomApp && m_atomTopic)
  95. {
  96. ATOM atomApp = LOWORD(lParam);
  97. ATOM atomTopic = HIWORD(lParam);
  98. if (atomApp == m_atomApp)
  99. {
  100. if (NULL == atomTopic || atomTopic == m_atomTopic)
  101. {
  102. // if (NULL == atomTopic) send an ACK for every topic we know about.
  103. // if (atomTopic == m_atomTopic) send an ACK for this topic.
  104. // since we only know about one topic these two code paths are the same.
  105. ::SendMessage((HWND)wParam, WM_DDE_ACK, (WPARAM)m_hWnd, MAKELONG(m_atomApp,m_atomTopic));
  106. }
  107. }
  108. }
  109. return 0;
  110. }
  111. LRESULT
  112. CMainFrame::OnDDEExecute(WPARAM wParam, LPARAM lParam)
  113. {
  114. LPTSTR pszCommand = (LPTSTR)GlobalLock((HGLOBAL)lParam);
  115. if (pszCommand)
  116. {
  117. if (0 == StrCmpNI(pszCommand, TEXT("[open("), 6))
  118. {
  119. TCHAR szFilename[MAX_PATH];
  120. StrCpyN(szFilename, pszCommand+6, ARRAYSIZE(szFilename));
  121. // find the ending ')' and make it a NULL
  122. LPTSTR pszEnd = StrRChr(szFilename, NULL, TEXT(')'));
  123. if (pszEnd)
  124. *pszEnd = NULL;
  125. theApp.OpenDocumentFile(szFilename);
  126. }
  127. GlobalUnlock((HGLOBAL)lParam);
  128. }
  129. // Post an ACK back to the calling client, 0x8000=fAck
  130. LPARAM lpOut = ReuseDDElParam(lParam, WM_DDE_EXECUTE, WM_DDE_ACK, 0x00008000, (WPARAM)lParam);
  131. ::PostMessage((HWND)wParam, WM_DDE_ACK, (WPARAM)m_hWnd, lpOut);
  132. return 0;
  133. }
  134. LRESULT
  135. CMainFrame::OnDDETerminate(WPARAM wParam, LPARAM lParam)
  136. {
  137. ::PostMessage((HWND)wParam, WM_DDE_TERMINATE, (WPARAM)m_hWnd, 0);
  138. return 0;
  139. }
  140. /////////////////////////////////////////////////////////////////////////////
  141. // CMainFrame diagnostics
  142. #ifdef _DEBUG
  143. void CMainFrame::AssertValid() const
  144. {
  145. CFrameWnd::AssertValid();
  146. }
  147. void CMainFrame::Dump(CDumpContext& dc) const
  148. {
  149. CFrameWnd::Dump(dc);
  150. }
  151. #endif //_DEBUG
  152. /////////////////////////////////////////////////////////////////////////////
  153. // CMainFrame message handlers