Buttons mit WinAPI



  • Hi ich brauch hilfe, habe sonst nichts gefunden...
    Unten habe ich mein erstes WinAPI Programm mit einem button da ich sonst eher mit directx programmiere, habe ich von WinAPI nicht mehr ahnung als ein leeres Fenster zu erstellen. Wenn ich das jetzt kompilliere erscheint ein Button in meinem programm. Wie kann ich nun eine Messagebox erscheinen lassen, wenn ich auf den button klicke? oder wie kann ich das Design des Buttons auf das von Vista uttons ändern?

    Gruß,
    cbacon

    // include the basic windows header files and the Direct3D header file
    #include <windows.h>
    #include <windowsx.h>
    #include <math.h>
    
    // the WindowProc function prototype
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
    
    HWND hWnd;
    
    // the entry point for any Windows program
    int WINAPI WinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPSTR lpCmdLine,
                       int nCmdShow)
    {
    
        WNDCLASSEX wc;
    
        ZeroMemory(&wc, sizeof(WNDCLASSEX));
    
        wc.cbSize = sizeof(WNDCLASSEX);
        wc.style = CS_HREDRAW | CS_VREDRAW;
        wc.lpfnWndProc = WindowProc;
        wc.hInstance = hInstance;
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
        wc.lpszClassName = "WindowClass";
    
        RegisterClassEx(&wc);
    
        hWnd = CreateWindowEx(NULL,
                              "WindowClass",
                              "Hallo WINAPI",
                              WS_OVERLAPPEDWINDOW,
                              CW_USEDEFAULT, CW_USEDEFAULT,
                              800, 600,
                              NULL,
                              NULL,
                              hInstance,
                              NULL);
    
    	CreateWindowEx(NULL, "Button", "Message",WS_CHILD | WS_VISIBLE  , 50, 50, 100, 30, hWnd, NULL, hInstance, NULL);
    
        ShowWindow(hWnd, nCmdShow);
    
        // set up and initialize Direct3D
    
        // enter the main loop:
    
        MSG msg;
        while(GetMessage(&msg, NULL, 0, 0))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    
        // clean up DirectX and COM
    
        return msg.wParam;
    }
    
    // this is the main message handler for the program
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch(message)
        {
            case WM_DESTROY:
                {
                    PostQuitMessage(0);
                    return 0;
                } break;
    
    		case WM_CLOSE:
    			PostQuitMessage(0);
    			break;
        }
    
        return DefWindowProc (hWnd, message, wParam, lParam);
    }
    


  • hey,
    du musst in die WndProc WM_COMMAND einfügen.

    case WM_COMMAND: 
    		switch(LOWORD(wParam))
    		{
    			case 2:
    				MessageBox
    				return 0;
    }
    break;
    

    Damit das case 2 aktiv wird, müsstest du hMenu in CreateWindow auf 2 setzen.



  • k danke hat (natürlich) funktioniert


Anmelden zum Antworten