Computing.Net > Forums > Programming > C++, drawing bitmap onto dialog

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

C++, drawing bitmap onto dialog

Reply to Message Icon

Name: Jeff
Date: November 19, 2003 at 04:54:39 Pacific
OS: WindowsXP
CPU/Ram: 733, 128MB ram
Comment:

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?



Sponsored Link
Ads by Google

Response Number 1
Name: Fozzie
Date: November 19, 2003 at 18:20:10 Pacific
Reply:

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
Reply to Message Icon

Related Posts

See More


Access Help VB 6.0 Write datagrid in ...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: C++, drawing bitmap onto dialog

C++ using Bitmap Images on dialogs www.computing.net/answers/programming/c-using-bitmap-images-on-dialogs/8160.html

AllegroGL help www.computing.net/answers/programming/allegrogl-help/8047.html

public static void methods?? (C#) www.computing.net/answers/programming/public-static-void-methods-c/12429.html