SMTI Temat założony przez niniejszego użytkownika |
» 2014-11-16 21:10:34 #include <windows.h> #include <time.h> #include <cstdlib>
HWND g_hwnd; HDC hdcOkno; int x, y;
HBITMAP hbmObraz; BITMAP bmInfo; RECT rcKulka; HDC hdcNowy; HDC hdcNew;
LRESULT CALLBACK WndProc( HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam ) { switch( Message ) { case WM_DESTROY: { DeleteObject( hbmObraz ); DeleteDC( hdcNowy ); PostQuitMessage( 0 ); break; } case WM_LBUTTONDOWN: { if( 10 == 10 ) { if( LOWORD( lParam ) >= x && LOWORD( lParam ) <= x + 85 && HIWORD( lParam ) >= y && HIWORD( lParam ) <= y + 150 ) { hdcOkno = GetDC( g_hwnd ); FillRect( hdcOkno, & rcKulka,( HBRUSH )( COLOR_WINDOW + 1 ) ); x = rand() % 1115; y = rand() % 750; SetRect( & rcKulka, x, y, x + 85, y + 150 ); ReleaseDC( g_hwnd, hdcOkno ); hbmObraz =( HBITMAP ) LoadImage( NULL, "plik.BMP", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); hdcOkno = GetDC( hwnd ); hdcNowy = CreateCompatibleDC( hdcOkno ); SelectObject( hdcNowy, hbmObraz ); BitBlt( hdcOkno, x, y, 85, 150, hdcNowy, 0, 0, SRCCOPY ); ReleaseDC( g_hwnd, hdcOkno ); ReleaseDC( g_hwnd, hdcNowy ); } } break; } default: return DefWindowProc( hwnd, Message, wParam, lParam ); } return 0; }
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { WNDCLASSEX wc; HWND hwnd; MSG Msg; memset( & wc, 0, sizeof( wc ) ); wc.cbSize = sizeof( WNDCLASSEX ); wc.lpfnWndProc = WndProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor( NULL, IDC_ARROW ); wc.hbrBackground =( HBRUSH )( COLOR_WINDOW + 1 ); wc.lpszClassName = "WindowClass"; wc.hIcon = LoadIcon( NULL, IDI_APPLICATION ); wc.hIconSm = LoadIcon( NULL, IDI_APPLICATION ); if( !RegisterClassEx( & wc ) ) { MessageBox( NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK ); return 0; } hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, "WindowClass", "Caption", WS_VISIBLE | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1200, 900, NULL, NULL, hInstance, NULL ); if( hwnd == NULL ) { MessageBox( NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK ); return 0; } srand( time( NULL ) ); x = rand() % 1115; y = rand() % 750; g_hwnd = hwnd; hbmObraz =( HBITMAP ) LoadImage( NULL, "plik.BMP", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); hdcOkno = GetDC( hwnd ); hdcNowy = CreateCompatibleDC( hdcOkno ); SelectObject( hdcNowy, hbmObraz ); BitBlt( hdcOkno, x, y, 85, 150, hdcNowy, 0, 0, SRCCOPY ); ReleaseDC( hwnd, hdcOkno ); ReleaseDC( hwnd, hdcNowy ); SetRect( & rcKulka, x, y, x + 85, y + 150 ); MessageBox( NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK ); while( GetMessage( & Msg, NULL, 0, 0 ) > 0 ) { TranslateMessage( & Msg ); DispatchMessage( & Msg ); } return Msg.wParam; } nwm czy to nie za dużo, przepraszam za ewentualny spam czy coś takiego, jestem nowy na forum. (kod bez timera i WM_PAINT ale cała reszta jest) |