Probleme mit resourcen.



  • Hi@all

    ich möchte ein Bitmap in ein Projekt einbeziehen.
    dazu mache ich resource.h ->

    #define ID_IMAGE 000001
    

    resource.rc

    #include <windows.h>
    #include "resource.h"
    
    ID_IMAGE BITMAP "image.bmp"
    

    dan in der main hab ich den header included.

    fehler:

    h:\c++\projects\winfaker\resource.rc(4) : error C2059: Syntaxfehler: 'Konstante'
    

    was kann ich tun und wie kann ich das bild mit loadimage laden?
    danke.



  • //Edit total verpeilt... 🙄



  • für das laden des Bildes

    CBitmap::LoadBitmap(IDB_BITMAP);
    	CImageList::Create(x, x, ILC_COLOR(x), 3, 0);
    	CImageList::Add(&bitmap, RGB(cx, cx, cx));
    

    für x trägst du jeweils die größe des image ein (4,16,32...)
    für cx bestimmst du die rot grün blau werte die zusammen die Farbe ergeben die transparent erscheinen soll



  • wie verpeilt?
    was ist mit dem kompiler-error?
    thx. sind die resourcen richtig?



  • Load dir mal Dev Cpp runter da gibst ein Ball spiel bei den ordner Example - das ist eigenlich ganz einfach und noch nen tipp an alle anfänger: schreibt mal einfach so ne win_api ab (kleines fenter mit button) dann versteht ihr C++ und wie einfach es ist 😉



  • hallo?
    ich hab schon ma so ne fenster-exe gemacht.
    aber ich will jetzt wissen, wo der fehler in der resource liegt.
    ich hab noch nie mit resource-dateien gearbeitet.
    cu.



  • in eine recourche kommen meist nur nen paar schane rein :

    recource:

    BALLBMP BITMAP "ball.bmp"
    MASKBMP BITMAP "ballmask.bmp"
    

    das ist von ein Ballspiel von DevCpp



  • oh sorry :

    mach doch einfach ohne recource 😉 funtz auch

    code ist ausen forum (ka mehr voher)

    #include <windows.h> 
    
    char* pcBmp = "C:\\Bilder\\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; 
    }
    


  • ja ich habs ja schon ohne resourcen mit nem externen bmp.
    aber ich will WILL das aber mit resourcen unbedingt haben.
    sonst ist die exe nicht mehr so portabel.
    thx.



  • ja wie mach ich das jetz mit resourcen!!!
    thx.



  • erstell dir mit dem MFC ne resourcen.rc datei und füge sie in dein project ein. in der resourcen.h definierst du dann die entsprechenden resourcen.

    evtl kuckste hier mal rein
    http://www.winapi.net/index.php?inhalt=t6



  • guckmal ey ! man gibt dir 10 antworten und du : immer noch falsch! 😞

    sei mal mit dem zufrieden das man dir gib 😡


Anmelden zum Antworten