FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

native win32 treeview proto code for phobos std.c.windows

 
Post new topic   Reply to topic     Forum Index -> Core32
View previous topic :: View next topic  
Author Message
Lynn



Joined: 27 Aug 2004
Posts: 89

PostPosted: Mon Sep 13, 2004 2:39 pm    Post subject: native win32 treeview proto code for phobos std.c.windows Reply with quote

<alert comment="newbie">

Below is code to augment std.c.windows.windows.d in order to implement basic functionality for the native win32 TreeView. Below that is sample code winsamp3.d that imports std.c.windows.windows_tree.d

Code:

module std.c.windows.windows_tree;

private import std.c.windows.windows;

extern (Windows)
{
/*
 * TreeControl Flags
 */
alias HANDLE HTREEITEM;

enum
{
TV_FIRST                = 0x1100,      // TreeView messages
TVN_FIRST               = (0U-400U),   // treeview
TVN_LAST                = (0U-499U),

TVS_HASBUTTONS          = 0x0001,
TVS_HASLINES            = 0x0002,
TVS_LINESATROOT         = 0x0004,
TVS_EDITLABELS          = 0x0008,
TVS_DISABLEDRAGDROP     = 0x0010,
TVS_SHOWSELALWAYS       = 0x0020,
TVS_RTLREADING          = 0x0040,
TVS_NOTOOLTIPS          = 0x0080,
TVS_CHECKBOXES          = 0x0100,
TVS_TRACKSELECT         = 0x0200,
TVS_SINGLEEXPAND        = 0x0400,
TVS_INFOTIP             = 0x0800,
TVS_FULLROWSELECT       = 0x1000,
TVS_NOSCROLL            = 0x2000,
TVS_NONEVENHEIGHT       = 0x4000,

TVIF_TEXT               = 0x0001,
TVIF_IMAGE              = 0x0002,
TVIF_PARAM              = 0x0004,
TVIF_STATE              = 0x0008,
TVIF_HANDLE             = 0x0010,
TVIF_SELECTEDIMAGE      = 0x0020,
TVIF_CHILDREN           = 0x0040,
TVIF_INTEGRAL           = 0x0080,
TVIS_SELECTED           = 0x0002,
TVIS_CUT                = 0x0004,
TVIS_DROPHILITED        = 0x0008,
TVIS_BOLD               = 0x0010,
TVIS_EXPANDED           = 0x0020,
TVIS_EXPANDEDONCE       = 0x0040,
TVIS_EXPANDPARTIAL      = 0x0080,

TVIS_OVERLAYMASK        = 0x0F00,
TVIS_STATEIMAGEMASK     = 0xF000,
TVIS_USERMASK           = 0xF000,

TVI_ROOT                = (cast(int)0xFFFF0000),
TVI_FIRST               = (cast(int)0xFFFF0001),
TVI_LAST                = (cast(int)0xFFFF0002),
TVI_SORT                = (cast(int)0xFFFF0003),

TVM_INSERTITEMA         = (TV_FIRST + 0),
TVM_INSERTITEMW         = (TV_FIRST + 50),
TVM_INSERTITEM         = TVM_INSERTITEMA,

TVM_DELETEITEM          = (TV_FIRST + 1),
TVM_EXPAND              = (TV_FIRST + 2),
TVE_COLLAPSE            = 0x0001,
TVE_EXPAND              = 0x0002,
TVE_TOGGLE              = 0x0003,
TVE_EXPANDPARTIAL       = 0x4000,
TVE_COLLAPSERESET       = 0x8000,
TVM_GETITEMRECT         = (TV_FIRST + 4),
TVM_GETCOUNT            = (TV_FIRST + 5),
TVM_GETINDENT           = (TV_FIRST + 6),
TVM_SETINDENT           = (TV_FIRST + 7),
TVM_GETIMAGELIST        = (TV_FIRST + 8),
TVSIL_NORMAL            = 0,
TVSIL_STATE             = 2,
TVM_SETIMAGELIST        = (TV_FIRST + 9),
TVM_GETNEXTITEM         = (TV_FIRST + 10),
TVGN_ROOT               = 0x0000,
TVGN_NEXT               = 0x0001,
TVGN_PREVIOUS           = 0x0002,
TVGN_PARENT             = 0x0003,
TVGN_CHILD              = 0x0004,
TVGN_FIRSTVISIBLE       = 0x0005,
TVGN_NEXTVISIBLE        = 0x0006,
TVGN_PREVIOUSVISIBLE    = 0x0007,
TVGN_DROPHILITE         = 0x0008,
TVGN_CARET              = 0x0009,
TVGN_LASTVISIBLE        = 0x000A,
TVM_SELECTITEM          = (TV_FIRST + 11),
TVM_GETITEMA            = (TV_FIRST + 12),
TVM_GETITEMW            = (TV_FIRST + 62),
TVM_GETITEM            = TVM_GETITEMA,
TVM_SETITEMA            = (TV_FIRST + 13),
TVM_SETITEMW            = (TV_FIRST + 63),
TVM_SETITEM            = TVM_SETITEMA,
TVM_EDITLABELA          = (TV_FIRST + 14),
TVM_EDITLABELW          = (TV_FIRST + 65),
TVM_EDITLABEL           = TVM_EDITLABELA,
TVM_GETEDITCONTROL      = (TV_FIRST + 15),
TVM_GETVISIBLECOUNT     = (TV_FIRST + 16),
TVM_HITTEST             = (TV_FIRST + 17),
TVHT_NOWHERE            = 0x0001,
TVHT_ONITEMICON         = 0x0002,
TVHT_ONITEMLABEL        = 0x0004,
TVHT_ONITEMINDENT       = 0x0008,
TVHT_ONITEMBUTTON       = 0x0010,
TVHT_ONITEMRIGHT        = 0x0020,
TVHT_ONITEMSTATEICON    = 0x0040,
TVHT_ONITEM             = (TVHT_ONITEMICON | TVHT_ONITEMLABEL | TVHT_ONITEMSTATEICON),
TVHT_ABOVE              = 0x0100,
TVHT_BELOW              = 0x0200,
TVHT_TORIGHT            = 0x0400,
TVHT_TOLEFT             = 0x0800,
TVM_CREATEDRAGIMAGE     = (TV_FIRST + 18),
TVM_SORTCHILDREN        = (TV_FIRST + 19),
TVM_ENSUREVISIBLE       = (TV_FIRST + 20),
TVM_SORTCHILDRENCB      = (TV_FIRST + 21),
TVM_ENDEDITLABELNOW     = (TV_FIRST + 22),
TVM_GETISEARCHSTRINGA   = (TV_FIRST + 23),
TVM_GETISEARCHSTRINGW   = (TV_FIRST + 64),
TVM_GETISEARCHSTRING    = TVM_GETISEARCHSTRINGA,
TVM_SETTOOLTIPS         = (TV_FIRST + 24),
TVM_GETTOOLTIPS         = (TV_FIRST + 25),
TVM_SETINSERTMARK       = (TV_FIRST + 26),
TVM_SETITEMHEIGHT       = (TV_FIRST + 27),
TVM_GETITEMHEIGHT       = (TV_FIRST + 28),
TVM_SETBKCOLOR          = (TV_FIRST + 29),
TVM_SETTEXTCOLOR        = (TV_FIRST + 30),
TVM_GETBKCOLOR          = (TV_FIRST + 31),
TVM_GETTEXTCOLOR        = (TV_FIRST + 32),
TVM_SETSCROLLTIME       = (TV_FIRST + 33),
TVM_GETSCROLLTIME       = (TV_FIRST + 34),
TVM_SETINSERTMARKCOLOR  = (TV_FIRST + 37),
TVM_GETINSERTMARKCOLOR  = (TV_FIRST + 38),
TVN_SELCHANGINGA        = (TVN_FIRST-1),
TVN_SELCHANGINGW        = (TVN_FIRST-50),
TVN_SELCHANGEDA         = (TVN_FIRST-2),
TVN_SELCHANGEDW         = (TVN_FIRST-51),

TVC_UNKNOWN             = 0x0000,
TVC_BYMOUSE             = 0x0001,
TVC_BYKEYBOARD          = 0x0002,

TVN_GETDISPINFOA        = (TVN_FIRST-3),
TVN_GETDISPINFOW        = (TVN_FIRST-52),
TVN_SETDISPINFOA        = (TVN_FIRST-4),
TVN_SETDISPINFOW        = (TVN_FIRST-53),
TVIF_DI_SETITEM         = 0x1000,
TVN_ITEMEXPANDINGA      = (TVN_FIRST-5),
TVN_ITEMEXPANDINGW      = (TVN_FIRST-54),
TVN_ITEMEXPANDEDA       = (TVN_FIRST-6),
TVN_ITEMEXPANDEDW       = (TVN_FIRST-55),
TVN_BEGINDRAGA          = (TVN_FIRST-7),
TVN_BEGINDRAGW          = (TVN_FIRST-56),
TVN_BEGINRDRAGA         = (TVN_FIRST-8),
TVN_BEGINRDRAGW         = (TVN_FIRST-57),
TVN_DELETEITEMA         = (TVN_FIRST-9),
TVN_DELETEITEMW         = (TVN_FIRST-58),
TVN_BEGINLABELEDITA     = (TVN_FIRST-10),
TVN_BEGINLABELEDITW     = (TVN_FIRST-59),
TVN_ENDLABELEDITA       = (TVN_FIRST-11),
TVN_ENDLABELEDITW       = (TVN_FIRST-60),
TVN_KEYDOWN             = (TVN_FIRST-12),

TVN_GETINFOTIPA         = (TVN_FIRST-13),
TVN_GETINFOTIPW         = (TVN_FIRST-14),
TVN_SINGLEEXPAND        = (TVN_FIRST-15),

TVN_SELCHANGING         = TVN_SELCHANGINGA,
TVN_SELCHANGED          = TVN_SELCHANGEDA,
TVN_GETDISPINFO         = TVN_GETDISPINFOA,
TVN_SETDISPINFO         = TVN_SETDISPINFOA,
TVN_ITEMEXPANDING       = TVN_ITEMEXPANDINGA,
TVN_ITEMEXPANDED        = TVN_ITEMEXPANDEDA,
TVN_BEGINDRAG           = TVN_BEGINDRAGA,
TVN_BEGINRDRAG          = TVN_BEGINRDRAGA,
TVN_DELETEITEM          = TVN_DELETEITEMA,
TVN_BEGINLABELEDIT      = TVN_BEGINLABELEDITA,
TVN_ENDLABELEDIT        = TVN_ENDLABELEDITA,

TVN_GETINFOTIP          = TVN_GETINFOTIPA,
TVCDRF_NOIMAGES         = 0x00010000,
}

struct TVITEMA {
    UINT      mask;
    HTREEITEM hItem;
    UINT      state;
    UINT      stateMask;
    LPSTR     pszText;
    int       cchTextMax;
    int       iImage;
    int       iSelectedImage;
    int       cChildren;
    LPARAM    lParam;
}
alias TVITEMA *LPTVITEMA;
alias TVITEMA TV_ITEMA;

struct TVINSERTSTRUCTA {
    HTREEITEM hParent;
    HTREEITEM hInsertAfter;
    TV_ITEMA item;
}
alias TVINSERTSTRUCTA *LPTVINSERTSTRUCTA;
alias TVINSERTSTRUCTA *LPTV_INSERTSTRUCTA;
alias TVINSERTSTRUCTA TV_INSERTSTRUCTA;

struct NMHDRA {
    UINT  hwndFrom;
    UINT  idFrom;
    UINT  code;
}
alias NMHDRA *LPNMHDRA;
alias NMHDRA *LP_NMHDRA;

struct NMTREEVIEWA {
    NMHDRA     hdr;
    UINT       action;
    TVITEMA    itemOld;
    TVITEMA    itemNew;
    POINT      ptDrag;
}
alias NMTREEVIEWA *LPNMTREEVIEWA;
alias NMTREEVIEWA *LP_NMTREEVIEW;

}


