Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

Gotbread

Alter Hase

  • »Gotbread« ist der Autor dieses Themas

Beiträge: 421

Beruf: Student (Etechnik) + Hiwi

  • Private Nachricht senden

1

13.03.2010, 23:06

Drag'n'Drop auf eine ListView

Hallo

Ich möchte eine Listbox Drag'n'Drop fähig machen.
Allerdings gibt es dabei probleme.

Wenn ich die listview mit DragAcceptFiles registriere, tut sich nichts.
ich bekomme auch keine WM_DROPFILES nachricht. auch über WM_NOTIFIY
werde ich nicht darüber informiert.

habe schon alles abgesucht, es will einfach nicht...
Mfg Goti
www.gotbread.bplaced.net
viele tolle spiele kostenlos, viele hardware-basteleien :)

"Es ist nicht undicht, es läuft über" - Homer Simpson

David_pb

Community-Fossil

Beiträge: 3 886

Beruf: 3D Graphics Programmer

  • Private Nachricht senden

2

14.03.2010, 12:52

Hab mal ein Beispiel gemacht:

C-/C++-Quelltext

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
#include <windows.h>
#include <tchar.h>

LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
LRESULT CALLBACK DragDropProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
    static PTCHAR cls_name = _T( "cls_test" );

    WNDCLASS wc =
    {
        0,
        WndProc,
        0, 0,
        hInstance,
        LoadIcon( NULL, IDI_APPLICATION ),
        LoadCursor( NULL, IDC_ARROW ),
        GetSysColorBrush( COLOR_BTNFACE ),
        NULL,
        cls_name
    };

    if ( !RegisterClass( &wc ) ) {
        return 0;
    }

    HWND hWnd = CreateWindow( cls_name, _T( "Test" ), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL );
    if ( !hWnd ) {
        return 0;
    }

    // Create Control

    HWND hWndChild = CreateWindowEx( WS_EX_CLIENTEDGE, _T( "LISTBOX" ), _T( "" ), WS_CHILD | WS_VISIBLE, 10, 10, 250, 250, hWnd, NULL, hInstance, NULL );
    if ( hWndChild ) {
        DragAcceptFiles( hWndChild, TRUE );
        WNDPROC dragDropProc = MakeProcInstance( DragDropProc, hInstance );

        if ( dragDropProc )
        {
            WNDPROC oldProc = ( WNDPROC )SetWindowLong( hWndChild, GWL_WNDPROC, ( LONG )dragDropProc );
            SetWindowLong( hWndChild, GWL_USERDATA, ( LONG )oldProc );
        }
    }

    ShowWindow( hWnd, SW_SHOW );
    UpdateWindow( hWnd );

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

LRESULT CALLBACK DragDropProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    WNDPROC fwdProc = ( WNDPROC )GetWindowLong( hWnd, GWL_USERDATA );

    switch ( msg )
    {
    case WM_DROPFILES:
    {
        HDROP hDrop = ( HDROP )wParam;
        UINT count = DragQueryFile( hDrop, -1, 0, 0 );

        TCHAR file[MAX_PATH];
        for ( UINT i = 0; i < count; ++i )
        {
            DragQueryFile( hDrop, i, file, MAX_PATH );
            SendMessage( hWnd, LB_ADDSTRING, 0, ( LPARAM )file );
        }

        DragFinish( hDrop );
    }
    break;

    default:
        return fwdProc != NULL ? CallWindowProc( fwdProc, hWnd, msg, wParam, lParam ) : 0;
    }

    return 0;
}

LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    switch ( msg )
    {
    case WM_CLOSE:
        PostQuitMessage(0);
        break;

    default:
        return DefWindowProc( hWnd, msg, wParam, lParam );
    }

    return 0;
}

Gotbread

Alter Hase

  • »Gotbread« ist der Autor dieses Themas

Beiträge: 421

Beruf: Student (Etechnik) + Hiwi

  • Private Nachricht senden

3

