/*!
 *  This function modifies a window to enable resizing functionality.
 *  This affects the window style, size, system menu and appearance.
 *  
 *  @param lpCreateStruct Pointer to a @c CREATESTRUCT structure, usually
 *         passed by the system to the window procedure in a @c WM_CREATE
 *         or @c WM_NCCREATE
 *  
 *  @remarks The function is intended to be called only inside a @c WM_CREATE
 *           or @c WM_NCCREATE message handler.
 */
void CResizableLayout::MakeResizable(LPCREATESTRUCT lpCreateStruct)
{
	if (lpCreateStruct->style & WS_CHILD)
		return;

	CWnd* pWnd = GetResizableWnd();

#if (_WIN32_WINNT >= 0x0501 && !defined(RSZLIB_NO_XP_DOUBLE_BUFFER))
	// enable double-buffering on supported platforms
	pWnd->ModifyStyleEx(0, WS_EX_COMPOSITED);
#endif

	if (!(lpCreateStruct->style & WS_THICKFRAME))
	{
		// set resizable style
		pWnd->ModifyStyle(DS_MODALFRAME, WS_THICKFRAME);
		// keep client area
		CRect rect(CPoint(lpCreateStruct->x, lpCreateStruct->y),
			CSize(lpCreateStruct->cx, lpCreateStruct->cy));
		pWnd->SendMessage(WM_NCCALCSIZE, FALSE, (LPARAM)&rect);
		// adjust size to reflect new style
		::AdjustWindowRectEx(&rect, pWnd->GetStyle(),
			::IsMenu(pWnd->GetMenu()->GetSafeHmenu()), pWnd->GetExStyle());
		pWnd->SetWindowPos(NULL, 0, 0, rect.Width(), rect.Height(),
			SWP_NOSENDCHANGING|SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOREPOSITION);
		// update dimensions
		lpCreateStruct->cx = rect.Width();
		lpCreateStruct->cy = rect.Height();
	}
}
예제 #2
0
void CMainFrame::OnCwndDeletefilemenu()
{
   // This example deletes the leftmost popup menu or leftmost
   // popup menu item from the application's main window.
   CWnd* pMain = AfxGetMainWnd();

   // The main window _can_ be NULL, so this code
   // doesn't ASSERT and actually tests.
   if (pMain != NULL)
   {
      // Get the main window's menu
      CMenu* pMenu = pMain->GetMenu();

      // If there is a menu and it has items, we'll
      // delete the first one.
      if (pMenu != NULL && pMenu->GetMenuItemCount() > 0)
      {
         pMenu->DeleteMenu(0, MF_BYPOSITION);
         // force a redraw of the menu bar
         pMain->DrawMenuBar();
      }

      // No need to delete pMenu because it is an MFC
      // temporary object.
   }
}
////////////////////////////////////////////////////////////////////////////////////
////////////				ImageProcessing Menu Interfaces            /////////////
////////////////////////////////////////////////////////////////////////////////////
void CFPAnalysisView::OnEditUndo() 
{
  CWnd* pMain = GetParent();
  CFPAnalysisDoc* pDoc = GetDocument();
  CString szTitle = currentimage.GetFilename();

  if (pMain != NULL)
  {
	CMenu* pMenu = pMain->GetMenu();
	UINT state = pMenu->GetMenuState(ID_EDIT_UNDO, MF_BYCOMMAND);
	ASSERT(state != 0xFFFFFFFF);
		
	if (state & MF_GRAYED)
	{
			// do nothing if undo is grayed
	}
	else
	{
	   currentimage.SetOperationType(UNDO);
       currentimage.go();
	   pDoc->SetTitle(szTitle);  // if UNDO set caption to the filename
       pMenu->EnableMenuItem(ID_EDIT_UNDO, MF_DISABLED | MF_GRAYED); //disable undo
       Invalidate(TRUE);
	}
	
  }

}
void CFPAnalysisView::OnFileSave() 
{
  if (currentimage.OK())
	{
		if(AfxMessageBox("This will overwrite your existing file.", MB_ICONEXCLAMATION | MB_OKCANCEL)==IDOK)
		{
			
			CString sFilename = currentimage.GetFilename();
			CString sExt = sFilename.Right(3);

			if (!sExt.CompareNoCase("BMP"))
				currentimage.SaveBMP(sFilename);

			// disable undo after save	
			CWnd* pMain = GetParent();
			if (pMain != NULL)
			{
				CMenu* pMenu = pMain->GetMenu();
				pMenu->EnableMenuItem(ID_EDIT_UNDO, MF_DISABLED | MF_GRAYED);
			}

			Invalidate(TRUE);					// Refresh the entire view	
			
		}
	}	
}
void CFPAnalysisView::OnFileSaveAs() 
{
   if (currentimage.OK())
	{
		CString sFilename = currentimage.GetFilename();
		CString sFilt="BMP (*.bmp)|*.bmp||";

		CFileDialog dlg(
			FALSE,							// Create a save as file dialog
			"*.BMP",						// Default file extension
			sFilename,						// Filename
			OFN_HIDEREADONLY| 				// Flags - don't show the read only check box
			OFN_FILEMUSTEXIST|				//       - make sure file exists
			OFN_OVERWRITEPROMPT,			//       - ask about overwrite if file exists
			sFilt);							// the file filter

		if (dlg.DoModal()==IDOK)
		{
			sFilename = dlg.GetPathName();
			CString sExt = dlg.GetFileExt();
			CString sFilenameShort= dlg.GetFileName();

			CFPAnalysisDoc* pDoc = GetDocument();


			if (!sExt.CompareNoCase("BMP"))
			{
				currentimage.SetFilename(sFilename);
				currentimage.SaveBMP(sFilename);
				pDoc->SetTitle(sFilenameShort);
			}

			// disable undo after save	
			CWnd* pMain = AfxGetMainWnd();
			if (pMain != NULL)
			{
				CMenu* pMenu = pMain->GetMenu();
				pMenu->EnableMenuItem(ID_EDIT_UNDO, MF_DISABLED|MF_GRAYED);
			}

			Invalidate(TRUE);				// Refresh the entire view	

		}
	}	
}
예제 #6
0
extern "C" 	STEP_API HMENU WINAPI STEPGetMenu(UINT nType)
{
	CWnd	*pMainWnd = AfxGetMainWnd();
	CMenu	*STEP_hMenu = pMainWnd ? pMainWnd->GetMenu() : NULL;
	CMenu* subMenu;
	switch (nType) {
	case MENU_FILE:
		subMenu = STEP_hMenu->GetSubMenu(0);
		return subMenu->m_hMenu;
	case MENU_EDIT:
		subMenu = STEP_hMenu->GetSubMenu(1);
		return subMenu->m_hMenu;
	case MENU_DISP:
		subMenu = STEP_hMenu->GetSubMenu(2);
		return subMenu->m_hMenu;
	case MENU_CONV:
		subMenu = STEP_hMenu->GetSubMenu(3);
		return subMenu->m_hMenu;
	case MENU_PLAYLIST:
		subMenu = STEP_hMenu->GetSubMenu(4);
		return subMenu->m_hMenu;
	case MENU_PLAYER:
		subMenu = STEP_hMenu->GetSubMenu(5);
		return subMenu->m_hMenu;
	case MENU_OPTION:
		subMenu = STEP_hMenu->GetSubMenu(6);
		return subMenu->m_hMenu;
/*
	case MENU_OPTION_PLUGIN:
		subMenu = STEP_hMenu->GetSubMenu(6);
		subMenu = subMenu->GetSubMenu(13);
		return subMenu->m_hMenu;
*/
	case MENU_HELP:
		subMenu = STEP_hMenu->GetSubMenu(6);
		return subMenu->m_hMenu;
	}
	return NULL;
}
예제 #7
0
void CFileManagerDlg::OnInitMenuPopup(CMenu* pMenu, UINT nIndex, BOOL bSysMenu)
{
  // 	CDialogEx::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
  AfxCancelModes(m_hWnd);

  if (bSysMenu)
    return;     // don't support system menu

  ENSURE_VALID(pMenu);

  // check the enabled state of various menu items

  CCmdUI state;
  state.m_pMenu = pMenu;
  ASSERT(state.m_pOther == NULL);
  ASSERT(state.m_pParentMenu == NULL);

  // determine if menu is popup in top-level menu and set m_pOther to
  //  it if so (m_pParentMenu == NULL indicates that it is secondary popup)
  HMENU hParentMenu;
  if (AfxGetThreadState()->m_hTrackingMenu == pMenu->m_hMenu)
    state.m_pParentMenu = pMenu;    // parent == child for tracking popup
  else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
  {
    CWnd* pParent = GetTopLevelParent();
    // child windows don't have menus -- need to go to the top!
    if (pParent != NULL &&
      (hParentMenu = pParent->GetMenu()->GetSafeHmenu()) != NULL)
    {
      int nIndexMax = ::GetMenuItemCount(hParentMenu);
      for (int nItemIndex = 0; nItemIndex < nIndexMax; nItemIndex++)
      {
        if (::GetSubMenu(hParentMenu, nItemIndex) == pMenu->m_hMenu)
        {
          // when popup is found, m_pParentMenu is containing menu
          state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
          break;
        }
      }
    }
  }

  state.m_nIndexMax = pMenu->GetMenuItemCount();
  for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
    state.m_nIndex++)
  {
    state.m_nID = pMenu->GetMenuItemID(state.m_nIndex);
    if (state.m_nID == 0)
      continue; // menu separator or invalid cmd - ignore it

    ASSERT(state.m_pOther == NULL);
    ASSERT(state.m_pMenu != NULL);
    if (state.m_nID == (UINT)-1)
    {
      // possibly a popup menu, route to first item of that popup
      state.m_pSubMenu = pMenu->GetSubMenu(state.m_nIndex);
      if (state.m_pSubMenu == NULL ||
        (state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
        state.m_nID == (UINT)-1)
      {
        continue;       // first item of popup can't be routed to
      }
      state.DoUpdate(this, FALSE);    // popups are never auto disabled
    }
    else
    {
      // normal menu item
      // Auto enable/disable if frame window has 'm_bAutoMenuEnable'
      //    set and command is _not_ a system command.
      state.m_pSubMenu = NULL;
      state.DoUpdate(this, state.m_nID < 0xF000);
    }

    // adjust for menu deletions and additions
    UINT nCount = pMenu->GetMenuItemCount();
    if (nCount < state.m_nIndexMax)
    {
      state.m_nIndex -= (state.m_nIndexMax - nCount);
      while (state.m_nIndex < nCount &&
        pMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
      {
        state.m_nIndex++;
      }
    }
    state.m_nIndexMax = nCount;
  }
}