PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: WM_Create treeview size  (Read 225 times)

jermy

  • Junior Member
  • **
  • Posts: 92
WM_Create treeview size
« on: February 24, 2021, 01:12:03 PM »

Maybe a stupid question, but how do I get my treeview the same size as the tab control
Only in WM_SIZE the format is correct again, from WM_CREATE I cannot get desired format ( same size as the tab control )
I can of course send a WM_SIZE message with sendmessage
Code: [Select]
FUNCTION TabPage1_WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT


   SELECT CASE uMsg

      CASE WM_CREATE
         ' // Get a pointer to the TabPage class
         DIM pTabPage AS CTabPage PTR = AfxCTabPagePtr(GetParent(hwnd), 0)
         ' // Add controls to the first page
           pTabPage->AddControl( "TreeView", hwnd, IDC_TREEVIEW, "", 0, 0, 100 , 100 )


            Case WM_SIZE   ' this works
         DIM pWindow AS CWindow PTR = AfxCWindowPtr(hwnd)
         IF pWindow THEN pWindow->MoveWindow GetDlgItem(hwnd, IDC_TREEVIEW), 0, 0, pWindow->ClientWidth, pWindow->ClientHeight, CTRUE

?
Logged

Josť Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3325
Re: WM_Create treeview size
« Reply #1 on: February 24, 2021, 03:27:12 PM »

In the WM_CREATE message, the size of the page is not know because it has not been resized yet.

Instead, add the control after the tab page has been fully created and resized:

Code: [Select]
' // Create the first tab page
DIM pTabPage1 AS CTabPage PTR = NEW CTabPage
pTabPage1->InsertPage(hTab, 0, "Tab 1", -1, @TabPage1_WndProc)
pTabPage1->AddControl( "TreeView", pTabPage1->hWindow, IDC_TREEVIEW, "", 0, 0, pTabPage1->ClientWidth , pTabPage1->ClientHeight )
« Last Edit: February 24, 2021, 03:56:10 PM by Josť Roca »
Logged

jermy

  • Junior Member
  • **
  • Posts: 92
Re: WM_Create treeview size
« Reply #2 on: February 24, 2021, 03:47:02 PM »

Ok tnx

I moved the creation code for the treeview to winmain, now i want to fill the treeview this is also not possible from WM_CREATE Tabpage?
the code does not fill the treeview
Code: [Select]


FUNCTION TabPage1_WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT

   SELECT CASE uMsg

      CASE WM_CREATE

        DIM hTreeView AS HWND = GetDlgItem(hwnd, IDC_TREEVIEW)

 
   ' // Add items to the TreeView
   DIM AS HTREEITEM hRoot, hNode, hItem
   ' // Create the root node
   hRoot = TreeView_AddRootItem(hTreeView, "All accounts")
   ' // Create a node
   hNode = TreeView_AppendItem(hTreeView, hRoot, "A")
 

I did some testing the listview window handel is not yet created?
« Last Edit: February 24, 2021, 03:58:51 PM by jermy »
Logged

Josť Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3325
Re: WM_Create treeview size
« Reply #3 on: February 24, 2021, 04:01:12 PM »

After moving the creation code to WinMain, the TreeView control has not yet been created when you receive the WM_CREATE message. Mode the code after pTabPage1->AddControl.

Josť Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3325
Re: WM_Create treeview size
« Reply #4 on: February 24, 2021, 04:20:01 PM »

If you want to create the TreeView and the filling code in WM_CREATE, create the TreeView with any size, or even 0, and then resize it in WM_SIZE.

jermy

  • Junior Member
  • **
  • Posts: 92
Re: WM_Create treeview size
« Reply #5 on: February 24, 2021, 04:25:34 PM »

I have already tried that, he first runs WM_CREATE but does not automatically pass WM_SIZE  ( TabPage1_WndProc )
I can do this that works also
Code: [Select]

         sendMessage pTabPage1->hTabPage, WM_SIZE, 0 ,0

   FUNCTION = pWindow.DoEvents
END FUNCTION

« Last Edit: February 24, 2021, 04:33:39 PM by jermy »
Logged