Solved

help creating a bitmap tiler

Posted on 2000-05-08
5
302 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
ID: 2791961
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
ID: 2791972
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
ID: 2795719
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
ID: 2797844
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
ID: 2801636
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
object modeling - load and save functions 5 60
how to understand recursion 12 219
Excel/Word Add-in in what language? 5 107
Header Errors LNK2019, LNK1120 - Unresolved Externals 4 96
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

867 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

21 Experts available now in Live!

Get 1:1 Help Now