Code:

/* Compile with:
 *  dmd winsamp3 gdi32.lib winsamp3.def
 */

import std.string;
import std.c.windows.windows;
import std.c.windows.windows_tree;

const int IDC_BTN_BOOKS = 103;
const int IDC_BTN_SEARCH = 104;
const int IDC_EDIT_SEARCH_WORDS = 105;
const int IDC_EDIT_TEXT_VIEWER = 106;
const int IDC_BTN_OPTIONS = 107;
const int IDC_BTN_HELP = 108;
const int IDC_TREE_CHAP_SELECTOR = 109;
const int IDC_LIST_SEARCH_MATCHES_LIST = 110;

static HINSTANCE ghInstance;
static HWND      ghBooksBtn;
static HWND      ghChapSelectorTree;
static HWND      ghHelpBtn;
static HWND      ghOptionsBtn;
static HWND      ghSearchBtn;
static HWND      ghSearchWordsEdit;
static HWND      ghTextViewerEdit;
static HWND      ghWndMain;
static HTREEITEM gbHcsBook[68];

void CreateControls()
{
  HWND hChapSelectorTree;
 
  ghBooksBtn = CreateWindowA("BUTTON", "Books", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_TEXT,
                              5, 5, 53, 25, ghWndMain, cast(HMENU) IDC_BTN_BOOKS, ghInstance, null);
  ghSearchBtn = CreateWindowA("BUTTON", "Search", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_TEXT,
                              58, 5, 53, 25, ghWndMain, cast(HMENU) IDC_BTN_SEARCH, ghInstance, null);

  ghSearchWordsEdit = CreateWindowA("EDIT", "", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT,
                                    115, 5, 145, 25, ghWndMain, cast(HMENU) IDC_EDIT_SEARCH_WORDS, ghInstance, null);

  ghOptionsBtn = CreateWindowA("BUTTON", "Options", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_TEXT,
                                265, 5, 53, 25, ghWndMain, cast(HMENU) IDC_BTN_OPTIONS, ghInstance, null);

  ghHelpBtn = CreateWindowA("BUTTON", "Help", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_TEXT,
                            320, 5, 53, 25, ghWndMain, cast(HMENU) IDC_BTN_HELP, ghInstance, null);

  ghTextViewerEdit = CreateWindowA("EDIT", "", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOVSCROLL | WS_VSCROLL
                                              | ES_LEFT | ES_MULTILINE | ES_NOHIDESEL,
                                     115, 32, 260, 300, ghWndMain, cast(HMENU) IDC_EDIT_TEXT_VIEWER, ghInstance, null);

  SendMessageA(ghTextViewerEdit, WM_SETTEXT, 0,
      cast(int)cast(char*)"Hello\x0D\x0A"
                          "Line 2\x0D\x0A"
                          "Line 3\x0D\x0A"
                          "Long Line 4 to check word wrap aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll mmm\x0D\x0A"
                          "Line 5\x0D\x0A"
                          "Line 6");

  hChapSelectorTree = CreateWindowA("SYSTREEVIEW32", "",
                                     WS_CHILD | WS_VISIBLE | WS_BORDER | TVS_HASLINES |
                                     WS_CLIPSIBLINGS | TVS_HASBUTTONS | TVS_LINESATROOT,
                                     5, 32, 110, 300, ghWndMain,
                                     cast(HMENU) IDC_TREE_CHAP_SELECTOR, ghInstance, null);
  if (hChapSelectorTree == null) {
    MessageBoxA(null, cast(char *)("ChapSelector Tree not created!"), "Error", MB_OK | MB_ICONEXCLAMATION);
  }
  else {
    ghChapSelectorTree = hChapSelectorTree;
  }
}

