loading images to a picture box

This is a discussion on loading images to a picture box within the C++ Programming forums, part of the General Programming Boards category; i was trying to load a bmp image to a picture box control, using the windows api, but i couldn't ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    53

    Question loading images to a picture box

    i was trying to load a bmp image to a picture box control, using the windows api, but i couldn't find anything on how to do that. Could someone explain it to me? I was also wondering if i could load jpeg and png images, too.

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,635
    Is there a reason you are using Win32 API instead of a framework such as Qt?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    53
    i appreciate your suggestions, but i'm not asking about Qt or another framework.

    -i have been working on win32 for weeks now and think its what i have been looking for. But if you insist that Qt is a better choice, i'll take a look at it.-

    now do you have an answer for my first question?

  4. #4
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Googling you can end up here
    Don't know if there is explicitly a "Picture Box" in Win 32, but you can use any kind of window

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    53
    thanks for your reply. do you know a way to load jpeg images too?

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,635
    Quote Originally Posted by new_in_c++ View Post
    i appreciate your suggestions, but i'm not asking about Qt or another framework.

    -i have been working on win32 for weeks now and think its what i have been looking for. But if you insist that Qt is a better choice, i'll take a look at it.-

    now do you have an answer for my first question?
    I was wondering why you were using Win32. I wasn't suggesting you to switch. That's none of my business.
    It is merely the case that many people tend to use the wrong tool simply because they haven't been taught any better.
    As to your question, no: I have no idea. And the reason is because I don't tend to use Win32, because it's a pain in the ass. There are far better gui alternatives out there, which are C++ to boot, and not pure C.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,425

    Angry win pain

    if you are insane and like programming which is akin to dentistry, continue with the win api, if you like fast portable, easy to implement, native c++ coding, use fltk
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  8. #8
    Registered User
    Join Date
    Mar 2011
    Posts
    53
    why does everyone think win32 is pain? isn't it flexible enough to allow doing anything the windows OS allows? or is there another reason? and what does "being portable" mean?

    and thanks C_ntua, you seem to be the only one who has answered my question

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,635
    Because it takes a lot of code to do simple things and it isn't trivial.
    Of course the Win32 API allows you to do all the OS allows, because that's the thing--it is the complete functionality the OS allows you to use. But it isn't easy.
    Portable simply means it allows the code to work on multiple platforms. Win32 API obviously only works on Windows.
    Qt, for example, works on Windows, Mac, Linux, Symbian, Maemo. And it's simpler to use.

    Win32 is more flexible, but flexibility comes at a price of more complexity. There is a line you have to draw between flexible and ease to use. I would choose Qt or any other framework over Win32 at any time because 1) the api is C, which pretty much means that it's very inflexible and difficult to use, and 2) frameworks are far easier than the win32 api.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Registered User
    Join Date
    Mar 2011
    Posts
    53
    and can i use opengl and directx with frameworks?

  11. #11
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,635
    It would be doubtful, though there may be solutions for OpenGL with Qt.
    However, you must understand that if you're writing games, you don't need a Gui framework; you just need a window and manipulating effects via DirectX or OpenGL.
    If you're after animations and such using hard acceleration, it is possible using existing methods and such within frameworks. There is no need for DirectX/OpenGL there.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Registered User
    Join Date
    Mar 2011
    Posts
    53
    thanks for the explanation.

    but i'm still waiting for someone who knows win32 and is able to answer the main question

  13. #13
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,425

    wrong forum?

    so perhaps you would have been better posting in the windows programming section. For what its worth FLTK has full openGL support
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  14. #14
    Registered User
    Join Date
    Mar 2011
    Posts
    3
    Quote Originally Posted by new_in_c++ View Post
    i was trying to load a bmp image to a picture box control, using the windows api, but i couldn't find anything on how to do that. Could someone explain it to me? I was also wondering if i could load jpeg and png images, too.
    Forger has most of the information on his guide, theForger's Win32 API Tutorial

    I kinda went the resource/macro route which i kinda regret cause there's EXTREMELY little documentation on this and different compilers allow different tricks and blah, but the good part is that you can easily construct your resource files using programs such like ResEdit (or if you have VisualStudio use whatever it uses), anyhow here's some code to manage images and controls though resource/.rc file,

    slimcore.c (where you catch window events and draw/call/display window)
    Code:
    /*----------------------------------------------------------*\
        Slim TestCore v0.8 (just to get things rollin')
        LastUpd: 2011-03-11
       CFGnotes: Link "comctl32" and include resource file.
    
        Credits: Julien Audo (.cpp & ResEdit)
        URL/NFO: http://www.codeproject.com/KB/cpp/resedit.aspx
                 http://www.resedit.net
    \*----------------------------------------------------------*/
    
    #include <windows.h>
    #include <commctrl.h>
    
    // Ah damnit! I was wacking it around and accidently hit the top so it just exploded all over me!
    BOOL CALLBACK AppDlgProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
    {
       switch(uMsg)
       {
          case WM_INITDIALOG:
          {
             SetClassLongPtr(hDlg,GCLP_HICON,(long)LoadIcon(0,IDI_APPLICATION));
             return 1;
          }
    
          case WM_COMMAND:
          {
              switch(wParam)
              {
                  case IDCANCEL: EndDialog(hDlg, 0);
              }
          }
       }
       return 0;
    }
    
    // Damn ketchup bottles!
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
    {
       InitCommonControls();
       DialogBoxParam(hInstance,(LPCTSTR)50,0,AppDlgProc,0);
       return 0;
    }
    simpleresource.rc (where you construct the visual parts)
    Code:
    // A simple Resource file
    #include <windows.h>
    
    #ifndef IDC_STATIC
      #define IDC_STATIC (-1)
    #endif
    
    LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
    
    // Bitmap
    70 BITMAP ".//location//of//your//bitmap.bmp"
    
    // Dialog
    50 DIALOG 0, 0, 186, 95 STYLE DS_CENTER | DS_MODALFRAME | WS_POPUP FONT 8, "Ms Shell Dlg"
    { // if the compiler throws syntax-error replace "{" with "BEGIN"
       CONTROL 70, IDC_STATIC, WC_STATIC, SS_BITMAP, 52, 20, 77, 41 // image/control
       PUSHBUTTON "Exit", IDCANCEL, 150, 40, 35, 15                 // A close button, program will also listen to "ESC"
    } // if the compiler throws syntax-error replace "}" with "END"
    Hope you're not too confused, otherwise "theForger's" =)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C code need help loading picture automatically
    By mamashi in forum C Programming
    Replies: 4
    Last Post: 06-27-2010, 05:54 AM
  2. C code need help loading picture automatically
    By mamashi in forum C Programming
    Replies: 1
    Last Post: 06-24-2010, 02:11 PM
  3. How to program a "back" button with MFC
    By 99atlantic in forum Windows Programming
    Replies: 3
    Last Post: 04-26-2005, 08:34 PM
  4. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 07:00 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

Tags for this Thread


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