ShrinkingPropSheet.cpp
上传用户:ledjyj
上传日期:2019-03-13
资源大小:36k
文件大小:6k
源码类别:

工具条

开发平台:

Visual C++

  1. // ShrinkingPropSheet.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "tab_dlg_bar.h"
  5. #include "ShrinkingPropSheet.h"
  6. #include ".shrinkingpropsheet.h"
  7. // CShrinkingPropSheet
  8. IMPLEMENT_DYNAMIC(CShrinkingPropSheet, CPropertySheet)
  9. CShrinkingPropSheet::CShrinkingPropSheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
  10. :CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
  11. {
  12. }
  13. CShrinkingPropSheet::CShrinkingPropSheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
  14. :CPropertySheet(pszCaption, pParentWnd, iSelectPage)
  15. {
  16. }
  17. CShrinkingPropSheet::~CShrinkingPropSheet()
  18. {
  19. }
  20. BEGIN_MESSAGE_MAP(CShrinkingPropSheet, CPropertySheet)
  21. END_MESSAGE_MAP()
  22. // CShrinkingPropSheet message handlers
  23. BOOL CShrinkingPropSheet::OnInitDialog()
  24. {
  25.   // Inherited call
  26. BOOL bResult = CPropertySheet::OnInitDialog();
  27.    // Modifying exstyle in create method doesn't seem to work :-?, I guess
  28.    // DIALOGEX property sheets are not very well supported (if at all)
  29.    // We cannot access here the exstyle passed at creation time (dlgprop.cpp
  30.    // stores temporaly in AfxGetThreadState()->m_dwPropStyle, but when OnInitDialog
  31.    // is called that variable can have been overwritten
  32. /*
  33. The following causes the property sheet simply not to appear??? NO, it just can't be tabbed to, and is at back
  34. */
  35. // don't need this for dlgBar
  36. //ModifyStyleEx(0, WS_EX_TOOLWINDOW);
  37.    // Resize property sheet and tab ctrl to exactly fit the page, as by default
  38.    // PropertyPages have a non-sense minimum width of 214DLUs (MS dixit) 
  39.    // Height has also a minimum size.
  40.    
  41.    // There must be at least one property page, so safe accessing it is not needed
  42.    // (if it has no pages MFC will not show the PropertySheet)
  43.    CPropertyPage* pppg = GetActivePage();
  44.    // Get the resource for first page (all pages are assumed to be of the same 
  45.    // dimensions).
  46.    HRSRC hrsrc;
  47.    if (AfxIsValidString(pppg->m_psp.pszTemplate))
  48.       hrsrc = FindResource(pppg->m_psp.hInstance, pppg->m_psp.pszTemplate, RT_DIALOG);
  49.    else
  50.       hrsrc = FindResource(pppg->m_psp.hInstance,
  51.                            MAKEINTRESOURCE(pppg->m_psp.pszTemplate), RT_DIALOG);
  52.    // If found, we can resize the page (which was resized at creation time by MFC's), 
  53.    // It suffices modifying the layout here, as once the first page is added, MFC never
  54.    // resizes the dialog again to fit MS's minimum sizes of PropertyPages (even if you add
  55.    // new pages with AddPage() )
  56.    if (hrsrc) {
  57.       HGLOBAL hgbl = LoadResource(pppg->m_psp.hInstance, hrsrc);
  58.       if (hgbl) {
  59.          LPDLGTEMPLATE pdlgtpl;
  60.          pdlgtpl = (LPDLGTEMPLATE) LockResource(hgbl);
  61.          if (pdlgtpl) {
  62.             DLGTEMPLATEEX* pdlgtplex = (DLGTEMPLATEEX*) pdlgtpl;
  63.             CRect rcOriginal;
  64.             // Support for DIALOGEX PropertyPages, although those aren't very well supported
  65.             // either
  66.             if (pdlgtplex->signature == 0xFFFF) {
  67.                // DIALOGEX resource
  68.                rcOriginal.SetRect(pdlgtplex->x, pdlgtplex->y, 
  69.                   pdlgtplex->x + pdlgtplex->cx, pdlgtplex->y + pdlgtplex->cy);
  70.             } else {
  71.                // DIALOG resource
  72.                rcOriginal.SetRect(pdlgtpl->x, pdlgtpl->y, pdlgtpl->x+pdlgtpl->cx, 
  73.                   pdlgtpl->y+pdlgtpl->cy);
  74.             }
  75.             
  76.             // Okay, let's retrieve original size of PropertyPage
  77.             pppg->MapDialogRect(rcOriginal);
  78.             CRect rcModified;
  79.             pppg->GetClientRect(rcModified);
  80.             // If our original PropertyPage was not modified, the follwing code
  81.             // will make dcx = 0 and dcy = 0, so it works even for pages bigger
  82.             // than the minimum property page
  83.             int dcx = rcModified.Width() - rcOriginal.Width();
  84.             int dcy = rcModified.Height() - rcOriginal.Height();
  85.             
  86.             // We could deflate the pages by 0 and it would work, but just
  87.             // to be proper
  88.             if (dcx || dcy) {
  89.                // Resize PropertyPage
  90.                rcModified.DeflateRect(0,0,dcx,dcy);
  91.                pppg->SetWindowPos(NULL, 0,0,rcModified.Width(), rcModified.Height(), 
  92.                   SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOACTIVATE);
  93.                // Resize TabControl
  94.                GetTabControl()->GetWindowRect(rcModified);
  95.                rcModified.DeflateRect(0,0,dcx,dcy);
  96.                GetTabControl()->SetWindowPos(NULL, 0,0,rcModified.Width(), rcModified.Height(),
  97.                   SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOACTIVATE);
  98.                // Resize PropertySheet
  99.                GetWindowRect(rcModified);
  100.                rcModified.DeflateRect(0,0,dcx,dcy);
  101.                SetWindowPos(NULL, 0,0,rcModified.Width(), rcModified.Height(),
  102.                   SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOACTIVATE);
  103.             }
  104. /* HELP SAYS
  105. It is not necessary to unlock resources because the system automatically deletes them when the process that created them terminates.
  106. */
  107. //UnlockResource(hgbl);
  108.          }
  109.          // We are not supposed to call GlobalFree on hgbl (see the topic on LoadResource), 
  110.          // but MFC code does it this way (dlgprop.cpp)
  111.          // Anyway the other alternative is to call FreeResource and that's a 16bit func
  112.          // that doesn't seem to do anything on win32
  113. /* HELP SAYS
  114. The return type of LoadResource is HGLOBAL for backward compatibility, 
  115. not because the function returns a handle to a global memory block. 
  116. Do not pass this handle to the GlobalLock or GlobalFree function. */
  117. //         GlobalFree(hgbl);
  118.       }
  119.    }
  120. return TRUE;
  121. }