Loading bmp images in console

Is there any way to adapt this code so i can load images into my console video game and still be able to continue to play through it and without this interfering with the text in the game window? This is some code i snagged somewhere else and made my own image to load and it works long as the bmp is 16 colors.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <conio.h>
#include <iostream>
using namespace std;

HWND CopyBitmap(char*,HWND=0,int=0,int=0,int=0,int=0,int=0,int=0,int=0,int=0);
HWND ConsoleWindow(void);
int _tmain(int argc, _TCHAR* argv[])
{
  if (HWND myWin = ConsoleWindow())
  {
   CopyBitmap("C:\\sample.bmp",myWin,123,1,1,0,0);
    _getch();
  }
 return 0;
}

HWND CopyBitmap(char* Text,HWND hWnd,int id,int X,int Y,int W,int H,int Res,int Style,int Exstyle)
{
  HWND A;
  HBITMAP hBitmap;

  if (!Style) Style = WS_CLIPSIBLINGS|WS_CHILD|WS_VISIBLE|SS_BITMAP|WS_TABSTOP;

  A = CreateWindowEx(Exstyle,"static",NULL,Style,X,Y,0,0,hWnd,(HMENU)id,GetModuleHandle(0),NULL);

  hBitmap=(HBITMAP)LoadImage(0,Text,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);

  if (W || H) hBitmap = (HBITMAP)CopyImage(hBitmap,IMAGE_BITMAP,W,H,LR_COPYRETURNORG);
  SendMessage(A,(UINT)STM_SETIMAGE,(WPARAM)IMAGE_BITMAP,(LPARAM)hBitmap);
  if (W || H) SetWindowPos(A,HWND_TOP,X,Y,W,H,SWP_DRAWFRAME);
  return A;
}

HWND ConsoleWindow(void)
{
  HWND myWin;
  OSVERSIONINFO os;
  char szTempTitle[64], szClassName[128], szOriginalTitle[1024];

  os.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
  GetVersionEx( &os );
  if ( os.dwPlatformId == VER_PLATFORM_WIN32s ) return 0;

  GetConsoleTitle( szOriginalTitle, sizeof ( szOriginalTitle ) );
  sprintf( szTempTitle,"%u - %u", GetTickCount(), GetCurrentProcessId() );
  SetConsoleTitle( szTempTitle );
  Sleep( 40 );
  myWin = FindWindow( NULL, szTempTitle );
  SetConsoleTitle( szOriginalTitle );

  if ( os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS )
  {
    myWin = GetWindow( myWin, GW_CHILD );
    if ( myWin == NULL ) return 0;
    GetClassName( myWin, szClassName, sizeof ( szClassName ) );
    while ( strcmp( szClassName, "ttyGrab" ) != 0 )
    {
      myWin = GetNextWindow( myWin, GW_HWNDNEXT );
      if ( myWin == NULL ) return 0;
      GetClassName( myWin, szClassName, sizeof( szClassName ) );
    }
  }
  return myWin;
}
*groans*

Why are you using the console for this? Seriously. The console isn't designed for this kind of thing. You're making this way harder on yourself than it has to be, and you're learning all sorts of really outdated and bad practices that have no modern application. The hoops you're making yourself jump through are ridiculous.

It's like you're trying to turn a screw with your car keys. Sure you can do it... but why not just use the screwdriver that's sitting on the shelf?

http://www.sfml-dev.org/

EDIT:

Look at all that mess you're making yourself do... checking the OS version? Searching the OS for your own Window?

For contrast -- if you left the console and used an actual window, this is how easy it could be:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <SMFL/Graphics.hpp>

int main()
{
  sf::RenderWindow wnd( sf::VideoMode(640,480), "My Awesome Game" );  // the size/title of your window

  sf::Image img("myimage.png"); // load the image file

  sf::Sprite spr(    // create a "sprite" (something that is displayed on screen)
    img,   // using the loaded image
    sf::Vector2f( 50, 100 )  // the x,y pixel coords that you want the image to be drawn
   );


  //====

  wnd.Clear();  // clear the screen
  wnd.Draw(spr);  // draw your sprite
  wnd.Display();  // make everything visible.


  //====
  sf::Sleep(2);  // wait a little bit before exiting
}
Last edited on
I <3 SFML.
this sfml is it possible to convert the current code over to this? Do i have to relearn new stuff to do it, my plan was to make a game using dev console then start learning visual anyways i am trying to learn the outdated stuff and build off of that knowledge


is this the version i want dev for c++ 2008 since thats the IDE im using.

http://downloads.sourceforge.net/sfml/SFML-1.6-dev-windows-vc2008.zip
Last edited on
this sfml is it possible to convert the current code over to this?


Odds are you'll have to rewrite a large portion of it. Effectively it might be like starting over.

But this is why I've been saying this in just about every thread you've posted... I knew it would come to this. I wanted to stop you before it got to this point.

