DevCpp Listview geht nicht?



  • Hallo,

    ich bin nich ein Greennhorn, was c++ angeht, möchte micht aber gerne mehr damit befassen. Jetzt habe ich versucht, in das Beispiel "Wintest" ein Listview einzufügen, was aber überhaupt nicht klappen will.

    Hier mal der Quelltext mit den Änderungen:

    #include <windows.h>
    
    #include <string.h>
    #include <iostream>
    #include <commctrl.h>
    
    #define LVS_OWNERDATA           0x1000
    
    HWND hwndMain;
    
    LRESULT CALLBACK
    MainWndProc (HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
    {
    
    static HWND hwndButton = 0;
    static HWND hwndListView;
    static int cx, cy;/* Height and width of our button. */
    
    HDC hdc;/* A device context used for drawing */
    PAINTSTRUCT ps;/* Also used during window drawing */
    RECT rc;/* A rectangle used during drawing */
    
    switch (nMsg)
    {
    case WM_CREATE:
    {
    
    TEXTMETRIC tm;
    int dwStyle;
    
    hdc = GetDC (hwnd);
    SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT));
    GetTextMetrics (hdc, &tm);
    cx = tm.tmAveCharWidth * 30;
    cy = (tm.tmHeight + tm.tmExternalLeading) * 2;
    ReleaseDC (hwnd, hdc);
    
    dwStyle = WS_TABSTOP |
            WS_CHILD |
            WS_BORDER |
            WS_VISIBLE |
            LVS_AUTOARRANGE |
            LVS_REPORT |
            LVS_OWNERDATA;
    
    hwndButton = CreateWindow ("button","Click Here",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                    0, 0, cx, cy,hwnd,(HMENU) 1,((LPCREATESTRUCT) lParam)->hInstance,NULL);
    
    hwndListView = CreateWindowEx(WS_EX_CLIENTEDGE,"SysListView",TEXT(""),dwStyle,10,10,100,100,hwndMain,(HMENU)1,((LPCREATESTRUCT) lParam)->hInstance,NULL);                       
    
    return 0;
    break;
    }
    
    case WM_DESTROY:
    
    PostQuitMessage (0);
    return 0;
    break;
    
    case WM_PAINT:
    
    hdc = BeginPaint (hwnd, &ps);
    GetClientRect (hwnd, &rc);
    
    rc.bottom = rc.bottom / 2;
    DrawText (hdc, "Hello, World!", -1, &rc,
    DT_SINGLELINE | DT_CENTER | DT_VCENTER);
    
    EndPaint (hwnd, &ps);
    return 0;
    break;
    
    case WM_SIZE:
    
    if (hwndButton &&
    (wParam == SIZEFULLSCREEN ||
     wParam == SIZENORMAL)
       )
    {
    rc.left = (LOWORD(lParam) - cx) / 2;
    rc.top = HIWORD(lParam) * 3 / 4 - cy / 2;
    MoveWindow (
    hwndButton,
    rc.left, rc.top, cx, cy, TRUE);
    }
    break;
    
    case WM_COMMAND:
    
    if (LOWORD(wParam) == 1 &&
        HIWORD(wParam) == BN_CLICKED &&
        (HWND) lParam == hwndButton)
    {
    /* Our button was clicked. Close the window. */
    DestroyWindow (hwnd);
    }
    return 0;
    break;
    }
    
    return DefWindowProc (hwnd, nMsg, wParam, lParam);
    }
    
    int STDCALL
    WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
    {
    
    MSG msg;/* A Win32 message structure. */
    WNDCLASSEX wndclass;/* A window class structure. */
    char*szMainWndClass = "WinTestWin";
    
    memset (&wndclass, 0, sizeof(WNDCLASSEX));
    wndclass.lpszClassName = szMainWndClass;
    wndclass.cbSize = sizeof(WNDCLASSEX);
    wndclass.style = CS_HREDRAW | CS_VREDRAW;
    wndclass.lpfnWndProc = MainWndProc;
    wndclass.hInstance = hInst;
    wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
    wndclass.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
    
    RegisterClassEx (&wndclass);
    
    hwndMain = CreateWindow (
    szMainWndClass,/* Class name */
    "Hello",/* Caption */
    WS_OVERLAPPEDWINDOW,/* Style */
    CW_USEDEFAULT,/* Initial x (use default) */
    CW_USEDEFAULT,/* Initial y (use default) */
    CW_USEDEFAULT,/* Initial x size (use default) */
    CW_USEDEFAULT,/* Initial y size (use default) */
    NULL,/* No parent window */
    NULL,/* No menu */
    hInst,/* This program instance */
    NULL/* Creation parameters */
    );
    
    InitCommonControls();
    
    ShowWindow (hwndMain, nShow);
    UpdateWindow (hwndMain);
    
    while (GetMessage (&msg, NULL, 0, 0))
    {
    TranslateMessage (&msg);
    DispatchMessage (&msg);
    }
    return msg.wParam;
    }
    

    Es wäre schön, wenn mir jemand sagen könnte, was hier falsch iszt, oder warum das nicht geht.

    Vielen Dank!

    Gruss
    Eckhard1



  • hi

    das hat nix mit c++ zu tun, das ist winapi (und damit eher "c-style", kein c++).
    auch nichts mit dem dev cpp. frage das nächste mal am besten im winapi forum 🙂

    ein paar anmerkungen, so läuft es bei mir.. ein paar seltsame sache auskommentiert:

    #include <windows.h>
    #include <string.h>
    #include <iostream>
    #include <commctrl.h>
    
    #define LVS_OWNERDATA           0x1000
    
    HWND hwndMain;
    
    LRESULT CALLBACK MainWndProc (HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
    {
    
    	static HWND hwndButton = 0;
    	static HWND hwndListView;
    	static int cx, cy;/* Height and width of our button. */
    
    	HDC hdc;/* A device context used for drawing */
    	PAINTSTRUCT ps;/* Also used during window drawing */
    	RECT rc;/* A rectangle used during drawing */
    
    	switch (nMsg)
    	{
    		case WM_CREATE:
    	{
    
    		TEXTMETRIC tm;
    		int dwStyle;
    
    		hdc = GetDC (hwnd);
    		SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT));
    		GetTextMetrics (hdc, &tm);
    		cx = tm.tmAveCharWidth * 30;
    		cy = (tm.tmHeight + tm.tmExternalLeading) * 2;
    		ReleaseDC (hwnd, hdc);
    
    		dwStyle = WS_TABSTOP |
    				WS_CHILD |
    				WS_BORDER |
    				WS_VISIBLE |
    				LVS_AUTOARRANGE |
    				LVS_REPORT |
    				LVS_OWNERDATA;
    
    		hwndButton = CreateWindow ("button","Click Here",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
    						0, 0, cx, cy,hwnd,(HMENU) 1,((LPCREATESTRUCT) lParam)->hInstance,NULL);
    
    		hwndListView = CreateWindowEx(WS_EX_CLIENTEDGE,"SysListView",TEXT(""),dwStyle,10,10,100,100,hwndMain,(HMENU)1,((LPCREATESTRUCT) lParam)->hInstance,NULL);                      
    
    		return 0;
    		break;
    	}
    
    		case WM_DESTROY:{
    
    		PostQuitMessage (0);
    		return 0;
    		break;
    
    		case WM_PAINT:
    
    		hdc = BeginPaint (hwnd, &ps);
    		GetClientRect (hwnd, &rc);
    
    		rc.bottom = rc.bottom / 2;
    		DrawText (hdc, "Hello, World!", -1, &rc,
    		DT_SINGLELINE | DT_CENTER | DT_VCENTER);
    
    		EndPaint (hwnd, &ps);
    	//	return 0;		//??????????????
    		break;
    						}
    
    		case WM_SIZE:{
    
    						if (hwndButton && (wParam == SIZEFULLSCREEN || wParam == SIZENORMAL) )
    						{
    							rc.left = (LOWORD(lParam) - cx) / 2;
    							rc.top = HIWORD(lParam) * 3 / 4 - cy / 2;
    							MoveWindow (
    							hwndButton,
    							rc.left, rc.top, cx, cy, TRUE);
    						}
    						break;
    					 }
    
    		case WM_COMMAND:{
    
    						if ((LOWORD(wParam) == 1 &&HIWORD(wParam) == BN_CLICKED &&(HWND) lParam == hwndButton) )
    						{
    							/* Our button was clicked. Close the window. */
    							DestroyWindow (hwnd);
    						}
    							//return 0;//????????????
    							break;
    						}
    	}
    
    	return DefWindowProc (hwnd, nMsg, wParam, lParam);
    }
    
    //!!!!!!
    
    int WINAPI WinMain (HINSTANCE hInst,    //Kennzahl für die aktuelle Programminstanz
                        HINSTANCE hPrevInstance,//Kennzahl für die aktuell ev. schon laufende Programminstanz
                        LPSTR lpCmdLine,        //Zeiger auf Kommandozeilenparameter
                        int nShow)           //anfängliche Erscheinungsform des Fensters
    {
    
    	MSG msg;/* A Win32 message structure. */
    	WNDCLASSEX wndclass;/* A window class structure. */
    	char*szMainWndClass = "WinTestWin";
    
    	memset (&wndclass, 0, sizeof(WNDCLASSEX));
    	wndclass.lpszClassName = szMainWndClass;
    	wndclass.cbSize = sizeof(WNDCLASSEX);
    	wndclass.style = CS_HREDRAW | CS_VREDRAW;
    	wndclass.lpfnWndProc = MainWndProc;
    	wndclass.hInstance = hInst;
    	wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    	wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    	wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
    	wndclass.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
    
    	RegisterClassEx (&wndclass);
    
    	hwndMain = CreateWindow (
    		szMainWndClass,/* Class name */
    		"Hello",/* Caption */
    		WS_OVERLAPPEDWINDOW,/* Style */
    		CW_USEDEFAULT,/* Initial x (use default) */
    		CW_USEDEFAULT,/* Initial y (use default) */
    		CW_USEDEFAULT,/* Initial x size (use default) */
    		CW_USEDEFAULT,/* Initial y size (use default) */
    		NULL,/* No parent window */
    		NULL,/* No menu */
    		hInst,/* This program instance */
    		NULL/* Creation parameters */
    	);
    
    	//InitCommonControls();		//??????????????????
    
    	ShowWindow (hwndMain, nShow);
    	UpdateWindow (hwndMain);
    
    	while (GetMessage (&msg, NULL, 0, 0))
    	{
    		TranslateMessage (&msg);
    		DispatchMessage (&msg);
    	}
    	return msg.wParam;
    }
    

    bye 🙂



  • wieso stellst du die frage zweimal

    ??

    http://www.c-plusplus.net/forum/viewtopic.php?t=73195&highlight=
    nerv.


Anmelden zum Antworten