Create and array of Bitmaps using GDI+

Win32 Programming

    Next

  • 1. Edit box beep
    I have an Edit control which gives an annoying beep everytime I press Enter (I use it for entering keyboard commands). I've looked briefly through the google news archives and they suggest trapping WM_KEYUP=13 and changing that. But in my code that message isn't even returned; and the beep seems to happen as soon as I press the key. Any ideas to get rid of this sound (short of unplugging my speakers)? And why on earth make that noise anyway, is it supposed to be some sort of error? Thanks,
  • 2. How to show message from file?
    I read data from file. But ch type is char. So ch cant use in TextOut. How to solve it? Please help me. Thanx. John Wild case WM_PAINT: hdc=BeginPaint(hwnd,&ps); GetClientRect(hwnd,&rect); Col=Row=0; //Read file infile.open("rdata.txt",ios::in); if(!infile) { cout<<"Error!\n"; return 0; } while((ch=infile.get())!=EOF) { while(ch!='\n') { //cant pass compiler. TextOut(hdc,cxChar*Col,cyChar*Row,TEXT(ch),1); Col++; } Row++; } EndPaint(hwnd,&ps); return 0;
  • 3. No WM_RBUTTONUP / WM_NCRBUTTONUP when custom frame window mini
    "Mark Salsbery [MVP]" wrote: > I'm not sure why you expect a minimized window to receive mouse messages... > > Mark Because all the other apps on the taskbar display a context menu when you right click them, in their minimized state. Mine doesn't. I'm trying to change all that.

Create and array of Bitmaps using GDI+

Postby RVdPbHNvbg » Sun, 12 Jul 2009 08:08:06 GMT

Sorry if this is the wrong area, but I'm not sure where to post this.

I've figured out how to create images (bitmaps) with GDI+, and am very happy 
with the results.  I just need to be able to create an array of said bitmaps 
so I can reference them by an index instead of having to type an entire 
variable name.

An example of the kind of code I'm using now is:

	HDC hdc = GetDC(hWnd);
	Gdiplus::Graphics graphics(hdc);

	Gdiplus::Bitmap bitmap1(L"1.png");
	Gdiplus::Bitmap bitmap2(L"2.png");
	Gdiplus::Bitmap bitmap3(L"3.png");
	Gdiplus::Bitmap bitmap4(L"4.png");
	Gdiplus::Bitmap bitmap5(L"5.png");
	Gdiplus::Bitmap bitmap6(L"6.png");
	Gdiplus::Bitmap bitmap7(L"7.png");
	Gdiplus::Bitmap bitmap8(L"8.png");

	ReleaseDC(hWnd, hdc);

and what I want is something along the lines of:

	HDC hdc = GetDC(hWnd);
	Gdiplus::Graphics graphics(hdc);

	Gdiplus::Bitmap bitmap[8];

	bitmap[0] = (L"1.png");
	bitmap[1] = (L"2.png");
	bitmap[2] = (L"3.png");
	bitmap[3] = (L"4.png");
	bitmap[4] = (L"5.png");
	bitmap[5] = (L"6.png");
	bitmap[6] = (L"7.png");
	bitmap[7] = (L"8.png");

	ReleaseDC(hWnd, hdc);

I know that isn't the right syntax.  That's what I need help with.

I'm assuming there is a way to do this.  Does anyone know how?

Thanks in advance for any assistance you could give me.


RE: Create and array of Bitmaps using GDI+

Postby ZHJqYXNvbmhhcnJpc29u » Wed, 15 Jul 2009 01:12:01 GMT

You want and array of pointers, and to call new to allocate the bitmaps and 
call their constructor:

Gdiplus::Bitmap * bitmap[8];
bitmap[0] = new Gdiplus::Bitmap(L"1.png");
bitmap[1] = new Gdiplus::Bitmap(L"2.png");


some time later, you will want to call:

delete bitmap[0];
delete bitmap[1];
....

-Jason



Return to Win32 Programming

 

Who is online

Users browsing this forum: No registered users and 88 guest