(Dos) Drawing a bitmap?

This is a discussion on (Dos) Drawing a bitmap? within the C++ Programming forums, part of the General Programming Boards category; Sorry if I'm a dumb noobie, but I have been trying to draw a bitmap onto a dos promt. I ...

  1. #1
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379

    (Dos) Drawing a bitmap?

    Sorry if I'm a dumb noobie, but I have been trying to draw a bitmap onto a dos promt. I know theres some open source code, but I got lost as to what was happening to the bitmap -,-.
    Also, do I need the bitmap as an image, or can I use hex representation to draw the bitmap?

    Edit - So I dont make two posts, how do I make a wait(ms)? (miliseconds).
    Last edited by Blackroot; 12-29-2005 at 02:00 AM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    Now, do you really mean DOS, or that small rectangle in the middle of your XP desktop with a c:\> prompt in it?

    Better yet, actually say which Operating system and compiler you're using.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    So I dont make two posts, how do I make a wait(ms)? (miliseconds).
    use win32 api Sleep(int milliseconds) function.
    Code:
    #include <windows.h>
    int main()
    {
       Sleep(1000); // wait 1 second
    
      return 0;
    }

  4. #4
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    I mean the little dos rectangle in windows.

    I'm using Windows XP, borland dev++ compiler.
    -Thank you dragon ^.^.

    Mmm... It seems every time I ask a question, another comes to mind. Ah well, I might be a pest for asking but; I know its possible, but whats the library/function to use to get a key input (For windows). -Not cin, but something that you dont need to hit enter to have it recorded.

    Lol thanks again ^,^.
    Last edited by Blackroot; 12-29-2005 at 04:39 AM.

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    There is no standard way to get keyboard input without hitting <Enter> key. But some compilers support some functions in conio.h. check your compiler to see if it supports kbhit() which tests if there is a key in the keyboard input buffer.

    I don't think there is any way to draw a bitmap in a command prompt window and console program. You have to use GUI window for that.

  6. #6
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    I don't think there is any way to draw a bitmap in a command prompt window and console program. You have to use GUI window for that.

    http://www.daniweb.com/code/snippet174.html

    Code:
    
    #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
                    BCX_Bitmap("C:\\Windows\\greenstone.bmp",hConWnd,123,1,1,0,0);
    
                    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)
    {
            HWND A;
            HBITMAP hBitmap;
    
            // set default style
            if (!Style) Style = WS_CLIPSIBLINGS|WS_CHILD|WS_VISIBLE|SS_BITMAP|WS_TABSTOP;
    
            // form for the image
            A = CreateWindowEx(Exstyle,"static",NULL,Style,X,Y,0,0,hWnd,(HMENU)id,GetModuleHandle(0),NULL);
    
            // Text contains filename
            hBitmap=(HBITMAP)LoadImage(0,Text,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
    
            // auto-adjust width and height
            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;
    }
    
    
    // tricking Windows just a little ...
    HWND GetConsoleWndHandle(void)
    {
            HWND hConWnd;
            OSVERSIONINFO os;
            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;
    }
    Possibly??? Although rather hackish.

  7. #7
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    Wow O_O. I thought it was a whole lot simpler -,-.

    Tyvm, I'll go poking around your code to see how it ticks ^,^.

    Thanks again.

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Pausing FAQ link: http://faq.cprogramming.com/cgi-bin/...&id=1043284392
    whats the library/function to use to get a key input (For windows). -Not cin, but something that you dont need to hit enter to have it recorded.
    See the FAQ: http://faq.cprogramming.com/cgi-bin/...&id=1043284392
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Blackroot
    Wow O_O. I thought it was a whole lot simpler -,-.

    Tyvm, I'll go poking around your code to see how it ticks ^,^.

    Thanks again.

    Actually, my example was merely just to show it was possible to display a bitmap in the console. However, I'd never really recommend actually using it.

    I'd go with Ancient Dragon's suggestion of using a GUI program, or as it is more popularly known as, 'Windows Programming.' There's a forum for it on this website. But even that's considered difficult and has a steep learning curve.

    Also look into using secondary libraries such as Allegro or SDL.

    Or quite possibly, you probably don't wanna touch any GUI stuff until you've mastered the basics of regular command line programming.

    Good Luck,

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing circle into a bitmap file
    By brokensail in forum C++ Programming
    Replies: 2
    Last Post: 10-30-2006, 12:26 AM
  2. Drawing a bitmap on a dialog box?
    By JeremyCAFE in forum Windows Programming
    Replies: 0
    Last Post: 04-12-2006, 09:55 PM
  3. OpenGL -- Bitmaps
    By HQSneaker in forum Game Programming
    Replies: 14
    Last Post: 09-06-2004, 04:04 PM
  4. Drawing more than 1 bitmap
    By bluehead in forum Windows Programming
    Replies: 2
    Last Post: 12-07-2002, 08:51 AM
  5. drawing a bitmap in new position
    By Crossbow in forum Windows Programming
    Replies: 8
    Last Post: 12-06-2001, 02:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21