14.03.2010, 14:22

danke für das beispiel, David_pb, allerdings meinte ich eine listview.

ich hab es bereits versucht mit:

DragAcceptFiles()
RegisterDragDrop(), mit eigenem IDropTarget
das control gesubclasst
WS_EX_ACCEPTFILES

sowie auch in kombination. das listview (WC_LISTVIEW -> "SysListView32")
will einfach nicht...
Mfg Goti
www.gotbread.bplaced.net
viele tolle spiele kostenlos, viele hardware-basteleien :)

"Es ist nicht undicht, es läuft über" - Homer Simpson

David_pb

Community-Fossil

Beiträge: 3 886

Beruf: 3D Graphics Programmer

  • Private Nachricht senden

4

14.03.2010, 15:34

Das geht doch ganz genauso...

C-/C++-Quelltext

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
#include <windows.h>
#include <tchar.h>
#include <CommCtrl.h>

LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
LRESULT CALLBACK DragDropProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
    static PTCHAR cls_name = _T( "cls_test" );

    WNDCLASS wc =
    {
        0,
        WndProc,
        0, 0,
        hInstance,
        LoadIcon( NULL, IDI_APPLICATION ),
        LoadCursor( NULL, IDC_ARROW ),
        GetSysColorBrush( COLOR_BTNFACE ),
        NULL,
        cls_name
    };

    if ( !RegisterClass( &wc ) ) {
        return 0;
    }

    HWND hWnd = CreateWindow( cls_name, _T( "Test" ), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL );
    if ( !hWnd ) {
        return 0;
    }

    // Create Control

    HWND hWndChild = CreateWindowEx( WS_EX_CLIENTEDGE, WC_LISTVIEW, _T( "" ), WS_CHILD | WS_VISIBLE | LVS_REPORT, 10, 10, 250, 250, hWnd, NULL, hInstance, NULL );
    if ( hWndChild ) 
    {
        LVCOLUMN column;
        column.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT;
        column.fmt = LVCFMT_LEFT;
        column.cx = 250;
        column.pszText = _T( "Dateiname" );
        ListView_InsertColumn( hWndChild, 0, &column );

        DragAcceptFiles( hWndChild, TRUE );
        WNDPROC dragDropProc = MakeProcInstance( DragDropProc, hInstance );

        if ( dragDropProc )
        {
            WNDPROC oldProc = ( WNDPROC )SetWindowLong( hWndChild, GWL_WNDPROC, ( LONG )dragDropProc );
            SetWindowLong( hWndChild, GWL_USERDATA, ( LONG )oldProc );
        }
    }

    ShowWindow( hWnd, SW_SHOW );
    UpdateWindow( hWnd );

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

LRESULT CALLBACK DragDropProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    WNDPROC fwdProc = ( WNDPROC )GetWindowLong( hWnd, GWL_USERDATA );

    switch ( msg )
    {
    case WM_DROPFILES:
    {
        HDROP hDrop = ( HDROP )wParam;
        UINT count = DragQueryFile( hDrop, -1, 0, 0 );

        TCHAR file[MAX_PATH];
        for ( UINT i = 0; i < count; ++i )
        {
            DragQueryFile( hDrop, i, file, MAX_PATH );
            LVITEM item = {0};
            item.mask = LVIF_TEXT;
            item.pszText = file;
            ListView_InsertItem( hWnd, &item );
        }

        DragFinish( hDrop );
    }
    break;

    default:
        return fwdProc != NULL ? CallWindowProc( fwdProc, hWnd, msg, wParam, lParam ) : 0;
    }

    return 0;
}

LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    switch ( msg )
    {
    case WM_CLOSE:
        PostQuitMessage(0);
        break;

    default:
        return DefWindowProc( hWnd, msg, wParam, lParam );
    }

    return 0;
}

Gotbread

Alter Hase

  • »Gotbread« ist der Autor dieses Themas

Beiträge: 421