Do i have to relearn new stuff to do it


Yes. A good portion of the things you've learned are useless in game programming. Console dev and game dev are two entirely different worlds.

The language basics though will all be the same, so it won't be like you're starting from square 1 all over again. You'll have a better understanding of the basics than before.

my plan was to make a game using dev console then start learning visual


Yes, but this is a bad way to go because most things you learn in the console have zero application in game dev.

i am trying to learn the outdated stuff and build off of that knowledge


Isn't that a wasted step? Why not just start with more recent techniques right away? (especially since they're so much easier!)

is this the version i want dev for c++ 2008 since thats the IDE im using.


Looks like it.

Be sure to follow the online guide for building and linking to SFML. Setting SFML up the first time is the hardest part... but you only have to do it once, then it's good to go forever.
Disch what do you think of FLTK?
I shied (shy'd?) away from it because I thought the GUI was ugly.

I prefer native controls, so I'm not a fan of hand-drawn controls like Java/FLTK. That's probably what attracted me to wxWidgets.

wxWidgets is certainly a lot heavier/more bloated than FLTK though. So pick your poison.
Well i got it all setup and a new project Version 2.0 with empty project for now i moved over the includes until i can figure out which ones i need and don't need.


Now my question is how do i load a starting graphics window where i will load my text/grahpics/music etc from. I want to start out with a large dos style window "full GUI" that can render video or graphics etc... to get started.


I want my window to stay open for use, how do i maintain an open window i dont want every command to pop a window up do stuff and close.
Last edited on
Well an empty project compiles fine but as soon as i use sample code:

>KingdomOfMythos Version 2.0.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall sf::RenderWindow::~RenderWindow(void)" (??1RenderWindow@sf@@UAE@XZ) referenced in function _wmain
1>KingdomOfMythos Version 2.0.obj : error LNK2019: unresolved external symbol "public: void __thiscall sf::Window::Display(void)" (?Display@Window@sf@@QAEXXZ) referenced in function _wmain
1>KingdomOfMythos Version 2.0.obj : error LNK2019: unresolved external symbol "public: void __thiscall sf::RenderTarget::Clear(class sf::Color const &)" (?Clear@RenderTarget@sf@@QAEXABVColor@2@@Z) referenced in function _wmain
1>KingdomOfMythos Version 2.0.obj : error LNK2019: unresolved external symbol "public: __thiscall sf::Color::Color(unsigned char,unsigned char,unsigned char,unsigned char)" (??0Color@sf@@QAE@EEEE@Z) referenced in function _wmain
1>KingdomOfMythos Version 2.0.obj : error LNK2019: unresolved external symbol "public: void __thiscall sf::Window::Close(void)" (?Close@Window@sf@@QAEXXZ) referenced in function _wmain
1>KingdomOfMythos Version 2.0.obj : error LNK2019: unresolved external symbol "public: bool __thiscall sf::Window::GetEvent(class sf::Event &)" (?GetEvent@Window@sf@@QAE_NAAVEvent@2@@Z) referenced in function _wmain
1>KingdomOfMythos Version 2.0.obj : error LNK2019: unresolved external symbol "public: bool __thiscall sf::Window::IsOpened(void)const " (?IsOpened@Window@sf@@QBE_NXZ) referenced in function _wmain
1>KingdomOfMythos Version 2.0.obj : error LNK2019: unresolved external symbol "public: __thiscall sf::RenderWindow::RenderWindow(class sf::VideoMode,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned long,struct sf::WindowSettings const &)" (??0RenderWindow@sf@@QAE@VVideoMode@1@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@KABUWindowSettings@1@@Z) referenced in function _wmain
1>KingdomOfMythos Version 2.0.obj : error LNK2019: unresolved external symbol "public: __thiscall sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (??0VideoMode@sf@@QAE@III@Z) referenced in function _wmain
1>C:\Users\Snaef98\Documents\Visual Studio 2008\Projects\KingdomOfMythos Version 2.0\Debug\KingdomOfMythos Version 2.0.exe : fatal error LNK1120: 9 unresolved externals
You need to link to the lib. Follow the tutorial here: http://www.sfml-dev.org/tutorials/1.6/start-vc.php
Last edited on
I did all the directions required and still had problems for the time being im sticking with my project on console and its coming out nicely, if i cant load images oh well thats gonna be something as a last thing to work on if i can create a work around... otherwise im ok with this being a purely text game. - gonna close this one since i can get tech support right from their site lol
That's unfortunate.

Getting SFML set up is a little difficult, yes, but it's well worth it. You only have to do it once.

Please just stick it out and get it working. It will really benefit you. I'm happy to help if you can explain what kind of trouble you're having.
I agree with Disch - I had quite a bunch of problems setting up SFML, but once I figured it out, getting beyond the console was so much easier. I'm very glad that I managed to work out SFML instead of trying to understand win32.
Topic archived. No new replies allowed.