hilfe beim hintergrund



  • hallo,

    bin ganz neu in sachen programmierung. habe jetzt mein erstes prog geschrieben und möchte als hintergrund ein bild von einem auto. ist das möglich? wenn ja, kann mir jmd sagen, was und wie ich es in meinen code eingeben kann?

    vielen dank im voraus
    neuling
    code von dev 4.9.8 und win 98 bzw 2000:

    #include <windows.h>

    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    PSTR szCmdLine, int iCmdShow)
    {
    MSG msg;
    HWND hWnd;
    WNDCLASS wc;

    const char szAppName[] = "Windows Buttons";

    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hInstance = hInstance;
    wc.lpfnWndProc = WndProc;
    wc.lpszClassName = szAppName;
    wc.lpszMenuName = NULL;
    wc.style = CS_HREDRAW | CS_VREDRAW;

    RegisterClass(&wc);

    hWnd = CreateWindow( szAppName,
    szAppName,
    WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    NULL,
    NULL,
    hInstance,
    NULL);

    ShowWindow(hWnd, iCmdShow);
    UpdateWindow(hWnd);

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

    return msg.wParam;
    }

    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {

    static HWND Button;

    switch (message)
    {
    case WM_CREATE:
    {

    Button1 = CreateWindow( "button",
    "Ampel",
    WS_CHILD | WS_VISIBLE,
    0, 0, 0, 0,
    hWnd,
    NULL,
    ((LPCREATESTRUCT) lParam) -> hInstance,
    NULL);

    return 0;
    }
    case WM_SIZE:
    {

    MoveWindow(Button, LOWORD(lParam) / 2 - 80, HIWORD(lParam) - 30,
    160, 22, TRUE);

    return 0;
    }

    case WM_COMMAND:
    {
    if (lParam == (LPARAM)Button)
    {
    if (HIWORD(wParam) == BN_CLICKED)
    _outp(0x378,1);
    sleep(1400);
    _outp(0x378,9);
    sleep(1400);
    _outp(0x378,13);
    sleep(1400);
    _outp(0x378,29);
    sleep(1400);
    _outp(0x378,61);
    sleep(1400);
    _outp(0x378,2);
    sleep(4000);
    _outp(0x378,0);
    }
    if (lParam == (LPARAM)Button2)
    {
    if (HIWORD(wParam) == BN_CLICKED)
    SendMessage(hWnd, WM_CLOSE, 0, 0);
    }
    return 0;
    }
    case WM_DESTROY:
    {
    PostQuitMessage(0);
    return 0;
    }
    }
    return DefWindowProc(hWnd, message, wParam, lParam);
    }



  • Bitte beim nächsten mal Cpp-tag's benutzen.

    #include <windows.h>
    
    char* pcBmp = "xyz.bmp";
    HINSTANCE hInst;
    
    LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
    
    INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
    {
    WNDCLASSEX WndCls;
    static char szAppName[] = "Proggingmanias Simple Bitmap Window";
    MSG Msg;
    
    hInst = hInstance;
    WndCls.cbSize = sizeof(WndCls);
    WndCls.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
    WndCls.lpfnWndProc = WindProcedure;
    WndCls.cbClsExtra = 0;
    WndCls.cbWndExtra = 0;
    WndCls.hInstance = hInst;
    WndCls.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    WndCls.hCursor = LoadCursor(NULL, IDC_ARROW);
    WndCls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    WndCls.lpszMenuName = NULL;
    WndCls.lpszClassName = szAppName;
    WndCls.hIconSm = LoadIcon(hInstance, IDI_APPLICATION);
    RegisterClassEx(&WndCls);
    
    CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,
    szAppName,
    "Proggingmanias Simple Bitmap Window",
    WS_OVERLAPPEDWINDOW | WS_VISIBLE,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    NULL,
    NULL,
    hInstance,
    NULL);
    
    while( GetMessage(&Msg, NULL, 0, 0) )
    {
    TranslateMessage(&Msg);
    DispatchMessage( &Msg);
    }
    
    return (Msg.wParam);
    }
    
    LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg,
    WPARAM wParam, LPARAM lParam)
    {
    HDC hDC, MemDC;
    PAINTSTRUCT Ps;
    HBITMAP hbmp;
    char buf[256];
    
    RECT r;
    GetWindowRect( hWnd, &r );
    
    switch(Msg)
    {
    case WM_DESTROY:
    PostQuitMessage(WM_QUIT);
    break;
    case WM_PAINT:
    hDC = BeginPaint(hWnd, &Ps);
    
    hbmp = (HBITMAP)LoadImage(NULL, pcBmp, IMAGE_BITMAP, 0, 0,
    LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
    
    if ( !hbmp )
    {
    
    MessageBox( hWnd, buf, "Picture not found", MB_OK );
    ExitProcess(1);
    }
    
    // Create a memory device compatible with the above DC variable
    MemDC = CreateCompatibleDC(hDC);
    // Select the new bitmap
    SelectObject(MemDC, hbmp);
    
    // Copy the bits from the memory DC into the current dc
    BitBlt(hDC, 0, 0, r.right, r.bottom, MemDC, 0, 0, SRCCOPY);
    
    // Restore the old bitmap
    DeleteDC(MemDC);
    DeleteObject(hbmp);
    EndPaint(hWnd, &Ps);
    break;
    
    default:
    return DefWindowProc(hWnd, Msg, wParam, lParam);
    }
    return 0;
    }
    


  • pivke schrieb:

    Bitte beim nächsten mal Cpp-tag's benutzen.

    Bitte beim nächsten Mal Cpp-Tags so hinzufügen, dass die Einrückung nicht verlorengeht. Und den Apostroph weglassen 😉

    #include <windows.h>
    
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
                       PSTR szCmdLine, int iCmdShow)
    {
       MSG        msg;
       HWND       hWnd;
       WNDCLASS   wc;
    
       const char szAppName[]  = "Windows Buttons";
    
       wc.cbClsExtra           = 0;
       wc.cbWndExtra           = 0;
       wc.hbrBackground        = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
       wc.hCursor              = LoadCursor(NULL, IDC_ARROW);
       wc.hIcon                = LoadIcon(NULL, IDI_APPLICATION);
       wc.hInstance            = hInstance;
       wc.lpfnWndProc          = WndProc;
       wc.lpszClassName        = szAppName;
       wc.lpszMenuName         = NULL;
       wc.style                = CS_HREDRAW | CS_VREDRAW;
    
       RegisterClass(&wc);
    
       hWnd = CreateWindow(    szAppName,
                               szAppName,
                               WS_OVERLAPPEDWINDOW,
                               CW_USEDEFAULT,
                               CW_USEDEFAULT,
                               CW_USEDEFAULT,
                               CW_USEDEFAULT,
                               NULL,
                               NULL,
                               hInstance,
                               NULL);
    
       ShowWindow(hWnd, iCmdShow);
       UpdateWindow(hWnd);
    
       while (GetMessage(&msg, NULL, 0, 0))
       {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
       }
    
       return msg.wParam;
    }
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    
       static HWND Button;
    
       switch (message)
       {
       case WM_CREATE:
          {
    
             Button1 = CreateWindow(  "button",
                                      "Ampel",
                                      WS_CHILD | WS_VISIBLE,
                                      0, 0, 0, 0,
                                      hWnd,
                                      NULL,
                                      ((LPCREATESTRUCT) lParam) -> hInstance,
                                      NULL);
    
             return 0;
          }
       case WM_SIZE:
          {
    
             MoveWindow(Button, LOWORD(lParam) / 2 - 80, HIWORD(lParam) - 30, 
                                                               160, 22, TRUE);
    
             return 0;
          }
    
       case WM_COMMAND:
          {
             if (lParam == (LPARAM)Button)
             {
                if (HIWORD(wParam) == BN_CLICKED)
                  _outp(0x378,1);
                  sleep(1400);
                  _outp(0x378,9);
                  sleep(1400);
                  _outp(0x378,13);
                  sleep(1400);
                  _outp(0x378,29);
                  sleep(1400);
                  _outp(0x378,61);
                  sleep(1400);
                  _outp(0x378,2);
                  sleep(4000);
                  _outp(0x378,0);
             }
             if (lParam == (LPARAM)Button2)
             {
                if (HIWORD(wParam) == BN_CLICKED)
                   SendMessage(hWnd, WM_CLOSE, 0, 0);
             }
             return 0;
          }
       case WM_DESTROY:
          {
             PostQuitMessage(0);
             return 0;
          }
       }
       return DefWindowProc(hWnd, message, wParam, lParam);
    }
    


  • das hat mir sehr weitergeholfen!

    vielen dank



  • neuling1000 schrieb:

    das hat mir sehr weitergeholfen!

    vielen dank

    ironie?



  • lippoliv schrieb:

    neuling1000 schrieb:

    das hat mir sehr weitergeholfen!

    vielen dank

    ironie?

    Sarkasmus.

    Zum Thema...
    Hier ein paar Schlagwörter von Funktionen: LoadImage (), StretchBlt () bzw. BitBlt ().



  • Am besten nicht .ico sondern .bmp 🙂

    Du solltest manche Kommentare zur kenntnis nehmen!



  • Meinst du mich?



  • ich glaube er weiß es selbst nicht, wen er meint 😉 in dem ganzen thread gibts nix mit icons.. nur halt das programmicon... und da sollte man kein bitmap nehmen 😉



  • Machine schrieb:

    ich glaube er weiß es selbst nicht, wen er meint 😉 in dem ganzen thread gibts nix mit icons.. nur halt das programmicon... und da sollte man kein bitmap nehmen 😉

    ja deshalb habe ich auch nochmal nachgefragt...



  • Nein sry, das ging an neuling1000

    Ich meine Quellcode über 100 Zeilen ohne cpp-tag zu lesen macht ca. 0 sinn.

    Da fehlt mindestens die Einrückung.

    türlich weis ich nich was ich meine... Hintergrundbilder ohne BMP?
    Es geht schließlich um Hintergrundbilder...



  • lippoliv schrieb:

    Nein sry, das ging an neuling1000

    Ich meine Quellcode über 100 Zeilen ohne cpp-tag zu lesen macht ca. 0 sinn.

    Da fehlt mindestens die Einrückung.

    türlich weis ich nich was ich meine... Hintergrundbilder ohne BMP?
    Es geht schließlich um Hintergrundbilder...

    und wo hat er geschrieben, dass er nen icon als hintergrund nutzen will? 😮



  • Wieso nen Icon als Hintergrund?

    Ich wollte mal n Hintergrund machen und habs erst mit .ico versucht, weil die Transparenz können...
    Lief aber nich soo geil. 😉



  • du sprichst für mich in rätseln... aber egal...



  • Der Thread ist doch schon gelöst, nicht das er noch in den Offtopic rutscht...
    😉



  • pivke schrieb:

    Der Thread ist doch schon gelöst, nicht das er noch in den Offtopic rutscht...
    😉

    Ist er das? Es wurde die dafür benötigten Funktionen genannt, aber wenn er wirklich neu in der WinAPI-Programmierung ist, dann wird er bestimmt noch die ein oder andere Frage haben.


Anmelden zum Antworten