void DoMessagePump()
{
  MSG msg;
  while (GetMessageA(&msg, cast(HWND) null, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessageA(&msg);
  }
}

void CreateMainWindow()
{
  HWND hWnd;
  hWnd = CreateWindowA("DWndClass", "Berean Bible", WS_THICKFRAME |
                        WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE,
                        CW_USEDEFAULT, CW_USEDEFAULT, 385, 375, HWND_DESKTOP,
                        cast(HMENU) null, ghInstance, null);
  assert(hWnd);
  ghWndMain = hWnd;
}

void InitApplication()
{
  WNDCLASS wc;
  wc.lpszClassName = "DWndClass";
  wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
  wc.lpfnWndProc = &WindowProc;
  wc.hInstance = ghInstance;
  wc.hIcon = LoadIconA(cast(HINSTANCE) null, IDI_APPLICATION);
  wc.hCursor = LoadCursorA(cast(HINSTANCE) null, IDC_CROSS);
  wc.hbrBackground = cast(HBRUSH) (COLOR_WINDOW + 1);
  wc.lpszMenuName = null;
  wc.cbClsExtra = wc.cbWndExtra = 0;
  assert(RegisterClassA(&wc));
}

void InitInstance()
{
  ghInstance = GetModuleHandleA(null);
  InitApplication();

  CreateMainWindow();

  CreateControls();

  LoadChapSelector();
}

void LoadChapterText(LPARAM lParam)
{
  LPNMTREEVIEWA pnmtv = cast(LPNMTREEVIEWA) lParam;
  TVITEMA tvI;
  char szText[256];

  tvI.mask = TVIF_TEXT | TVIF_PARAM;
  tvI.pszText = szText;
  tvI.cchTextMax = 256;
  tvI.hItem = pnmtv.itemNew.hItem;

  SendMessageA(ghChapSelectorTree, TVM_GETITEM, 0, cast(int)cast(TVITEMA*)&tvI);
  LPARAM param = tvI.lParam;

  char[] part1 = toString(tvI.pszText);
  char[] part2 = toString(param);
  char[] part3 = part1 ~ " = " ~ part2;

  SendMessageA(ghTextViewerEdit, WM_SETTEXT, 0, cast(int)cast(char*)part3);
}

void LoadBook(int bookNum, char[] bookName, char[] bookAbbrev, int chapCount)
{
  TV_ITEMA tvI;
  TV_INSERTSTRUCTA tvIns;

  tvI.mask = TVIF_TEXT | TVIF_PARAM;
  tvI.pszText = bookName;
  tvI.cchTextMax = 10;
  tvI.lParam = bookNum * 1000;
  tvIns.item = tvI;
  tvIns.hInsertAfter = cast(HTREEITEM)TVI_ROOT;
  tvIns.hParent = null;
  gbHcsBook[bookNum] = cast(HTREEITEM)SendMessageA(ghChapSelectorTree, TVM_INSERTITEM, 0, cast(int)&tvIns);

  tvI.cChildren = 0;
  tvIns.hParent = gbHcsBook[bookNum];
  tvIns.hInsertAfter = cast(HTREEITEM)TVI_LAST;

  for (int i = 1; i <= chapCount; ++i) {
    tvI.pszText = bookAbbrev ~ "." ~ toString(i);
    tvI.lParam = bookNum * 1000 + i;
    tvIns.item = tvI;
    SendMessageA(ghChapSelectorTree, TVM_INSERTITEM, 0, cast(int)&tvIns);
  }
}

void LoadChapSelector()
{
  LoadBook(1, "Genesis", "Gen", 10);
  LoadBook(2, "Exodus", "Exo", 8);
  LoadBook(3, "Leviticus", "Lev", 4);
  LoadBook(4, "Numbers", "Num", 6);
}

/**********************************************************/

/* Note the similarity of this code to the console D startup
 * code in \dmd\src\phobos\dmain2.d
 * You'll also need a .def file with at least the following in it:
 *  EXETYPE NT
 *  SUBSYSTEM WINDOWS
 */

extern (C) void gc_init();
extern (C) void gc_term();
extern (C) void _minit();
extern (C) void _moduleCtor();
extern (C) void _moduleUnitTests();

extern (Windows)
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
  int result = 1;

  gc_init();      // initialize garbage collector
  _minit();     // initialize module constructor table

  try {
    _moduleCtor();    // call module constructors
    _moduleUnitTests(); // run unit tests (optional)

    InitInstance();
  DoMessagePump();
  }
  catch (Object o) {    // catch any uncaught exceptions
    MessageBoxA(null, cast(char *)o.toString(), "Error",
                MB_OK | MB_ICONEXCLAMATION);
    result = 0;   // failed
  }
  gc_term();      // run finalizers; terminate garbage collector
  return result;
}

