hemanth.balaji 0 Newbie Poster

I have to build a project. For that I am using an

OWNER Drwan Menu. Now i want the small part of the

remaining space to have an image. i.e a small logo

in the top right corner of the application on the

menu bar unused space. Now to dry that I just typed

a code to display an image somewahere in the main

window. But the output is not showing the Bitmap.

Why is that.

What is the probelm with the below code

#include <windows.h>
#include"resource.h"

#define ID_FILE_EXIT 9001
#define ID_STUFF_GO 9002

const char g_szClassName[] = "myWindowClass";
HINSTANCE hInstance;

LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, 

WPARAM wParam, LPARAM lParam)
{
	HDC hDC, MemDCExercising;
    PAINTSTRUCT Ps;
    HBITMAP bmpExercising;
	
	switch(Message)
	{
		case WM_CREATE:
		{
			HMENU hMenu, hSubMenu;

			hMenu = CreateMenu();

			hSubMenu = 

CreatePopupMenu();
			AppendMenu(hSubMenu, 

MF_STRING, ID_FILE_EXIT, "E&xit");
			AppendMenu(hMenu, MF_STRING 

| MF_POPUP, (UINT)hSubMenu, "&File");

			hSubMenu = 

CreatePopupMenu();
			AppendMenu(hSubMenu, 

MF_STRING, ID_STUFF_GO, "&Go");
			AppendMenu(hMenu, MF_STRING 

| MF_POPUP, (UINT)hSubMenu, "&Stuff");

			SetMenu(hwnd, hMenu);

		}
		break;

		case WM_PAINT:
		{
				hDC = 

BeginPaint(hwnd, &Ps);

				// Load the bitmap 

from the resource
				bmpExercising = 

LoadBitmap(hInstance, 

MAKEINTRESOURCE(IDB_EXERCISING));
				// 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, 200, 

200, 200, 200, MemDCExercising, 0, 0, SRCCOPY);

				// Restore the old 

bitmap
				

DeleteDC(MemDCExercising);
				

DeleteObject(bmpExercising);
				EndPaint(hwnd, 

&Ps);
		}
		break;

		case WM_COMMAND:
			switch(LOWORD(wParam))
			{
				case ID_FILE_EXIT:
					

PostMessage(hwnd, WM_CLOSE, 0, 0);
				break;
				case ID_STUFF_GO:
					break;
			}
		break;		

		case WM_CLOSE:
			DestroyWindow(hwnd);
		break;
		case WM_DESTROY:
			PostQuitMessage(0);
		break;
		default:
			return DefWindowProc(hwnd, 

Message, wParam, lParam);
	}
	return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE 

hPrevInstance,
	LPSTR lpCmdLine, int nCmdShow)
{
	WNDCLASSEX wc;
	HWND hwnd;
	MSG Msg;

	wc.cbSize		 = 

sizeof(WNDCLASSEX);
	wc.style		 = 0;
	wc.lpfnWndProc	 = WndProc;
	wc.cbClsExtra	 = 0;
	wc.cbWndExtra	 = 0;
	wc.hInstance	 = hInstance;
	wc.hIcon		 = NULL;
	wc.hCursor		 = LoadCursor(NULL, 

IDC_ARROW);
	wc.hbrBackground = 

(HBRUSH)(COLOR_WINDOW+1);
	wc.lpszMenuName  = NULL;
	wc.lpszClassName = g_szClassName;
	wc.hIconSm		 = NULL;

	RegisterClassEx(&wc);

	hwnd = CreateWindowEx(
		WS_EX_CLIENTEDGE, 	

g_szClassName, 	"A Menu ", 	

WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, CW_USEDEFAULT, 240, 

120, NULL, NULL, hInstance, NULL);

	if(hwnd == NULL)
	{
		MessageBox(NULL, "Window Creation 

Failed!", "Error!",
			MB_ICONEXCLAMATION | 

MB_OK);
		return 0;
	}

	ShowWindow(hwnd, nCmdShow);
	UpdateWindow(hwnd);

	while(GetMessage(&Msg, NULL, 0, 0) > 0)
	{
		TranslateMessage(&Msg);
		DispatchMessage(&Msg);
	}
	return Msg.wParam;
}

<< moderator edit: added code tags: [code][/code] >>

I have also uploaded the project itself :

http://www.geocities.com/kalamirch/menu_two.zip

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.