Solved

help creating a bitmap tiler

Posted on 2000-05-08
5
298 Views
Last Modified: 2008-02-01
 Hello everyone.  What I want to do is this:  create a program which takes a number of bitmaps, each having a name formatted as name0000, name0001, etc, and loads them one by one.  It then takes each of these bitmaps and tiles them into a grid with a 1 pixel border between each.  Then, saving would be a nice option but not necessary (I could just use printscreen).  I don't care if it uses a dialog or SDI or whatever.

  Unfortunately, I have pretty much no experience with HBITMAPS and the like, and I'm not sure how to get started.  I'd appreciate it if someone could get me started on the riight track.

Thanks a lot!
Gabe S.
0
Comment
Question by:GabeSmed
5 Comments
 
LVL 9

Expert Comment

by:ShaunWilde
Comment Utility
okay you can load the bitmaps from file using ::LoadImage()

you can get the size of the bitmap using ::GetObject() to fill in a supplied BITMAP structure

you can BitBlt the bitmap by selecting it into a device context and then BitBlt'ing it onto the screen

There are many examples on the above

Keywords are LoadImage, GetObject, BITMAP and BitBlt

If you need help on any of the steps please ask
0
 
LVL 1

Expert Comment

by:yz
Comment Utility
I think there should be a easy way, at first create a large bitmap, and load it into a memory DC, fill it with the border color, then load these small bitmap file, and paste them into this large bitmap use bitblt at the correctly position.
0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 200 total points
Comment Utility
Next is small programm for display
bitmap to screen. Enumerate all bitmaps in you dir (FindFirstFile/FindNextFile),
make coordinates and use this programm
for each Bitmap for every coordinates :
void DisplayBitmap(HINSTANCE hInst,HDC hdc, char *szBitmapName, int x, int y)
{
  BITMAP bm;
  HDC hdc1 = CreateCompatibleDC(hdc);
  HBITMAP bmp = (HBITMAP)LoadImage(hInst, szBitmapName,IMAGE_BITMAP,
                                                   0,0,LR_LOADFROMFILE);
  GetObject(bmp,sizeof(bm),&bm);//get bitmap data
  SelectObject(hdc1, bmp);     //select
  BitBlt(hdc, x,y,bm.bmWidth,bm.bmHeight,
                 hdc1, 0, 0, SRCCOPY);  //display
  DeleteDC(hdc1); //delete context
  DeleteObject(bmp); //delete object
}

Of course, it is only 1-sr step in you
Apps.

I hope, it helps. Alex
0
 

Author Comment

by:GabeSmed
Comment Utility
That's a great answer, but I have one (two) questions.  How do I supply the HINSTANCE and HDC in the parameters?

Thanks.
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
Comment Utility
That may be begin of you apps:
#define STRICT
#include <windows.h>
#pragma hdrstop
#include <windowsx.h>

LRESULT FAR PASCAL  WndProc( HWND, UINT , WPARAM, LPARAM );
HINSTANCE hInst;
#pragma argsused
int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
          LPSTR lpszCmd, int nCmdShow)
{
   static char szAppName[] = "Bitmap" ;
   HWND        hwnd ;
   MSG         msg ;
   WNDCLASS    wndclass ;
//   HANDLE    hAccel;

   if (!hPrevInstance)
   {
      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
      wndclass.lpfnWndProc   = (WNDPROC)WndProc ;
      wndclass.cbClsExtra    = 0 ;
      wndclass.cbWndExtra    = 0 ;
      wndclass.hInstance     = hInstance ;
      wndclass.hIcon         = LoadIcon( NULL, IDI_APPLICATION );
      wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
      wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
      wndclass.lpszMenuName  = MAKEINTRESOURCE( CHELPAPMENU );
      wndclass.lpszClassName = szAppName ;

      RegisterClass (&wndclass) ;
  }

  hInst = hInstance;//save instance
  hwnd = CreateWindow (szAppName,
    "Windows Help Example",
    WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    NULL,
    NULL,
    hInstance,
    NULL) ;

   ShowWindow (hwnd, nCmdShow) ;
   UpdateWindow (hwnd) ;

   while (GetMessage (&msg, NULL, 0, 0))
   {
       TranslateMessage (&msg) ;
       DispatchMessage (&msg) ;
   }
   return msg.wParam ;
}

LRESULT FAR PASCAL  WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{

   switch (message)
   {
      case WM_PAINT:
      {
        HDC hdc;
        PAINTSTRUCT ps;
        RECT rectClient;

        hdc = BeginPaint( hwnd, &ps );//get dc
       //paint with dc and hInstance
       //for find files use FinFirstFile...
        EndPaint( hwnd, &ps );
      }
      break;

      case CM_EXIT:
           DestroyWindow( hwnd );
           break;
      case WM_DESTROY:
         PostQuitMessage (0) ;
         return 0 ;
   }
   return DefWindowProc (hwnd, message, wParam, lParam) ;
}
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now