Hi, I use the code below for an bitmap image and it works great. The only problem is after I use system("cls") or when the scroller goes down it cuts the image. I use compiler Dev-C++ and my OS is Windows XP and I have also vista.

I was thinking redrawing the image would solve the problem but how can I do that? I have tried pasting the command inside main 2 or 3 times but it wont work. Any solution to this?

// put a bitmap image on a Windows Console display
// BCX basic original by Joe Caverly and Kevin Diggins
// BCX generated C code modified for PellesC/Dev-C++
#include <stdio.h>
#include <string.h>
#include <windows.h>    // Win32Api Header File 
static HWND  hConWnd;

HWND BCX_Bitmap(char*,HWND=0,int=0,int=0,int=0,int=0,int=0,int=0,int=0,int=0);
HWND GetConsoleWndHandle(void);

int main()
  hConWnd = GetConsoleWndHandle();
  if (hConWnd)
    // select a bitmap file you have or use one of the files in the Windows folder
    // filename, handle, ID, ulcX, ulcY, width, height   0,0 auto-adjusts
    getchar();  // wait
  return 0;

// draw the bitmap
HWND BCX_Bitmap(char* Text,HWND hWnd,int id,int X,int Y,int W,int H,int Res,int Style,int Exstyle)
  HBITMAP hBitmap;
  // set default style
  // form for the image
  A = CreateWindowEx(Exstyle,"static",NULL,Style,X,Y,0,0,hWnd,(HMENU)id,GetModuleHandle(0),NULL);
  // Text contains filename

  // auto-adjust width and height
  if (W || H) hBitmap = (HBITMAP)CopyImage(hBitmap,IMAGE_BITMAP,W,H,LR_COPYRETURNORG);
  if (W || H) SetWindowPos(A,HWND_TOP,X,Y,W,H,SWP_DRAWFRAME);
  return A;

// tricking Windows just a little ...
HWND GetConsoleWndHandle(void)
  HWND hConWnd;
  char szTempTitle[64], szClassName[128], szOriginalTitle[1024];

  os.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
  GetVersionEx( &os );
  // may not work on WIN9x
  if ( os.dwPlatformId == VER_PLATFORM_WIN32s ) return 0;

  GetConsoleTitle( szOriginalTitle, sizeof ( szOriginalTitle ) );
  sprintf( szTempTitle,"%u - %u", GetTickCount(), GetCurrentProcessId() );
  SetConsoleTitle( szTempTitle );
  Sleep( 40 );
  // handle for NT and XP
  hConWnd = FindWindow( NULL, szTempTitle );
  SetConsoleTitle( szOriginalTitle );

  // may not work on WIN9x
  if ( os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS )
    hConWnd = GetWindow( hConWnd, GW_CHILD );
    if ( hConWnd == NULL ) return 0;
    GetClassName( hConWnd, szClassName, sizeof ( szClassName ) );
    // while ( _stricmp( szClassName, "ttyGrab" ) != 0 )
    while ( strcmp( szClassName, "ttyGrab" ) != 0 )
      hConWnd = GetNextWindow( hConWnd, GW_HWNDNEXT );
      if ( hConWnd == NULL ) return 0;
      GetClassName( hConWnd, szClassName, sizeof( szClassName ) );
  return hConWnd;
9 Years
Discussion Span
Last Post by marco93

It's a wrong and newbie code, which doesn't work at all of course, as it's a very bad idea to create a static control as child of console window.
And SetConsoleTitle() is awful to get the console window, instead of the right api.

You must use windows subsystem to display bitmaps.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.