Image Not Showing

Discussion in 'Win32' started by hemanth.balaji, Jun 9, 2005.

  1. hemanth.balaji

    hemanth.balaji New Member

    Joined:
    May 22, 2005
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    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

    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;
    }
    I have also uploaded the project itself :

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

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    If you can format the code a bit more using BB code it will be easier for us to go through the codes

    Below are MFC code but I have commented so that you as Win32 programmer can also understand
    Code:
    	//Create a device context to load the bitmap into
     	CDC dcMem;
     	dcMem.CreateCompatibleDC(pdc);
     
     	//Get the Display area available
     	CRect lRect;
     	GetClientRect(lRect);
     	lRect.NormalizeRect();
     
     	//select the bitmap into compatible device context
     	CBitmap* pOldBitmap = (CBitmap*)dcMem.SelectObject
     	(&m_bmpBitmap);
     	//m_bmpBitmap.SetBitmapDimension(lRect.Width(),lRect.Height());
     
     	//copy & resize the window to the dialog window
     	pdc->StretchBlt(0,0,lRect.Width(),lRect.Height(),&dcMem,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
     
    The above code will not run but just have the concept of displaying the bitmap.

    If you want I can give you the code in which above code is running.

    Thanks
    Shabbir Bhimani
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice