Solved

CPropertySheet size...

Posted on 2000-02-28
5
1,746 Views
Last Modified: 2013-11-20
I have made a Propertysheet, but the damn thing sizes itself to the widest page contained within it. When I use Sheet.SetWindowPos, The right side of the sheet gets clipped away...

WHHHYYYYY?!?!?

Is there some way to avoid this??
Is there some way I can make a property sheet the size I want to, without the clipping?

The reason I wanna do this, is that it makes the space on the right side a great deal larger than on the bottom, top and left..

0
Comment
Question by:lar_jens
  • 3
5 Comments
 
LVL 8

Expert Comment

by:gelbert
ID: 2566176
You would need to derive class from CPropertySheet and overwrite OnInitDialog(). See CPropertySheet::OnInitDialog()(dlgprop.cpp in MFC source code) to understand how to resize dialog.
0
 
LVL 1

Author Comment

by:lar_jens
ID: 2567944
Øhh..

I'm sorry, but I would expect a little more explanation for 200 points..

Listen.. 200 points means that the question is HARD, thus requiring HARD work to answer..

No offence, but I think that your explanation was a little vague..

0
 
LVL 1

Author Comment

by:lar_jens
ID: 2567976
What I want to know is how I can resize the CPropertySheet without it's beeing clipped on the right side..

OnInitDialog uses ::SetWindowPos (same as I am), but when I use it the right side of the sheet gets clipped away..
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 200 total points
ID: 2568233
Hi lar_jens,

perhaps I found a solution which can be adapted for your need. At www.codeproject.com I found code which makes a property sheet appear matching to the size of its first page resource. I modified this a bit because the sheet's buttons were not moved. To use it derive a new class from CPropertySheet and implement its OnInitDialog like this:

BOOL CMyPropertySheet::OnInitDialog()
{
 // Inherited call
 CPropertySheet::OnInitDialog();
 // Modifying exstyle in create method doesn't seem to work :-?, I guess
 // DIALOGEX property sheets are not very well supported (if at all)
 // We cannot access here the exstyle passed at creation time (dlgprop.cpp
 // stores temporaly in AfxGetThreadState()->m_dwPropStyle, but when OnInitDialog
 // is called that variable can have been overwritten
 ModifyStyleEx(0, WS_EX_TOOLWINDOW);
      
 // Resize property sheet and tab ctrl to exactly fit the page, as by default
 // PropertyPages have a non-sense minimum width of 214DLUs (MS dixit)
 // Height has also a minimum size.
      
 // There must be at least one property page, so safe accessing it is not needed
 // (if it has no pages MFC will not show the PropertySheet)
 CPropertyPage* pppg = GetActivePage();
      
 // Get the resource for first page (all pages are assumed to be of the same
 // dimensions).
 HRSRC hrsrc;
 if (AfxIsValidString(pppg->m_psp.pszTemplate))
  hrsrc = FindResource(pppg->m_psp.hInstance, pppg->m_psp.pszTemplate, RT_DIALOG);
 else
  hrsrc = FindResource(pppg->m_psp.hInstance, MAKEINTRESOURCE(pppg->m_psp.pszTemplate), RT_DIALOG);
      
 // If found, we can resize the page (which was resized at creation time by MFC's),
 // It suffices modifying the layout here, as once the first page is added, MFC never
 // resizes the dialog again to fit MS's minimum sizes of PropertyPages (even if you add
 // new pages with AddPage() )
 if (hrsrc) {
  HGLOBAL hgbl = LoadResource(pppg->m_psp.hInstance, hrsrc);
  if (hgbl) {
   LPDLGTEMPLATE pdlgtpl;
   pdlgtpl = (LPDLGTEMPLATE) LockResource(hgbl);
   if (pdlgtpl) {
    DLGTEMPLATEEX* pdlgtplex = (DLGTEMPLATEEX*) pdlgtpl;
    CRect rcOriginal;
                        
    // Support for DIALOGEX PropertyPages, although those aren't very well supported
    // either
    if (pdlgtplex->signature == 0xFFFF) {
     // DIALOGEX resource
     rcOriginal.SetRect(pdlgtplex->x, pdlgtplex->y, pdlgtplex->x + pdlgtplex->cx, pdlgtplex->y + pdlgtplex->cy);
    } else {
     // DIALOG resource
     rcOriginal.SetRect(pdlgtpl->x, pdlgtpl->y, pdlgtpl->x+pdlgtpl->cx, pdlgtpl->y+pdlgtpl->cy);
    }
                        
    // Okay, let's retrieve original size of PropertyPage
    pppg->MapDialogRect(rcOriginal);
                        
    CRect rcModified;
    pppg->GetClientRect(rcModified);
    // If our original PropertyPage was not modified, the follwing code
    // will make dcx = 0 and dcy = 0, so it works even for pages bigger
    // than the minimum property page
    int dcx = rcModified.Width() - rcOriginal.Width();
    int dcy = rcModified.Height() - rcOriginal.Height();
                        
    // We could deflate the pages by 0 and it would work, but just
    // to be proper
    if (dcx || dcy) {
     // Resize PropertyPage
     rcModified.DeflateRect(0,0,dcx,dcy);
     pppg->SetWindowPos(NULL, 0,0,rcModified.Width(), rcModified.Height(), SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOACTIVATE);
                              
     // Resize TabControl
     GetTabControl()->GetWindowRect(rcModified);
     rcModified.DeflateRect(0,0,dcx,dcy);
                                        GetTabControl()->SetWindowPos(NULL, 0,0,rcModified.Width(), rcModified.Height(), SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOACTIVATE);
                              
     // Resize PropertySheet
     GetWindowRect(rcModified);
                                   rcModified.DeflateRect(0,0,dcx,dcy);
     SetWindowPos(NULL, 0,0,rcModified.Width(), rcModified.Height(), SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOACTIVATE);

// next lines added by me (ZOPPO) to move buttons to correct position, could be modified
// to handle shrinking of the buttons when the dialog is too small...
// I found that code at http://www.codeguru.com/propertysheet/resize_sheet.shtml
     int ids[] = { IDOK, IDCANCEL, ID_APPLY_NOW };
     CRect rectWnd;
     for( int i =0; i < sizeof(ids)/sizeof(ids[0]); i++)
     {
      GetDlgItem(ids[i])->GetWindowRect(rectWnd);
      ScreenToClient(rectWnd);
      rectWnd.OffsetRect( -dcx, -dcy );
      GetDlgItem(ids[i])->MoveWindow(rectWnd);
     }
    }
    UnlockResource(hgbl);
   }
   // We are not supposed to call GlobalFree on hgbl (see the topic on LoadResource),
   // but MFC code does it this way (dlgprop.cpp)
   // Anyway the other alternative is to call FreeResource and that's a 16bit func
   // that doesn't seem to do anything on win32
   GlobalFree(hgbl);
  }
 }

 return TRUE;
}


hope that helps,

ZOPPO
0
 
LVL 1

Author Comment

by:lar_jens
ID: 2568606
Thank you..
Just what I'm looking 4...

Thnx!
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Folder Comparison 12 54
conditional code and condition difference 9 82
Problem to event 3 96
Is there a simple front-end menu system. 9 89
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question