-
Bitmaps Not Displaying
Hello All ^^
Well I think I got used to resources, but.. I have a few problems left..
Creating a resource for a bitmap image.. I would go through all the proper procedures for loading the bitmap. The program compiles with no errors, and yet.. The image fails to show up.. I am not sure why this occurs.. I will submit my source code and hopefully someone can aid me..
Thank-You
Farewell~
DC
Code:
#include "stdafx.h"
#include <windows.h>
#include "resource.h"
HINSTANCE hInst;
LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX WndCls;
static char szAppName[] = "BitmapIntro";
MSG Msg;
hInst = hInstance;
WndCls.cbSize = sizeof(WndCls);
WndCls.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
WndCls.lpfnWndProc = WindProcedure;
WndCls.cbClsExtra = 0;
WndCls.cbWndExtra = 0;
WndCls.hInstance = hInst;
WndCls.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndCls.hCursor = LoadCursor(NULL, IDC_ARROW);
WndCls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndCls.lpszMenuName = NULL;
WndCls.lpszClassName = szAppName;
WndCls.hIconSm = LoadIcon(hInstance, IDI_APPLICATION);
RegisterClassEx(&WndCls);
CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,
szAppName,
"Bitmaps Fundamentals",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
while( GetMessage(&Msg, NULL, 0, 0) )
{
TranslateMessage(&Msg);
DispatchMessage( &Msg);
}
return static_cast<int>(Msg.wParam);
}
LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg,
WPARAM wParam, LPARAM lParam)
{
HDC hDC, MemDCExercising;
PAINTSTRUCT Ps;
HBITMAP bmpExercising;
switch(Msg)
{
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
break;
case WM_PAINT:
hDC = BeginPaint(hWnd, &Ps);
// Load the bitmap from the resource
bmpExercising = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_YUNA));
// Create a memory device compatible with the above DC variable
MemDCExercising = CreateCompatibleDC(hDC);
// Select the new bitmap
SelectObject(MemDCExercising, bmpExercising);
// Copy the bits from the memory DC into the current dc
BitBlt(hDC, 10, 10, 450, 400, MemDCExercising, 0, 0, SRCCOPY);
// Restore the old bitmap
DeleteDC(MemDCExercising);
DeleteObject(bmpExercising);
EndPaint(hWnd, &Ps);
break;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
return 0;
}
[/I][/COLOR][/FONT]
-
I copied your code directly in to a temporary project and tested it out. I don't have the bmp that you're trying to use, so I drew up one really quick and compiled it. The image appeared to be drawing fine.
One thing you might want to make sure of though, is that you included the .rc file in to your project. It will still compile fine without it, but if it's not included, the image will not show up. So if you're in visual C++, just right click on the workspace tree thing and click "Add Files to Project". Then select the .rc file that you should have in the project folder and include it. Your image should hopefully then show up (assuming you haven't already done this)
If you're not in visual studio, you should still have a .rc file somewhere, just add it to your project and recompile.
-
[color=royalblue]
^^ THANKS ^^
It worked out great, I owe you one.. I was wondering why it didn't work ^^''
Thanks again ^^
Farewell~
[/font]
-
no problem, glad I could help