Herzlich Willkommen, lieber Gast!
  Sie befinden sich hier:

  Forum » C / C++ (WinAPI, Konsole) » anfängerfrage

Forum | Hilfe | Team | Links | Impressum | > Suche < | Mitglieder | Registrieren | Einloggen
  Quicklinks: MSDN-Online || STL || clib Reference Grundlagen || Literatur || E-Books || Zubehör || > F.A.Q. < || Downloads   

Autor Thread - Seiten: > 1 <
000
30.06.2004, 20:31 Uhr
~guest
Gast



Code:

IDB_BALL BITMAP "test.bmp"


C++:
#include <windows.h>

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "Little Game";





LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HBITMAP g_hbmBall = NULL;

    switch (message)                  /* handle the messages */
    {

            
    case WM_COMMAND:
        
        if ( LOWORD (wParam) ==1)
        {    
            mciSendString("open \"test.mp3\" alias MP3", 0, 0, 0);
            mciSendString("play MP3 from 0 notify", NULL, 0,0);

        }
        
        
        if ( LOWORD (wParam) ==2)
        {    
            mciSendString("stop MP3",NULL,0,0);
            mciSendString("close MP3",NULL,0,0);

        }        
    return 0;  
          
    case WM_CREATE:
        g_hbmBall = LoadBitmap(GetModuleHandle(NULL), "IDB_BALL");
        if(g_hbmBall == NULL)
            MessageBox(hwnd, "Could not load IDB_BALL!", "Error", MB_OK | MB_ICONEXCLAMATION);
    break;
        
    case WM_PAINT:
    {
        BITMAP bm;
        PAINTSTRUCT ps;

        HDC hdc = BeginPaint(hwnd, &ps);

        HDC hdcMem = CreateCompatibleDC(hdc);
        HBITMAP hbmOld = SelectObject(hdcMem, g_hbmBall);

        GetObject(g_hbmBall, sizeof(bm), &bm);

        BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCPAINT);

        SelectObject(hdcMem, hbmOld);
        DeleteDC(hdcMem);

        EndPaint(hwnd, &ps);
    }
    break;
        
    case WM_DESTROY:
        DeleteObject(g_hbmBall);
        PostQuitMessage(0);
    break;            
            
            
    default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}






int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{
    HWND hwnd;               /* This is the handle for our window */
    static HANDLE hBitmap, hBitmap2, hBitmap3;
    static HWND hButton, hButton2, hButton3;
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    HBRUSH MyBrush = CreateSolidBrush(RGB(255, 0, 255));

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    //wincl.hbrBackground = MyBrush;
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    //wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
    wincl.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    
    
    
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Little Game",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           544,                 /* The programs width */
           375,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

           hButton2  = CreateWindow ( "button", "", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_BITMAP,
                             150, 150, 75, 20, hwnd, (HMENU)2,
                             (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);

           hBitmap2 = LoadImage (GetModuleHandle(NULL), "test2.bmp", IMAGE_BITMAP,0, 0,LR_DEFAULTCOLOR | LR_LOADFROMFILE);

           SendMessage(hButton2,BM_SETIMAGE,(WPARAM) IMAGE_BITMAP,(LPARAM)(HANDLE) hBitmap2);
          
           ////////////////////
      



           ////////////////////////////////////////
           hButton  = CreateWindow ( "button", "", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_BITMAP,
                             110, 100, 75, 20, hwnd, (HMENU)1,
                             (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);

           hBitmap= LoadImage (GetModuleHandle(NULL), "test2.bmp", IMAGE_BITMAP,0, 0,LR_DEFAULTCOLOR | LR_LOADFROMFILE);

           SendMessage(hButton,BM_SETIMAGE,(WPARAM) IMAGE_BITMAP,(LPARAM)(HANDLE) hBitmap);
          

          
    /* Make the window visible on the screen */
    ShowWindow (hwnd, nFunsterStil);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */


br>ich wüßte gern warum ich keine test- hintergrund-bitmap sehe.

// keine fehler beim compilieren
Resources |CODE||



Code |CPP||
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
001
30.06.2004, 21:41 Uhr
FloSoft
Medialer Over-Flow
(Administrator)


einfach LoadBitmap(NULL,MAKEINTRESOURCE(IDB_BITMAP)); benutzen, dann klappt das

(also nicht "IDB_BITMAP" sondern MAKEINTRESOURCE(IDB_BITMAP) )
--
class God : public ChuckNorris { };
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
002
30.06.2004, 23:31 Uhr
~guest
Gast


Nun sieht es so aus, aber funktioniert nicht. Nun geht die "MessageBox" auf und saget "Could not load IDB_BITMAP!" _ HABE ABER KEINE LINKER_ERROR



C++:
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{

LPCTSTR IDB_BITMAP;  
HBITMAP g_hbmBall = NULL;

    switch (message)                  /* handle the messages */
    {

            
    case WM_COMMAND:
        
        if ( LOWORD (wParam) ==1)
        {    
            mciSendString("open \"test.mp3\" alias MP3", 0, 0, 0);
            mciSendString("play MP3 from 0 notify", NULL, 0,0);

        }
        
        
        if ( LOWORD (wParam) ==2)
        {    
            mciSendString("stop MP3",NULL,0,0);
            mciSendString("close MP3",NULL,0,0);

        }        
    return 0;  
          
    case WM_CREATE:
        g_hbmBall = LoadBitmap(GetModuleHandle(NULL), "IDB_BITMAP");
        //g_hbmBall = LoadBitmap(NULL, MAKEINTRESOURCE(IDB_BITMAP));
        
        if(g_hbmBall == NULL)
            MessageBox(hwnd, "Could not load IDB_BITMAP!", "Error", MB_OK | MB_ICONEXCLAMATION);
    break;
        
    case WM_PAINT:
    {
        BITMAP bm;
        PAINTSTRUCT ps;

        HDC hdc = BeginPaint(hwnd, &ps);

        HDC hdcMem = CreateCompatibleDC(hdc);
        HBITMAP hbmOld = SelectObject(hdcMem, g_hbmBall);

        GetObject(g_hbmBall, sizeof(bm), &bm);

        BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCPAINT);

        SelectObject(hdcMem, hbmOld);
        DeleteDC(hdcMem);

        EndPaint(hwnd, &ps);
    }
    break;
        
    case WM_DESTROY:
        DeleteObject(g_hbmBall);
        PostQuitMessage(0);
    break;            
            
            
    default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
003
30.06.2004, 23:32 Uhr
typecast
aka loddab
(Operator)


Bitte das nächste mal einen Aussagekräftigen Titel benutzen. Wer kommt schon auf den Gedanken bei diesem Problem nach anfängerfrage zu suchen?
--
All parts should go together without forcing. ... By all means, do not use a hammer. (IBM maintenance manual, 1925)

Dieser Post wurde am 30.06.2004 um 23:33 Uhr von typecast editiert.
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
Seiten: > 1 <     [ C / C++ (WinAPI, Konsole) ]  


ThWBoard 2.73 FloSoft-Edition
© by Paul Baecher & Felix Gonschorek (www.thwboard.de)

Anpassungen des Forums
© by Flo-Soft (www.flo-soft.de)

Sie sind Besucher: