computing
  • 0

C++, drawing bitmap onto dialog

  • 0

I am making a Win32 application using MS visual C++ 6. My problem is that i can’t draw a bitmap resource on to a dialog. Here is a section of what my source code looks like:

#include “stdafx.h”
#include “resource.h”

HINSTANCE hInstance;

LRESULT CALLBACK DlgProc(HWND , UINT , WPARAM , LPARAM);
LRESULT CALLBACK MainDlgProc(HWND , UINT , WPARAM , LPARAM);
LRESULT CALLBACK AbtDlgProc(HWND , UINT , WPARAM , LPARAM);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
DialogBox(NULL, MAKEINTRESOURCE(IDD_PwChk), NULL, (DLGPROC)DlgProc);
return 0;
}

LRESULT CALLBACK DlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
char szPassword[11]={0};
switch(msg)
{
case WM_PAINT:
{
HBITMAP hBitmap = (HBITMAP)LoadImage(hInstance, “IDB_pwTitle”, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE);
HDC hdc = GetDC(hWnd);
HDC image_dc = CreateCompatibleDC(hdc);
HBITMAP old_hbitmap = (HBITMAP)SelectObject(image_dc, hBitmap);
BitBlt(hdc ,10 , 10, 10, 10, image_dc, 0, 0, SRCCOPY);
break;
}

Can any1 tell me when i’m doing wrong?
I also use dialog resources and disply them using the DialogBox function, the reson why i don’t draw the image onto the dialog resource in the resource editor is because when i do this the images are not displayed in WindowsXP

Does any1 have an answer?

Share

1 Answer

  1. Have you left out part of the code?

    One minor thing, I believe that the break; statement should be outside of the brackets on your case WM_PAINT switch. That’s how it’s done with borland anyway.

    Does DialogBox() return a handle in Visual C++?

    Also there is no message loop at all in your code. The DlgProc callback procedure is probably never being sent any messages at all unless Visual C++ does way more housekeeping for the user that Borland C++ builder does.

    I also noticed that you have not created an application window, or retreived a handle for it. Does the code you posted compile or run? If so, what do you get when you run the executable?

    • 0
Leave an answer

Leave an answer

Browse