| | |
loading bitmaps
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jun 2009
Posts: 104
Reputation:
Solved Threads: 1
I'm trying to load a bit map but the picture won't come up. It compiles just fine. I'm not sure if this makes a difference either but I am trying to load a bitmap into a dialog box. Here's the code:
The .cpp file:
The resource file:
The resource.h file:
#define IDD_MAIN 100
#define IDB_HANG 101
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
[/code]
The .cpp file:
C++ Syntax (Toggle Plain Text)
#include "windows.h" #include "resource.h" HBITMAP g_hbmHang = NULL; BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { switch(Message) { case WM_CREATE: g_hbmHang = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_HANG)); if(g_hbmHang == NULL) MessageBox(hwnd, "Could not load IDB_HANG!", "Error", MB_OK |MB_ICONEXCLAMATION); break; case WM_CLOSE: DestroyWindow(hwnd); break; case WM_PAINT: { BITMAP bm; PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); HDC hdcMem = CreateCompatibleDC(hdc); HBITMAP hbmOld = (HBITMAP)SelectObject (hdcMem, g_hbmHang); GetObject(g_hbmHang, sizeof(bm), &bm); BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY); SelectObject(hdcMem, hbmOld); DeleteDC(hdcMem); EndPaint(hwnd, &ps); } break; case WM_DESTROY: DeleteObject(g_hbmHang); PostQuitMessage(0); break; default: return FALSE; } return TRUE; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { return DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, DlgProc); }
C++ Syntax (Toggle Plain Text)
//Microsoft Developer Studio generated resource script. // #include "resource.h" #define APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // // Generated from the TEXTINCLUDE 2 resource. // #ifndef __BORLANDC__ #include "winres.h" #endif ///////////////////////////////////////////////////////////////////////////// #undef APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // English (Canada) resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENC) #ifdef _WIN32 LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_CAN #pragma code_page(1252) #endif //_WIN32 #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // TEXTINCLUDE // 1 TEXTINCLUDE DISCARDABLE BEGIN "resource.h\0" END 2 TEXTINCLUDE DISCARDABLE BEGIN "#ifndef __BORLANDC__\r\n" "#include ""winres.h""\r\n" "#endif\r\n" "\0" END 3 TEXTINCLUDE DISCARDABLE BEGIN "\r\n" "\0" END #endif // APSTUDIO_INVOKED IDD_MAIN DIALOG DISCARDABLE 0, 0, 207, 156 STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Controls One" FONT 8, "MS Sans Serif" BEGIN LTEXT "Add",IDC_STATIC,7,10,14,8 END ///////////////////////////////////////////////////////////////////////////// // // Bitmap // IDB_HANG BITMAP DISCARDABLE "hang.bmp" #endif // English (Canada) resources ///////////////////////////////////////////////////////////////////////////// #ifndef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // Generated from the TEXTINCLUDE 3 resource. // ///////////////////////////////////////////////////////////////////////////// #endif // not APSTUDIO_INVOKED
#define IDD_MAIN 100
#define IDB_HANG 101
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
[/code]
Download code from http://winprog.org/tutorial/ and compare it with your code.
Failure is not fatal, but failure to change might be. - John Wooden
•
•
Join Date: Jul 2009
Posts: 8
Reputation:
Solved Threads: 0
Hi goody11,
I'm trying to write a similar program where I can display an image in a dialogbox. I've posted a thread on how to do it....but no response from anyone.
http://www.daniweb.com/forums/thread210539.html
Now i'm trying to use your program, to see if I can extend it for my purpose. I'm getting a compile error "cannot open include file winres.h" Where does this file come from?
Thanks,
Amar
I'm trying to write a similar program where I can display an image in a dialogbox. I've posted a thread on how to do it....but no response from anyone.
http://www.daniweb.com/forums/thread210539.html
Now i'm trying to use your program, to see if I can extend it for my purpose. I'm getting a compile error "cannot open include file winres.h" Where does this file come from?
Thanks,
Amar
![]() |
Similar Threads
- BMP C++ (C++)
- Displaying Text with SDL and OpenGL (C++)
- NEED a source code (simple GAME) (C++)
- Error Loading operating System (Windows NT / 2000 / XP)
- Very slow loading Windows XP Pro...HELP! (Windows NT / 2000 / XP)
- a few win32 bitmap loading question (C++)
- Problems loading websites (Web Browsers)
- Loading Bar Problem (Web Browsers)
- IE 6.0 freeze while loading (Web Browsers)
Other Threads in the C++ Forum
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