extern(Windows)
int WindowProc(HWND hWnd, uint uMsg, WPARAM wParam, LPARAM lParam)
{
  LPNMHDRA  pnmhdr;

  switch (uMsg) {
    case WM_COMMAND: {
      switch (LOWORD(wParam)) {
        case IDC_BTN_BOOKS:
          if (HIWORD(wParam) == BN_CLICKED) {
            MessageBoxA(hWnd, "Clicked", "Books",
                        MB_OK | MB_ICONINFORMATION);
          }
          break;
        case IDC_BTN_SEARCH:
          if (HIWORD(wParam) == BN_CLICKED) {
            MessageBoxA(hWnd, "Clicked", "Search",
                        MB_OK | MB_ICONEXCLAMATION);
          }
          break;
        case IDC_BTN_OPTIONS:
          if (HIWORD(wParam) == BN_CLICKED) {
            MessageBoxA(hWnd, "Clicked", "Options",
                        MB_OK | MB_ICONEXCLAMATION);
          }
          break;
        case IDC_BTN_HELP:
          if (HIWORD(wParam) == BN_CLICKED) {
            MessageBoxA(hWnd, "Clicked", "Help",
                        MB_OK | MB_ICONEXCLAMATION);
          }
          break;
        case IDC_EDIT_SEARCH_WORDS:
          if (HIWORD(wParam) == BN_CLICKED) {
            MessageBoxA(hWnd, "Clicked", "Search Words",
                        MB_OK | MB_ICONEXCLAMATION);
          }
          break;
        case IDC_EDIT_TEXT_VIEWER:
          if (HIWORD(wParam) == BN_CLICKED) {
            MessageBoxA(hWnd, "Clicked", "Text Viewer",
                        MB_OK | MB_ICONEXCLAMATION);
          }
          break;
      }
      break;
    }
    case WM_DESTROY:
      PostQuitMessage(0);
      break;

    case WM_NOTIFY:
      pnmhdr = cast(LPNMHDRA)lParam;
      if (pnmhdr.hwndFrom == cast(UINT)ghChapSelectorTree) {
        UINT code = pnmhdr.code;
        if (code == TVN_SELCHANGED || code == TVN_KEYDOWN) {
          LoadChapterText(lParam);
        }
      }
      break;

    default:
      break;
  }
  return DefWindowProcA(hWnd, uMsg, wParam, lParam);
}


