• 13
• 18
• 19
• 27
• 9

# Mapping Resources (win32 api)

This topic is 3789 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm trying to make a treeview dialog and I'm using this MSDN entry to guide me: http://msdn2.microsoft.com/en-us/library/bb773409.aspx I drew out a dialog box that has a treeview on the left side in ResEd and now I've imported that resource file to my project. The problem is that the code and resource do not agree on the coordinate system. In my resource file, this is what the treeview looks like:
CONTROL "",IDC_TRV1,"SysTreeView32",0x50010003,8,7,112,183,0x00000200
I create the treeview like this:
    hwndTV = CreateWindowEx(0,
WC_TREEVIEW,
"Tree View",
WS_VISIBLE | WS_CHILD | WS_BORDER | TVS_HASLINES,
hwndParent,
g_hInst,
NULL); 
My treeview is much smaller then the one that I made with ResEd, and it's in the wrong place. What am I doing wrong?

##### Share on other sites
The resource dialog uses dialog units, the CreateWindow(Ex) function pixels.

##### Share on other sites
OK, thank you, that is helpful.

Now I'm using MapDialogRect() to convert the resource coordinates to screen coordinates. But it's still wrong on-screen.

The MSDN note for MapDialogRect() says that only handles from "one of the dialog box creation functions" are valid. But I don't have that handle until after I create the treeview with CreateWindowEx(), right?? And I need the result from MapDialogRect() in order to call CreateWindowEx(). Which is a paradox.

Currently I'm initializing the treeview in the dialog's message handler under the case WM_INITDIALOG and using the handle (hwnd) provided to the message handler. But I assume this is the wrong handle (hwnd) due to the MSDN note. I don't see anything else to do, though.

In case what I just said didn't make any sense, here are some code snippets:
BOOL CALLBACK DlgManagerProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam){    switch(Message)    {        case WM_INITDIALOG:		//anything that needs to be done once dialog is visible		HWND tree;		tree = CreateATreeView(hwnd);		AddItemToTreeView(tree, "Sample Folder", 1);		AddItemToTreeView(tree, "Sample Item", 2);        return TRUE;        //..........    }    return TRUE;}HWND CreateATreeView(HWND hwndParent) {     HWND hwndTV;    // handle to tree-view control     RECT rcTree;    // treeview box    // MSDN: Ensure that the common control DLL is loaded.     // InitCommonControls(); //obsolete, see InitCommonControlEx() if necessary	rcTree.top = 8;	rcTree.left = 7;	rcTree.bottom = 183;	rcTree.right = 112;	MapDialogRect(hwndParent, &rcTree);	//int width = rcTree.right - rcTree.left;	//int height = rcTree.bottom - rcTree.top;    // Create the tree-view control.     hwndTV = CreateWindowEx(0,//WS_EX_CLIENTEDGE,                            WC_TREEVIEW,                            "Tree View",                            WS_VISIBLE | WS_CHILD | WS_BORDER | TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT | TVS_NOHSCROLL,                             rcTree.left, rcTree.top, rcTree.right, rcTree.bottom,                             hwndParent,                             (HMENU)IDD_DLGMANAGER,                             g_hInst,                             NULL);     return hwndTV;}

[the functions CreateATreeView() and AddItemToTreeView() are substantially similar to the ones in the MSDN article I cited in my first post]
edit: removed code comments from MSDN that no longer apply after my modifications, fixed spacing
edit again: nevermind, I seem to have fixed it. Got confused on the left/rights and widths apparently. THANKS!!!!! :)

[Edited by - polaris2013 on November 3, 2007 9:31:08 AM]