Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

help creating a bitmap tiler

Posted on 2000-05-08
5
305 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

808 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