Navigation
Artikel
Stuff
RSS Feeds
|
Sourcecodes - Bitmap in ein Windows-Fenster ladenSprachenübersicht/C / C++/ C#/Grafik Keywords: Ein Bitmap in ein Fenster laden, WINAPI, C++ Quellcode, Sourcecode Herzlichen Dank an Anton Staruschkin von www.cpp-programming.de/, für die Erlaubnis seine Quellcodes zu veröffentlichen.
Code: #include <windows.h> LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); char szClassName[ ] = "LoadBMP"; int WINAPI WinMain (HINSTANCE hThisInstance,HINSTANCE hPrevInstance, LPSTR lpszArgument,int nFunsterStil) { HWND hwnd; MSG messages; WNDCLASSEX wincl; wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; wincl.style = CS_DBLCLKS; wincl.cbSize = sizeof (WNDCLASSEX); wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; if (!RegisterClassEx (&wincl)) return 0; hwnd = CreateWindowEx (0, szClassName, szClassName, WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT,544,375,HWND_DESKTOP, NULL,hThisInstance,NULL); ShowWindow (hwnd, nFunsterStil); while (GetMessage (&messages, NULL, 0, 0)) { TranslateMessage(&messages); DispatchMessage(&messages); } return messages.wParam; } LRESULT CALLBACK WindowProcedure (HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam) { HDC hdc, hdcMem; static HBITMAP hBitMap; static BITMAP bitmap ; PAINTSTRUCT ps ; switch (message) { case WM_CREATE: hBitMap = (HBITMAP)LoadImage(0,"bitmap.bmp",IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE|LR_LOADFROMFILE|LR_CREATEDIBSECTION); if(hBitMap==NULL) { MessageBox(hwnd,"Bild konnte nicht geladen werden","Error",0); return -1; } GetObject (hBitMap, sizeof (BITMAP), &bitmap) ; return 0; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; hdcMem = CreateCompatibleDC (hdc) ; SelectObject (hdcMem, hBitMap) ; BitBlt (hdc, 0, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY) ; DeleteDC (hdcMem) ; EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: DeleteObject (hBitMap) ; PostQuitMessage (0); break; default: return DefWindowProc (hwnd, message, wParam, lParam); } return 0; } Gibt es noch irgendwelche Fragen, oder wollen Sie über den Artikel diskutieren? Sprachenübersicht/C / C++/ C#/Grafik/Bitmap in ein Windows-Fenster laden |