Bitmap (Windows CE)

Heike711

Grünschnabel
Hallo,
ich schreibe momentan ein Programm bei dem verschieden Elemente visualisiert werden sollen (Linien, Bitmaps, Rechtecke,...), dazu verwende ich Microsoft eMbedded Visual C++.
Jetzt habe ich ein Problem. Ich habe in einem Testprogramm ein Bitmap in die Resource geladen und es dann mit der LoadBitmap-Funktion auch darstellen können. Jedoch habe ich jetzt das Problem, dass das Bitmap nicht dargestellt wird. Habe eine Klasse SIControl erstellt, von der die Klassen erben (SILine, SIBitmap,...).
Die Linien werden gezeichnet und dargestellt nur eben nicht das Bitmap. :confused::confused:

Hier zuerst der Code in dem die Klassen definiert sind:
Code:
// SIControl.cpp: implementation of the SIControl class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <windows.h>
#include "resource.h"
#include <Commctrl.h>
#include "SIControl.h"
#include "SIBitmap.h"


//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

SIControl::SIControl()
{

}

SIControl::~SIControl()
{

}

//////////////////////////////////////////////////////////////////////
// SILine Class
//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

SILine::SILine(int p_Xstart, int p_Ystart, int p_Xend, int p_Yend, COLORREF  p_penColor,
			   int p_penWidth, int p_penDashed, int p_Dashlen, 
                                                   int p_Dashbreak)
{
	Xstart = p_Xstart;
	Ystart = p_Ystart;
	Xend = p_Xend;
	Yend = p_Yend;
	penColor = p_penColor;
	penWidth = p_penWidth;
	penDashed = p_penDashed ;
	Dashlen = p_Dashlen;
	Dashbreak = p_Dashbreak;
}

SILine::~SILine()
{

}

BOOL SILine::Paint(HDC hdc)
{

	HPEN  mypen;
	if(penDashed == 0){
		mypen = CreatePen(PS_SOLID,penWidth,penColor);
	}else{
		mypen = CreatePen(PS_DASH,1,penColor);
	}
	SelectObject(hdc,mypen);

	
	POINT p[2];
	p[0].x=Xstart;
	p[0].y=Ystart;
	p[1].x=Xend;
	p[1].y=Yend;
	
	Polyline(hdc,p,2);
	
	DeleteObject(mypen);
	return	TRUE;
}

//////////////////////////////////////////////////////////////////////
// SIBitmap Class
//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

SIBitmap::SIBitmap(int p_Adress, int p_Align, int p_Autosize, int p_Stretch,
				   int p_BitmapResourceBit0, 
                                                                   int p_BitmapResourceBit1,
                                                                   int p_BitmapFileBit0,
				   int p_BitmapFileBit1, int p_Center, 
                                                                   int p_BitNr, int p_BitmapWidth, 
				   int p_SubsheetEnable, int p_HelpActivate0, 
                                                                   int p_HelpActivate1, 
				   int p_HelpKontext0, int p_HelpKontext1, 
                                                                   int p_Height, int p_Left, 
				   int p_Top, BOOL p_Transparent,
                                                                   int p_Variable)
{
	Adress = p_Adress;
	Align = p_Align;
	Autosize = p_Autosize;
	Stretch = p_Stretch;
	BitmapResourceBit0 = p_BitmapResourceBit0;
	BitmapResourceBit1 = p_BitmapResourceBit1;
	BitmapFileBit0 = p_BitmapFileBit0;
	BitmapFileBit1 = p_BitmapFileBit1;
	Center = p_Center;
	BitNr = p_BitNr;
	BitmapWidth = p_BitmapWidth;
	SubsheetEnable = p_SubsheetEnable;
	HelpActivate0 = p_HelpActivate0;
	HelpActivate1 = p_HelpActivate1;
	HelpKontext0 = p_HelpKontext0;
	HelpKontext1 = p_HelpKontext1;
	Height = p_Height;
	Left = p_Left;
	Top = p_Top;
	Transparent = p_Transparent;
	Variable = p_Variable;
}

SIBitmap::~SIBitmap()
{

}
BOOL SIBitmap::Paint(HDC hdc)
{
	PAINTSTRUCT ps;
	HINSTANCE g_hInst;
	HDC memory = CreateCompatibleDC(hdc);
	HBITMAP bild = LoadBitmap(g_hInst,MAKEINTRESOURCE(IDB_BITMAP1)); 
	SelectObject(memory, bild);
	BitBlt(ps.hdc, 10,10, 50,50, memory, 0, 0, SRCCOPY);
	DeleteObject(bild);
	return TRUE;
}


Hier ist ein weiterer Codeschnipsel, indem die Funktionen in das Fenster eingefügt werden:
Code:
LRESULT CALLBACK WndProc (HWND hwnd, UINT umsg, WPARAM wParam, 
                          LPARAM lParam)
{

  int wmId, wmEvent;


  switch (umsg)
  {
    // Add cases such as WM_CREATE, WM_COMMAND, WM_PAINT if you don't 
    // want to pass these messages along for default processing.

    case WM_CLOSE:
      DestroyWindow (hwnd);
      return 0;

    case WM_DESTROY:
	  CommandBar_Destroy(hwndCB);
      PostQuitMessage (0);
      return 0;

	case WM_CREATE:
			break;
	case WM_COMMAND:
			break;
	case WM_SIZE:
   // Tell the command bar to resize itself to fill the top of the
		break;
	case WM_PAINT:

		PAINTSTRUCT ps;
        HDC hdc;
        COLORREF crTxt, crBk;
		RECT rcClient; 
        hdc = BeginPaint(hwnd, &ps);
		GetClientRect(hwnd,&rcClient); 
		

		SILine* pLine = new SILine(0,130,100,30,RGB(255,0,0),2,false,1,2);
		pLine->Paint(ps.hdc);
		delete pLine;

		pLine = new SILine(10,130,220,130,RGB(255,0,255),20,true,1,2);
		pLine->Paint(ps.hdc);
		delete pLine;


		SIBitmap* pBitmap = new SIBitmap(1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 100,
                                                                                    0, 0, 0, 0, 0, 100, 300, 100, 
                                                                                    true, 0);
		pBitmap->Paint(ps.hdc);
		delete pBitmap;

		
		EndPaint(hwnd, &ps);


        break;
  }
  return DefWindowProc (hwnd, umsg, wParam, lParam);
}

Ich bekomme auch keine Fehlermeldung beim Kompilieren oder Bilden.
Hoffe, dass mir jemand helfen kann.

Mfg und schon einmal vielen Dank im voraus
Heike
 
Hi,
ich habe mich ein paar Tage nicht um das Problem gekümmert und was anderes gemacht und gestern hab ich mich hingesetzt, mir noch mal alles angeschaut und zack sprang mich der Fehler fast an. ;)
Ich habe der DeleteObject( )-Funktion das Falsche übergeben. Der Code sieht jetzt so aus:

Code:
BOOL SIBitmap::Paint(HDC hdc) 
{ 
    PAINTSTRUCT ps; 
    HINSTANCE g_hInst; 
    HDC memory = CreateCompatibleDC(hdc); 
    HBITMAP bild = LoadBitmap(g_hInst,MAKEINTRESOURCE(IDB_BITMAP1)); 
    SelectObject(memory, bild); 
    BitBlt(ps.hdc, 10,10, 50,50, memory, 0, 0, SRCCOPY); 
    DeleteObject(memory);  // vorher stand da DeleteObject(bild);
    return TRUE; 
}


Jetzt funktioniert alles.

Liebe Grüße und einen schönen Tag (trotz des schlechten Wetters)
Heike
 
Zurück