</alert?
Back to top
View user's profile Send private message
jcc7



Joined: 22 Feb 2004
Posts: 657
Location: Muskogee, OK, USA

PostPosted: Mon Sep 13, 2004 5:06 pm    Post subject: Re: native win32 treeview proto code for phobos std.c.window Reply with quote

Lynn wrote:
Below is code to augment std.c.windows.windows.d in order to implement basic functionality for the native win32 TreeView. Below that is sample code winsamp3.d that imports std.c.windows.windows_tree.d
Looks, great. I'd definitely like to see something like this in Phobos, Ares, or Core32. It'd make it more likely that Walter would accept it if you license it as public domain, copywrite it but donate it to Digital Mars, or something like that (I'm not a license expert).

The code compiles for me, but there seems to be something different about my computer. When I run it, a messagebox appears and it tells me: "Error: ChapSelector Tree not created!". I also ran the .exe in the .zip that you e-mailed me and it did the same thing. I'm running WinXP. I'm going to run a program that checks DLL dependencies when I figure out where I put it. Any ideas what's wrong with my system? Does it need some graphic files or something? I've tried to work with TreeView in D before, but I ran into a problem where Windows thought I wanted to use non-ASCII characters!

Maybe it's time for me to format my hard drive. Sad
Back to top
View user's profile Send private message AIM Address
Lynn



Joined: 27 Aug 2004
Posts: 89

PostPosted: Tue Sep 14, 2004 5:14 am    Post subject: Reply with quote

Odd. The code was developed on an Xp-Home computer. The winsamp3.exe can be invoked and runs ok on three computers on my home network, including two running Win2000. One of those is a "test box" without much installed beyond a baseline configuration. AFAIK, winsamp3.exe is 75kb and "self-contained" except for msvcrt.dll

Did you compile with:
winsamp3 gdi32.lib winsamp3.def

The windows_tree.d file should be in the same directory as windows.d. I wonder if perhaps windows_tree.d got compiled ok? However, winsamp3.exe is supposed to be self-contained so that should not make any difference.

Can you compile the winsamp.d sample code and run the resulting winsamp.exe?

Thanks for the advice about license issues. i-a-n-a-l. I'll look at other source code and paste something in. Any suggestions?
Back to top
View user's profile Send private message
Lynn



Joined: 27 Aug 2004
Posts: 89

PostPosted: Tue Sep 14, 2004 5:21 am    Post subject: Reply with quote

<alert comment="newbie">

An aside:

Code:

  SendMessageA(ghChapSelectorTree, TVM_GETITEM, 0, cast(int)cast(TVITEMA*)&tvI);
  LPARAM param = tvI.lParam;

  char[] part1 = toString(tvI.pszText);
  char[] part2 = toString(param);
  char[] part3 = part1 ~ " = " ~ part2;

  SendMessageA(ghTextViewerEdit, WM_SETTEXT, 0, cast(int)cast(char*)part3);


I had trouble figuring out how to format the string to go in the EditCtrl. When I clicked on Exo.3, I wanted to confirm what was clicked by putting the string "Exo.3 = 2003" in the EditCtrl. I got it to work with the "hold-your-nose" use of part1, part2, and part3. I had trouble using OutBuffer and other approaches. Any suggestions?

</alert>
Back to top
View user's profile Send private message
Lynn



Joined: 27 Aug 2004
Posts: 89

PostPosted: Tue Sep 14, 2004 5:41 am    Post subject: Reply with quote

<alert comment="newbie">

I put in the lines below into windows_tree.d and winsamp3.d. Seem ok? I uploaded a revised DmdTreeView.zip to:
http://berbible.sourceforge.net/misc/DmdTreeView.zip

I was somewhat surprised that many of the .d source files had no copyright information. I wonder if that would be appropriate to mention on the D forum?

Code:

/*
 *  Copyright (C) 2004 by Digital Mars, www.digitalmars.com
 *  Written by Lynn Allan by adapting code by Walter Bright
 *
 *  This software is provided 'as-is', without any express or implied
 *  warranty. In no event will the authors be held liable for any damages
 *  arising from the use of this software.
 *
 *  Permission is granted to anyone to use this software for any purpose,
 *  including commercial applications, and to alter it and redistribute it
 *  freely, subject to the following restrictions:
 *
 *  o  The origin of this software must not be misrepresented; you must not
 *     claim that you wrote the original software. If you use this software
 *     in a product, an acknowledgment in the product documentation would be
 *     appreciated but is not required.
 *  o  Altered source versions must be plainly marked as such, and must not
 *     be misrepresented as being the original software.
 *  o  This notice may not be removed or altered from any source
 *     distribution.
 */


</alert>
Back to top
View user's profile Send private message
jcc7



Joined: 22 Feb 2004
Posts: 657
Location: Muskogee, OK, USA

PostPosted: Tue Sep 14, 2004 7:57 am    Post subject: Reply with quote

Lynn wrote:
Odd. The code was developed on an Xp-Home computer. The winsamp3.exe can be invoked and runs ok on three computers on my home network, including two running Win2000. One of those is a "test box" without much installed beyond a baseline configuration.
Very odd. And you're using DMD 0.101, right? I've also tried it with my Win2000 computer at work and fails on that one, too. Since it passes all of your tests, it's probably something I'm doing.

I made an example of a working treeview in D code last night (while making use of your windows_tree.d, too). I'll study the differences between your example and my example and figure out what the problem is.

Lynn wrote:
AFAIK, winsamp3.exe is 75kb and "self-contained" except for msvcrt.dll

Did you compile with:
winsamp3 gdi32.lib winsamp3.def
Pretty much. I didn't compile windows_tree.d into Phobos, so I added windows_tree.d to the compile line. I could try rebuilding Phobos and adding windows_tree.d, but I don't see why that should be necessary.


Lynn wrote:
Can you compile the winsamp.d sample code and run the resulting winsamp.exe?
That's the weird thing. I don't have any problem compiling it from source, but I get the same error every time I run it.

Lynn wrote:
Thanks for the advice about license issues. i-a-n-a-l. I'll look at other source code and paste something in. Any suggestions?
I think the easiest one for everyone would be:
Code:
/*
By Lynn
License: Public Domain
*/
Back to top
View user's profile Send private message AIM Address
jcc7



Joined: 22 Feb 2004
Posts: 657
Location: Muskogee, OK, USA

PostPosted: Tue Sep 14, 2004 11:09 am    Post subject: Reply with quote

I've also tried the .exe that you produced on my computer at work (Windows 2000). It still has the same problem. My current theory is it's a DLL issue, but I won't have a chance to investigate further until after I get home from work this evening.
Back to top
View user's profile Send private message AIM Address
jcc7



Joined: 22 Feb 2004
Posts: 657
Location: Muskogee, OK, USA

PostPosted: Tue Sep 14, 2004 5:16 pm    Post subject: I solved my problem! Reply with quote

I think I found my problem... and solved it. Very Happy

Add a line near the top of std.c.windows.windows_tree:
Code:
extern (Windows)
{

export int InitCommonControls(); /* new code */

/*
 * TreeControl Flags
 */
alias HANDLE HTREEITEM;


Then, add a line to winsamp3 before the TreeView is created:

Code:
  InitCommonControls();  /* new code */

  hChapSelectorTree = CreateWindowA("SYSTREEVIEW32", "",
                                     WS_CHILD | WS_VISIBLE | WS_BORDER | TVS_HASLINES |
                                     WS_CLIPSIBLINGS | TVS_HASBUTTONS | TVS_LINESATROOT,
                                     5, 32, 110, 300, ghWndMain,
                                     cast(HMENU) IDC_TREE_CHAP_SELECTOR, ghInstance, null);



Then, compile something like this:
Code:
dmd winsamp windows_tree.d gdi32.lib comctl32.lib winsamp3.def


I don't recall if comctl32.lib comes with the DM tools (you'll get a link error if it's not there). If you don't have one, let me know and I'll get you set up.

It works for me!
Back to top
View user's profile Send private message AIM Address
Lynn



Joined: 27 Aug 2004
Posts: 89

PostPosted: Wed Sep 15, 2004 4:50 am    Post subject: Reply with quote

I added the code you suggested, and it still works. I have to wonder why it ever worked on the computers I have here. The dmd distribution doesn't come with lib\comctl32.lib, but dmc.zip does.

I just checked and I have dmd ver 0.95. I'll download and install .101 and see if it has similar behavior. [Later: installed 0.101 and having same behavior.]

Regardless of whether I have the "InitCommonControls();", DmdTreeView.exe still works. I've used command lines with and without comctl32.lib:
dmd DmdTreeView gdi32.lib DmdTreeView.def
dmd DmdTreeView comctl32.lib gdi32.lib DmdTreeView.def
and both compile/link ok and DmdTreeView.exe runs fine.

Do you know what a "gub" is?

It's "bug" backwards. A bug is code that doesn't work and you don't know why. A "gub" is code that works, and you don't know why. Wink
Back to top
View user's profile Send private message
jcc7



Joined: 22 Feb 2004
Posts: 657
Location: Muskogee, OK, USA

PostPosted: Wed Sep 15, 2004 4:41 pm    Post subject: Reply with quote

Lynn wrote:
I added the code you suggested, and it still works. I have to wonder why it ever worked on the computers I have here.
I wish I knew that, too. It's quite mysterious.

Lynn wrote:
I've used command lines with and without comctl32.lib:
dmd DmdTreeView gdi32.lib DmdTreeView.def
dmd DmdTreeView comctl32.lib gdi32.lib DmdTreeView.def
and both compile/link ok and DmdTreeView.exe runs fine.

Every day I know less than the previous day. This is what I get when I leave out comctl32.lib:
Code:
Error 42: Symbol Undefined _InitCommonControls@0
--- errorlevel 1
If your version will link and assuming it runs Wink, that's good enough for me. Perhaps you have a better gdi32.lib than I'm using. You are actually calling the InitCommonControls in your code, right?

Lynn wrote:
Do you know what a "gub" is?

It's "bug" backwards. A bug is code that doesn't work and you don't know why. A "gub" is code that works, and you don't know why. Wink
Laughing I don't think I've heard that one before. I've seen plenty of gubs. I wonder about the gubs, but I only worry about the bugs.

By the way, I just realized that Core32 project already has all of the TreeView definitions in win32.commctrl, so I don't really see a place for your windows_tree.d work in this project. Still, Walter or the Ares team might be interested. And you're still welcome to start threads here. I think I have more fun tweaking other people's slightly buggy code than writing my own super-buggy code. Smile
Back to top
View user's profile Send private message AIM Address
Lynn



Joined: 27 Aug 2004
Posts: 89

PostPosted: Thu Sep 16, 2004 10:23 am    Post subject: Reply with quote

I tried to download from Core32 svn, but got a message that the Sep, 2004 file was corrupted. I was able to download the Aug, 2004 version. It does appear to have TreeView constants and structure definitions.

Would you be able to check the latest core32 zip file for corruption?

Sigh.
Back to top
View user's profile Send private message
jcc7



Joined: 22 Feb 2004
Posts: 657
Location: Muskogee, OK, USA

PostPosted: Thu Sep 16, 2004 1:27 pm    Post subject: Reply with quote

Lynn wrote:
Would you be able to check the latest core32 zip file for corruption?
Thanks for pointing out the problem. I think what I did was create a .7z format archive and named it with a .zip. Embarassed When I open it with 7-zip, it works fine, but it'll be unreadable for all other compression programs.

It's easy to fix, and I'll create a new valid archive when I get home.

Update: I removed the invalid archive and added a fresh one. Please, let me know if you have any more problems.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Core32 All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group