Bitmap in der Dialogbox auswählen, anzeigen und wieder speichern
-
Hi,
ich hoffe mir kann jemand helfen. Also mein Problem:
Ich will aus der "öffnen" Dialogbox eine .bmp Fileöffnen. Soweit so gut...
Er zeigt mir auch die Bitmap an. Aber sobald er das Fenster neu zeichnen will habe ich ein Problem. Entweder er öffnet dann bei jedem Neuzeichnen wieder die Dialogbox oder aber er zeichnet gar nicht neu.Ich möchte aber einfach das nach dem Öffnen der Bitmap, diese permanent angezeigt wird. Aber leider finde ich den Fehler nicht.Hier erstmal der Quellcode:
#include <stdio.h> #include <windows.h> #include <commdlg.h> #include "resource.h" LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); #define FILTER "Bitmap (*.bmp)\0*.bmp\0\0" static OPENFILENAME ofn = {0}; LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { HWND hwnd; MSG msg; WNDCLASSEX wndclassex = {0}; wndclassex.cbSize = sizeof(WNDCLASSEX); static char szAppName[]= "Menü Erstellung"; wndclassex.style = CS_HREDRAW | CS_VREDRAW; wndclassex.lpfnWndProc = WndProc; wndclassex.cbClsExtra = 0; wndclassex.cbWndExtra = 0; wndclassex.hInstance = hInstance; wndclassex.hIcon = LoadIcon (NULL, IDI_APPLICATION); wndclassex.hCursor = LoadCursor (NULL, IDC_ARROW); wndclassex.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); wndclassex.lpszMenuName = "MENU"; wndclassex.lpszClassName = szAppName; wndclassex.hIconSm = wndclassex.hIcon; RegisterClassEx(&wndclassex); hwnd = CreateWindowEx (WS_EX_CLIENTEDGE, szAppName, "Graphische Datenverarbeitung 2", WS_OVERLAPPEDWINDOW, 0, 0, 1200, 768, NULL, NULL, hInstance, NULL); ShowWindow (hwnd, iCmdShow); UpdateWindow (hwnd); while (GetMessage (&msg, NULL, 0, 0)==TRUE) { TranslateMessage (&msg); DispatchMessage (&msg); } return msg.wParam; } LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static int zustand=0, zustand2=0; char DateiName[_MAX_PATH+1] = ""; static HBITMAP hBitMap; static BITMAP bitmap ; HDC hdc, hdcMem; PAINTSTRUCT ps; switch (message) { case WM_CREATE: return 0; case WM_COMMAND: switch(LOWORD(wParam)) { case IDM_APP_EXIT: MessageBox(NULL, "Copyright 2004 by Christian Hofferer", "Auf Wiedersehen", MB_OK); SendMessage(hwnd, WM_CLOSE, 0, 0); return 0; case IDM_APP_SPEICHERN: zustand = 2; InvalidateRect(hwnd,NULL,TRUE); return 0; case IDM_APP_OPEN: zustand = 1; InvalidateRect(hwnd,NULL,TRUE); return 0; case IDM_APP_ABOUT: MessageBox(NULL, "Christian Hofferer\n658733", "GDV2-Praktikum", MB_OK); return 0; } return 0; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; if (zustand ==1 && zustand2 ==0) { ofn.lStructSize = sizeof (OPENFILENAME) ; ofn.hwndOwner = NULL; ofn.nMaxFile = _MAX_PATH; ofn.lpstrFile = DateiName; ofn.lpstrDefExt = "bmp"; ofn.lpstrFilter = FILTER; if (GetOpenFileName(&ofn)) { switch (ofn.nFilterIndex) { case 1: break; } } } if (zustand ==1) { hBitMap = (HBITMAP)LoadImage(0, DateiName ,IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); GetObject (hBitMap, sizeof (BITMAP), &bitmap); hdcMem = CreateCompatibleDC (hdc) ; SelectObject (hdcMem, hBitMap) ; BitBlt (hdc, 50, 50, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY) ; DeleteDC (hdcMem) ; MessageBox(NULL, "Christian Hofferer\n658733", "GDV2-Praktikum", MB_OK); zustand2 =1; } if (zustand ==2) { ofn.lStructSize = sizeof (OPENFILENAME) ; ofn.hwndOwner = NULL; ofn.nMaxFile = _MAX_PATH; ofn.lpstrFile = DateiName; ofn.lpstrDefExt = "bmp"; ofn.lpstrFilter = FILTER; if (GetSaveFileName(&ofn)) { switch (ofn.nFilterIndex) { case 1: zustand =0; break; } } EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: PostQuitMessage (0); return (0); } } return DefWindowProc (hwnd, message, wParam, lParam); }Dann wäre ich noch dankbar für ein paar Hinweise wo ich etwas zu den Themen Bitmap invertieren oder Bitmap als Graustufenbild ausgeben finden könnte und wie ich dies dann speichere.
Vielen Dank schonmal für eure Hilfe, ich dreh nämlich langsam aber sicher durch.
Mfg Hoffyy
-
Hoffyyy schrieb:
Hi,
ich hoffe mir kann jemand helfen. Also mein Problem:
Ich will aus der "öffnen" Dialogbox eine .bmp Fileöffnen. Soweit so gut...
Er zeigt mir auch die Bitmap an. Aber sobald er das Fenster neu zeichnen will habe ich ein Problem. Entweder er öffnet dann bei jedem Neuzeichnen wieder die Dialogbox oder aber er zeichnet gar nicht neu.Ich möchte aber einfach das nach dem Öffnen der Bitmap, diese permanent angezeigt wird. Aber leider finde ich den Fehler nicht.Das Problem liegt offensichtlich bei den Zustandsvariablen. Wenn "zustand" '1' ist, wird nicht dafür gesorgt, dass es einen anderen Wert hat. Somit würde nämlich der if-Block, der "zustand" auf den Wert '1' abprüft, nicht mehr ausgeführt werden. Das erinnert mich an einen User, der erst vor Kurzem ein ähnliches Problem hatte
