Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Hacking CPropertySheet

Hacking CPropertySheet

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mustafa Demirhan
    wrote on last edited by
    #1

    Hi CPians, In one of my projects, I need a property sheet but there must be a header control on top of the propety sheet. I solved the problem using the source code of CPropertSheet from MFC. Here is the main part of the code: CStepCreatorSheet is derived from CPropertySheet

    BOOL CStepCreatorSheet::OnInitDialog()
    {
    BOOL bResult = CPropertySheet::OnInitDialog();

    // move the window!
        CRect rectWnd;
    GetWindowRect (rectWnd);
    ScreenToClient(rectWnd);
    SetWindowPos (NULL, 0, 0, rectWnd.Width(), rectWnd.Height() + m\_nHeaderHeight,
    	SWP\_NOMOVE | SWP\_NOZORDER | SWP\_NOACTIVATE);
    
    m\_HeaderCtrl.CreateEx (NULL, NULL, NULL, WS\_CHILD | WS\_VISIBLE | WS\_TABSTOP | WS\_BORDER, 
    	-1, -1, rectWnd.Width (), m\_nHeaderHeight - 5, m\_hWnd, 0, 0);
    // move the tab control
    HWND hWnd = (HWND)GetTabControl()->m\_hWnd;
    ASSERT(hWnd != NULL);
    CRect rectOld;
    ::GetWindowRect (hWnd, &rectOld);
    ScreenToClient (&rectOld);
    //::MoveWindow (hWnd, rectOld.left, rectOld.top + m\_nHeaderHeight, rectOld.Width (), rectOld.Height () - m\_nHeaderHeight, TRUE);
    ::SetWindowPos (hWnd, NULL, rectOld.left, rectOld.top + m\_nHeaderHeight, rectOld.Width (), rectOld.Height (),
    	SWP\_NOZORDER | SWP\_NOACTIVATE);
        
        //move the property sheet
    hWnd = (HWND)m\_pMainPage1->m\_hWnd;
    ASSERT(hWnd != NULL);
    ::GetWindowRect (hWnd, &rectOld);
    ScreenToClient (&rectOld);
    ::SetWindowPos (hWnd, NULL, rectOld.left, rectOld.top + m\_nHeaderHeight, rectOld.Width (), rectOld.Height (),
    	SWP\_NOZORDER | SWP\_NOACTIVATE);
    
    // move buttons by similar amount
    for (int i = 0; i < sizeof(\_PropSheetButtons) / sizeof (int); i++)
    {
    	hWnd = ::GetDlgItem(m\_hWnd, \_PropSheetButtons\[i\]);
    	if (hWnd != NULL)
    	{
    		::GetWindowRect (hWnd, &rectOld);
    		ScreenToClient (&rectOld);
    		::SetWindowPos (hWnd, NULL, rectOld.left, rectOld.top + m\_nHeaderHeight, rectOld.Width (), rectOld.Height (),
    			SWP\_NOZORDER | SWP\_NOACTIVATE);
    	}
    }
    
    CenterWindow ();
    return bResult;
    

    }

    BOOL CStepCreatorSheet::OnCommand(WPARAM wParam, LPARAM lParam)
    {
    // allow message map override
    if (CWnd::OnCommand(wParam, lParam))
    return TRUE;

    // crack message parameters
    UINT nID = LOWORD(wParam);
    HWND hWndCtrl = (HWND)lParam;
    int nCode = HIWORD(wParam);
    
    // set m\_nModalResult to ID of button, whenever button is clicked
    if (hWndCtrl != NULL && nCode == BN\_CLICKED)
    {
    	if (::SendMessage(hWndCtrl, WM\_GETDLGCODE, 0, 0) &
    		(DLGC\_BUTTON|DLGC\_DEFPUSHBUTTON))
    	{
    		LONG lStyle = ::GetWindowLong(hWndCtrl, GW
    
    J 1 Reply Last reply
    0
    • M Mustafa Demirhan

      Hi CPians, In one of my projects, I need a property sheet but there must be a header control on top of the propety sheet. I solved the problem using the source code of CPropertSheet from MFC. Here is the main part of the code: CStepCreatorSheet is derived from CPropertySheet

      BOOL CStepCreatorSheet::OnInitDialog()
      {
      BOOL bResult = CPropertySheet::OnInitDialog();

      // move the window!
          CRect rectWnd;
      GetWindowRect (rectWnd);
      ScreenToClient(rectWnd);
      SetWindowPos (NULL, 0, 0, rectWnd.Width(), rectWnd.Height() + m\_nHeaderHeight,
      	SWP\_NOMOVE | SWP\_NOZORDER | SWP\_NOACTIVATE);
      
      m\_HeaderCtrl.CreateEx (NULL, NULL, NULL, WS\_CHILD | WS\_VISIBLE | WS\_TABSTOP | WS\_BORDER, 
      	-1, -1, rectWnd.Width (), m\_nHeaderHeight - 5, m\_hWnd, 0, 0);
      // move the tab control
      HWND hWnd = (HWND)GetTabControl()->m\_hWnd;
      ASSERT(hWnd != NULL);
      CRect rectOld;
      ::GetWindowRect (hWnd, &rectOld);
      ScreenToClient (&rectOld);
      //::MoveWindow (hWnd, rectOld.left, rectOld.top + m\_nHeaderHeight, rectOld.Width (), rectOld.Height () - m\_nHeaderHeight, TRUE);
      ::SetWindowPos (hWnd, NULL, rectOld.left, rectOld.top + m\_nHeaderHeight, rectOld.Width (), rectOld.Height (),
      	SWP\_NOZORDER | SWP\_NOACTIVATE);
          
          //move the property sheet
      hWnd = (HWND)m\_pMainPage1->m\_hWnd;
      ASSERT(hWnd != NULL);
      ::GetWindowRect (hWnd, &rectOld);
      ScreenToClient (&rectOld);
      ::SetWindowPos (hWnd, NULL, rectOld.left, rectOld.top + m\_nHeaderHeight, rectOld.Width (), rectOld.Height (),
      	SWP\_NOZORDER | SWP\_NOACTIVATE);
      
      // move buttons by similar amount
      for (int i = 0; i < sizeof(\_PropSheetButtons) / sizeof (int); i++)
      {
      	hWnd = ::GetDlgItem(m\_hWnd, \_PropSheetButtons\[i\]);
      	if (hWnd != NULL)
      	{
      		::GetWindowRect (hWnd, &rectOld);
      		ScreenToClient (&rectOld);
      		::SetWindowPos (hWnd, NULL, rectOld.left, rectOld.top + m\_nHeaderHeight, rectOld.Width (), rectOld.Height (),
      			SWP\_NOZORDER | SWP\_NOACTIVATE);
      	}
      }
      
      CenterWindow ();
      return bResult;
      

      }

      BOOL CStepCreatorSheet::OnCommand(WPARAM wParam, LPARAM lParam)
      {
      // allow message map override
      if (CWnd::OnCommand(wParam, lParam))
      return TRUE;

      // crack message parameters
      UINT nID = LOWORD(wParam);
      HWND hWndCtrl = (HWND)lParam;
      int nCode = HIWORD(wParam);
      
      // set m\_nModalResult to ID of button, whenever button is clicked
      if (hWndCtrl != NULL && nCode == BN\_CLICKED)
      {
      	if (::SendMessage(hWndCtrl, WM\_GETDLGCODE, 0, 0) &
      		(DLGC\_BUTTON|DLGC\_DEFPUSHBUTTON))
      	{
      		LONG lStyle = ::GetWindowLong(hWndCtrl, GW
      
      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      If it works like a charm I wouldn't wotry more about it. Now seriously, your code seems fine to me. In fact you might consider doing a bunch with it and posting an article here at CP. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      M 1 Reply Last reply
      0
      • J Joaquin M Lopez Munoz

        If it works like a charm I wouldn't wotry more about it. Now seriously, your code seems fine to me. In fact you might consider doing a bunch with it and posting an article here at CP. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        M Offline
        M Offline
        Mustafa Demirhan
        wrote on last edited by
        #3

        Hi Joaquín, Thanks for your reply. I asked this question, because I am not a GUI guru :(( . In fact, I have never needed such a thing and because of this I am just curious if I am in the right path or not. If I get confirmations from the professionals, I will surely post an article about this issue ;) . There are no articles about this, as far as i know. Mustafa Demirhan http://www.macroangel.com Sonork ID 100.9935:zoltrix

        T 1 Reply Last reply
        0
        • M Mustafa Demirhan

          Hi Joaquín, Thanks for your reply. I asked this question, because I am not a GUI guru :(( . In fact, I have never needed such a thing and because of this I am just curious if I am in the right path or not. If I get confirmations from the professionals, I will surely post an article about this issue ;) . There are no articles about this, as far as i know. Mustafa Demirhan http://www.macroangel.com Sonork ID 100.9935:zoltrix

          T Offline
          T Offline
          Tim Smith
          wrote on last edited by
          #4

          I agree, the code looks fine. This is a lot like the case where you have to hack out the OK/CANCEL buttons from a property sheet when you need the property sheet as just a simple control. Tim Smith I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups