[C++] treeview eigen windowprocedure werkt niet

Pagina: 1
Acties:

  • Overspeed
  • Registratie: April 2000
  • Laatst online: 00:44
Op de één of andere manier krijg ik het niet voor elkaar om de window procedure van de treeview te laten werken...

De MessageBoxen in de switch van TreeViewWindowProc worden niet uitgevoerd.

De code:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <windows.h>
#include <commctrl.h>

static TCHAR szAppName[] = TEXT("blaat");
static TCHAR szClassName[] = TEXT("MyWindowClass");
static TCHAR szTreeViewClass[] = TEXT("MyTreeViewClass");

HWND hTreeview;
HINSTANCE hInstance;

LRESULT CALLBACK MyWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_CREATE:
        break;
    case WM_SIZE:
        MoveWindow(hTreeview, 0, 30, 200, HIWORD(lParam), false);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

LRESULT CALLBACK TreeViewWindowProc(HWND hTreeview, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_CREATE:
        MessageBox(hTreeview, TEXT("WM_CREATE"), TEXT("Melding"), MB_OK);
        break;
    case WM_SIZE:
        MessageBox(hTreeview, TEXT("WM_SIZE"), TEXT("Melding"), MB_OK);
        break;
    default:
        return DefWindowProc(hTreeview, message, wParam, lParam);
    }
    return 0;
}

void RegisterTreeViewClass(HINSTANCE hInstance, LPCTSTR Name)
{
    WNDCLASSEX wcWindow;

    wcWindow.cbSize = sizeof(wcWindow);
    wcWindow.lpfnWndProc = (WNDPROC) TreeViewWindowProc;
    wcWindow.style = CS_HREDRAW|CS_VREDRAW;
    wcWindow.cbClsExtra = 0;
    wcWindow.cbWndExtra = 0;
    wcWindow.hInstance = hInstance;
    wcWindow.hIcon = NULL;
    wcWindow.hIconSm = NULL;
    wcWindow.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcWindow.hbrBackground = (HBRUSH) COLOR_HIGHLIGHT;
    wcWindow.lpszMenuName = NULL;
    wcWindow.lpszClassName = Name;

    RegisterClassEx(&wcWindow);
}

void MyRegisterClass(HINSTANCE hInstance, LPCTSTR Name)
{
    WNDCLASSEX wc;

    wc.cbSize = sizeof(wc);
    wc.lpfnWndProc = (WNDPROC) MyWndProc;
    wc.style = CS_HREDRAW|CS_VREDRAW;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = NULL;
    wc.hIconSm = NULL;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH) COLOR_WINDOW;
    wc.lpszMenuName = NULL;
    wc.lpszClassName = Name;

    RegisterClassEx(&wc);

}


HWND CreateTreeview(HWND hWnd, HINSTANCE hInstance)
{
    hTreeview = CreateWindow(WC_TREEVIEW, "",
    WS_VISIBLE|WS_CHILD|WS_BORDER|TVS_LINESATROOT|TVS_HASLINES|TVS_HASBUTTONS, 0, 30, 270, 500,
    hWnd, NULL, hInstance, NULL);

    return hTreeview;
}


HWND MyInitWindow(HINSTANCE hInstance, int nShowCmd)
{
    HWND hWnd;

    hWnd = CreateWindow(szClassName,
                        szAppName,
                        WS_OVERLAPPEDWINDOW,
                        CW_USEDEFAULT,
                        0,
                        CW_USEDEFAULT,
                        0,
                        NULL,
                        NULL,
                        hInstance,
                        NULL);
    if (hWnd)
    {
        ShowWindow(hWnd, nShowCmd);
        UpdateWindow(hWnd);
    }

    return hWnd;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    HWND hWnd;
    MSG msg;
    INITCOMMONCONTROLSEX ictrl;

    ictrl.dwICC = ICC_TREEVIEW_CLASSES;
    ictrl.dwSize = sizeof(ictrl);
    InitCommonControlsEx(&ictrl);

    MyRegisterClass(hInstance, szClassName);
    hWnd = MyInitWindow(hInstance, nShowCmd);

    
    RegisterTreeViewClass(hInstance, szTreeViewClass);
    hTreeview = CreateTreeview(hWnd, hInstance);

    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return msg.wParam;
}

Er is in Nederland niets beter beveiligd dan de snelwegen m.b.v. mobiele flitsteams, flitspalen, (on)opvallende surveillance-auto's, etc. Als er in mijn huis wordt ingebroken, dan kan ik beter de A2 oprennen dan 112 bellen.


  • .oisyn
  • Registratie: September 2000
  • Laatst online: 03-09 13:30

.oisyn

Moderator Devschuur®

Demotivational Speaker

simpel: je WM_CREATE retourneert NULL, waardoor het maken van de treeview gecanceled wordt :)

vang WM_CREATE niet af (dus gooi m door naar DefWindowProc), of retourneer TRUE

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.