Support Forums > WinFBE - Code Editor and Visual Designer

WinFBE using CWindow #5

(1/3) > >>

Paul Squires:
Hi Everyone,

Here is the latest source and exe/dll to try. As you can see, I have been busy trying to add functionality to the editor. You can now add a new file or open (one or more) disk files. That's it for the functionality on the File menu, however I have implemented a fair amount of the Edit and View menu functionality. Of course, lots left to do and not much error checking built in there yet.

It is *32 bit* only at this point because the Scintilla dll is 32-bit.

Edit: Updated June 15, 2016 to include all of Jose's suggestions below.

José Roca:
A few changes:


--- Code: ---   ' Add the top tabcontrol (initially not visible)
'   gTTabCtl.hWindow = pWindow->AddControl("TABCONTROL", pWindow->hWindow, _
'       IDC_FRMMAIN_TOPTABCONTROL, "", 0, 0, 0, pWindow->ScaleY(24), _
'       WS_CHILD Or WS_TABSTOP Or TCS_SINGLELINE Or TCS_RAGGEDRIGHT Or TCS_HOTTRACK Or TCS_TABS Or TCS_FOCUSNEVER, _
'       WS_EX_LEFT Or WS_EX_LTRREADING)

   gTTabCtl.hWindow = pWindow->AddControl("TABCONTROL", pWindow->hWindow, _
       IDC_FRMMAIN_TOPTABCONTROL, "", 0, 0, 0, 24, _
       WS_CHILD Or WS_TABSTOP Or TCS_SINGLELINE Or TCS_RAGGEDRIGHT Or TCS_HOTTRACK Or TCS_TABS Or TCS_FOCUSNEVER, _
       WS_EX_LEFT Or WS_EX_LTRREADING)

--- End code ---

The height doesn't have to be scaled because the AddControl method will do it.


--- Code: ---' ========================================================================================
' Position all child windows. Called manually and/or by WM_SIZE
' ========================================================================================
Function frmMain_PositionWindows( ByVal HWnd As HWnd ) As LRESULT

'   Dim pWindow As CWindow Ptr = AfxCWindowPtr(HWnd)

   Dim As HWnd hEdit, hTabCtl
   Dim As Rect rc
   Dim As Long nHeightRebar, nHeightStatusBar, nHeightTabControl

   ' Get the entire client area
'   rc = pWindow->GetClientRect()
   GetClientRect(hwnd, @rc)

   ' Get the heights of the rebar and statusbar
'   nHeightRebar = pWindow->ControlClientHeight( GetDlgItem(HWnd, IDC_FRMMAIN_REBAR) )
'   nHeightStatusBar = pWindow->ControlClientHeight( GetDlgItem(HWnd, IDC_FRMMAIN_STATUSBAR) )
   nHeightRebar = AfxGetWindowHeight( GetDlgItem(HWnd, IDC_FRMMAIN_REBAR) )
   nHeightStatusBar = AfxGetWindowHeight( GetDlgItem(HWnd, IDC_FRMMAIN_STATUSBAR) )

   ' If items exist in the top tabcontrol then show the tab control and account for its height
   hTabCtl = GetDlgItem(HWnd, IDC_FRMMAIN_TOPTABCONTROL)
   If TabCtrl_GetItemCount(hTabCtl) > 0 Then
'      nHeightTabControl = pWindow->ControlClientHeight(hTabCtl)
      nHeightTabControl = AfxGetWindowHeight(hTabCtl)
      SetWindowPos hTabCtl, 0, _
                     rc.Left, rc.Top + nHeightRebar, _
                     rc.Right, nHeightTabControl, _
                     SWP_SHOWWINDOW Or SWP_NOZORDER
   End If

   ' Reduce the height of the client area by the size of the rebar and statusbar.
   Dim pDoc As clsDocument Ptr = gTTabCtl.GetActiveDocument()
   If pDoc Then hEdit = pDoc->hWindow

   SetWindowPos hEdit, 0, _
                  rc.Left, rc.Top + nHeightRebar + nHeightTabControl, _
                  rc.Right, rc.Bottom - nHeightRebar - nHeightStatusBar - nHeightTabControl, _
                  SWP_SHOWWINDOW Or SWP_NOZORDER
   Function = 0