Beruf: Student (Etechnik) + Hiwi

  • Private Nachricht senden

5

14.03.2010, 16:20

hm es funzt... such grade bei mir den fehler, aber im prinzip habichs genaso gemacht.
Mfg Goti
www.gotbread.bplaced.net
viele tolle spiele kostenlos, viele hardware-basteleien :)

"Es ist nicht undicht, es läuft über" - Homer Simpson

David_pb

Community-Fossil

Beiträge: 3 886

Beruf: 3D Graphics Programmer

  • Private Nachricht senden

6

14.03.2010, 16:27

Zeig ggf mal den entsprechenden Codeteil.

Gotbread

Alter Hase

  • »Gotbread« ist der Autor dieses Themas

Beiträge: 421

Beruf: Student (Etechnik) + Hiwi

  • Private Nachricht senden

7

14.03.2010, 17:01

wenn ich das fenster so erzeuge, wie du es geschrieben hast, funktioniert es.
wenn ich mein framework nutze, und dessen handle als parent nehme,
habe ich zwar eine listview, jedoch arbeitet diese nicht mit dragndrop zusammen.

kann das daran liegen, dass das framework in einer dll liegt?

main.cpp

C-/C++-Quelltext

1
2
3
Window::CreateParams wndparams("titel", 520, 520);
wndparams.windowstyle = WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX;
window = CreateNewWindow(&wndparams);


createparams::createparams() - ctor

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Window::CreateParams::CreateParams(const char *ptitle, unsigned uwidth, unsigned uheight)
        {
            title = ptitle;
            width = uwidth;
            height = uheight;
            classname = 0;
            x = CW_USEDEFAULT;
            y = CW_USEDEFAULT;
            func = 0;
            extendedstyle = 0;
            windowstyle = WS_BORDER | WS_SYSMENU;
            classstyle = CS_HREDRAW | CS_VREDRAW;
            menu = false;
            fullscreen = false;
            clientrect = true;
            exit_on_close = true;
            visible = true;
            background = RGB(255, 255, 255);
            parent = 0;
        }


windows.cpp

C-/C++-Quelltext

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
CWindow::CWindow(const CreateParams *p)
        {
            INITCOMMONCONTROLSEX InitCtrlEx;
            InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
            InitCtrlEx.dwICC  = ICC_PROGRESS_CLASS;
            InitCommonControlsEx(&InitCtrlEx);

            params = *p;

            id = 2;
            painting = 0;
            memdc = 0;
            membitmap = 0;
            oldbitmap = 0;
            menu = 0;
            deleteonclose = false;

            DWORD counter = GetTickCount(); // unique windowname

            classname[0 ] = 'W';
            classname[1 ] = 'i';
            classname[2 ] = 'n';
            classname[3 ] = 'd';
            classname[4 ] = 'o';
            classname[5 ] = 'w';
            classname[6 ] = ' ';
            classname[7 ] = static_cast<char>((counter >>  0) & 0xff);
            classname[8 ] = static_cast<char>((counter >>  8) & 0xff);
            classname[9 ] = static_cast<char>((counter >> 16) & 0xff);
            classname[10] = static_cast<char>((counter >> 24) & 0xff);
            classname[11] = 0;

            if (params.classname)
                strcpy(classname, params.classname);

            if (!params.windowstyle)
                params.windowstyle = WS_OVERLAPPEDWINDOW;

            if (params.fullscreen)
            {
                params.x = 0;
                params.y = 0;
                params.width  = GetSystemMetrics(SM_CXSCREEN);
                params.height = GetSystemMetrics(SM_CYSCREEN);
                params.windowstyle = WS_POPUP;
            }
            else if (params.clientrect)
            {
                RECT r;
                SetRect(&r, 0, 0, params.width, params.height);
                AdjustWindowRect(&r, params.windowstyle | WS_CAPTION, params.menu ? 1 : 0);
                params.width = r.right - r.left;
                params.height = r.bottom - r.top;
            }

            WNDCLASS wc;
            ZeroMemory(&wc, sizeof(wc));

            wc.cbWndExtra = sizeof(this); // space for a pointer to CWindow (this-pointer)

            wc.hbrBackground = background = CreateSolidBrush(params.background);
            wc.hCursor = LoadCursor(0, IDC_ARROW);
            wc.hIcon = 0;
            wc.hInstance = GetModuleHandle(0);
            wc.lpfnWndProc = WindowProc;
            wc.lpszClassName = classname;
            wc.lpszMenuName = 0;
            wc.style = params.classstyle;

            RegisterClass(&wc); // *never* fails


            hWnd = CreateWindowEx(params.extendedstyle | (params.fullscreen ? WS_EX_TOPMOST : 0), wc.lpszClassName,
                params.title, params.windowstyle,
                params.x, params.y, params.width, params.height, params.parent, 0, wc.hInstance, this);

            if (hWnd && params.visible)
                ShowWindow(hWnd, SW_SHOWNORMAL);
        }


