Fenster erstellen



  • Hallo eine Frage,

    Erstens: wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;

    Kann ich bei Erstens das (HBRUSH) weglassen oder gehört das da hin weil funktionieren tut es auch ohne das (HBRUSH)

    #include <windows.h>
    #include <iostream.h>
    using namespace std;
    
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
    {
    
    int win_width = 400;
    int win_height = 400;
    
         static char szAppName[] = "name" ;
         HWND        hwnd ;
         MSG         msg ;
    
         WNDCLASSEX  wndclass ;
    
         wndclass.cbSize        = sizeof (wndclass) ;
         wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
         wndclass.lpfnWndProc   = WndProc ;
    
         wndclass.cbClsExtra    = 0 ;
         wndclass.cbWndExtra    = 0 ;
    
         wndclass.hInstance     = hInstance ;
         wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
    
         wndclass.hCursor       = LoadCursor (NULL, IDC_CROSS	) ;
    
        //wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
        wndclass.hbrBackground =  GetStockObject (WHITE_BRUSH);
    
        wndclass.lpszClassName = szAppName ;
        wndclass.hIconSm       = LoadIcon (NULL, 0) ;
    
        RegisterClassEx (&wndclass) ;
    
        hwnd = CreateWindow (szAppName, "Fenstername", WS_OVERLAPPEDWINDOW,
    			  CW_USEDEFAULT, CW_USEDEFAULT, win_width , win_height ,
    			  NULL, NULL, hInstance, NULL) ;
    
         ShowWindow (hwnd, SW_SHOW) ;
         UpdateWindow (hwnd) ;
    
         while (GetMessage (&msg, NULL, 0, 0))
              {
              TranslateMessage (&msg) ;
              DispatchMessage (&msg) ;
              }
         return msg.wParam ;
    }
    
    LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
    {
    
         switch (iMsg)
         {
    
              case WM_DESTROY :
              PostQuitMessage (0) ;
              return 0 ;
    
         }
    
       return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
    
    }
    


  • in C kannst du's weglassen in C++ nicht.



  • Wenn es auch ohne geht, dann wird es halt implizit konvertiert.



  • Ehm und Implizit bedeutet ?

    Ich kenne nur Explizit.



  • http://de.wiktionary.org/wiki/implizit

    hbrBackground ist vom Typ HGDIOBJ, also MUSS konvertiert werden. Wird es auch, und zwar automatisch, wenn man es nicht explizit hinschreibt.


Anmelden zum Antworten