End Function

--- End code ---

The CWindow metric methods return unscaled values, suitable to pass to another CWindow method that scales it (we don't want them to scale an already scaled value) but the API function SetWindowPos wants real values.

Alternate way, call CWindow SetWindowPos:


--- Code: ---' ========================================================================================
' Position all child windows. Called manually and/or by WM_SIZE
' ========================================================================================
Function frmMain_PositionWindows( ByVal HWnd As HWnd ) As LRESULT

   Dim pWindow As CWindow Ptr = AfxCWindowPtr(HWnd)

   Dim As HWnd hEdit, hTabCtl
   Dim As Rect rc
   Dim As Long nHeightRebar, nHeightStatusBar, nHeightTabControl

   ' Get the entire client area
   rc = pWindow->GetClientRect()

   ' Get the heights of the rebar and statusbar
'   nHeightRebar = pWindow->ControlClientHeight( GetDlgItem(HWnd, IDC_FRMMAIN_REBAR) )
'   nHeightStatusBar = pWindow->ControlClientHeight( GetDlgItem(HWnd, IDC_FRMMAIN_STATUSBAR) )
   ' // We need the control height, not just the client area
   nHeightRebar = pWindow->ControlHeight( GetDlgItem(HWnd, IDC_FRMMAIN_REBAR) )
   nHeightStatusBar = pWindow->ControlHeight( GetDlgItem(HWnd, IDC_FRMMAIN_STATUSBAR) )

   ' If items exist in the top tabcontrol then show the tab control and account for its height
   hTabCtl = GetDlgItem(HWnd, IDC_FRMMAIN_TOPTABCONTROL)
   If TabCtrl_GetItemCount(hTabCtl) > 0 Then
'      nHeightTabControl = pWindow->ControlClientHeight(hTabCtl)
      nHeightTabControl = pWindow->ControlHeight(hTabCtl)
      pWindow->SetWindowPos hTabCtl, 0, _
                     rc.Left, rc.Top + nHeightRebar, _
                     rc.Right, nHeightTabControl, _
                     SWP_SHOWWINDOW Or SWP_NOZORDER
   End If

   ' Reduce the height of the client area by the size of the rebar and statusbar.
   Dim pDoc As clsDocument Ptr = gTTabCtl.GetActiveDocument()
   If pDoc Then hEdit = pDoc->hWindow

   pWindow->SetWindowPos hEdit, 0, _
                  rc.Left, rc.Top + nHeightRebar + nHeightTabControl, _
                  rc.Right, rc.Bottom - nHeightRebar - nHeightStatusBar - nHeightTabControl, _
                  SWP_SHOWWINDOW Or SWP_NOZORDER
   Function = 0
End Function

--- End code ---

Using the unmodified code, see in the capture how it looks in my system.

José Roca:
And after the change...

José Roca:
Useful tip: If in the child dialogs you use the same DPI that the parent, ie.


--- Code: ---Function frmOptionsCompiler_Show( ByVal hWndParent As HWnd, _
                                  ByVal nCmdShow   As Long = 0 _
                                  ) As Long

   '  Create the main window and child controls
   Dim pWindow As CWindow Ptr = New CWindow
   pWindow->DPI = AfxCWindowPtr(hwndParent)->DPI

--- End code ---

You can test the effects of changing the DPI without having to change the DPI in your computer!

Just use


--- Code: ---'  Create the main window and child controls
Dim pWindow As CWindow Ptr = New CWindow("WinFBE")
pWindow->DPI = 144   ' or any other value

--- End code ---

If you do it, you will notice that you can have problems with the ownerdraw color comboboxes at certains DPIs.

But the most important is that you don't have to guess, just change the DPI value and you will notice visually any error.

José Roca:
You could even allow the user to choose the scaling ratio in terms of percentage if you want.

Navigation

[0] Message Index

[#] Next page

Go to full version