als parent nehme ich das hWnd.
das control erzeuge ich genauso wie David_bp
Mfg Goti
www.gotbread.bplaced.net
viele tolle spiele kostenlos, viele hardware-basteleien :)

"Es ist nicht undicht, es läuft über" - Homer Simpson

David_pb

Community-Fossil

Beiträge: 3 886

Beruf: 3D Graphics Programmer

  • Private Nachricht senden

8

14.03.2010, 17:36

Nein, die Dll sollte eigentlich unproblematisch sein. Der Code sieht soweit auch ok aus. Zeig trotzdem noch mal den Rest wo das Fenster + Control erzeugt wird und die MessageProcs.

Gotbread

Alter Hase

  • »Gotbread« ist der Autor dieses Themas

Beiträge: 421

Beruf: Student (Etechnik) + Hiwi

  • Private Nachricht senden

9

14.03.2010, 18:32

main.cpp

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
int WINAPI WinMain(HINSTANCE, HINSTANCE, char *, int)
{
    OleInitialize(0);
    InitCommonControls();

    Application app;
    app.Run();

    return 0;
}


Application::Application() ctor

C-/C++-Quelltext

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
Application::Application()
{
    Window::CreateParams wndparams("title", 520, 520);
    wndparams.windowstyle = WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX;
    window = CreateNewWindow(&wndparams);

    net = CreateNewNetwork();

    window->UserPointer() = this;
    window->SetWindowFunction(WinApiWindowFunc);

        // allerlei controlls erzeugen


       HWND hWndChild = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, "", WS_CHILD | WS_VISIBLE | LVS_REPORT, 280, 90, 220, 150, window->GetHandle(), 0, GetModuleHandle(0), 0);
    if ( hWndChild )
    {
        LVCOLUMN column;
        column.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT;
        column.fmt = LVCFMT_LEFT;
        column.cx = 250;
        column.pszText = "Dateiname";
        ListView_InsertColumn( hWndChild, 0, &column );

        DragAcceptFiles( hWndChild, TRUE );
        WNDPROC dragDropProc = DragDropProc;

        if ( dragDropProc )
        {
            WNDPROC oldProc = ( WNDPROC )SetWindowLong( hWndChild, GWL_WNDPROC, ( LONG )dragDropProc );
            SetWindowLong( hWndChild, GWL_USERDATA, ( LONG )oldProc );
        }
    } 
  
    // ...


die wndfunc is im augenblick noch leer, die dragDropProc is 1zu1 übernommen.
Mfg Goti
www.gotbread.bplaced.net
viele tolle spiele kostenlos, viele hardware-basteleien :)

"Es ist nicht undicht, es läuft über" - Homer Simpson

David_pb

Community-Fossil

Beiträge: 3 886

Beruf: 3D Graphics Programmer

  • Private Nachricht senden

10

14.03.2010, 19:38

Und die Messagepump befindet sich in Application::Run()?

Werbeanzeige