1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Bitmap display probelm.

Discussion in 'Win32' started by hemanth.balaji, May 26, 2005.

  1. hemanth.balaji

    hemanth.balaji New Member

    Joined:
    May 22, 2005
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    Hello,
    This is Bob from Bangalore, India. I have a doubt . I have a logo . I wanna display it in the project I

    made. But it is not happening. It worked ina a simple window program. But when I ported the same code in the

    below application which is available in the site it gives me a probelm. Please lemme know what is the probelm.

    The filename is within the zip file namely s2.bmp.

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

    Thanking you,
    Bob
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    Hello Bob

    If you can put the code that is giving you the problem then I think we can help you out. Looking through all the code is a bit of difficult for us to understand the problem area.

    Code:
    s_hBitmap = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_SIEMENS));
    if(s_hBitmap == NULL)
    	MessageBox(hwnd, "Could Not load the logo", "Error", MB_OK | MB_ICONEXCLAMATION);
    
    As it does not show the message box you are clearly loading the bitmap correctly but its just the display or paint that needs to be handled correctly.

    Thanks
    Shabbir Bhimani
     
  3. hemanth.balaji

    hemanth.balaji New Member

    Joined:
    May 22, 2005
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    See dude. When i used the same code in the above program how come that the image is showing. Why is it not showing in the above program. I think its hidden
     
  4. hemanth.balaji

    hemanth.balaji New Member

    Joined:
    May 22, 2005
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    Hi shabbir. It kinda worked when i put

    BitBlt( hdc, 400, 30, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);

    . The image was kinda hidden from the controls . I cud see it roughly as a line. What I want to do is display it on the controls I.E ON THE TABCONTROL OR THE TOOLBAR IN THE RIGHT TOP CORNER
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    What do you mean by its showing in the above program and also hidden in the above program.
     
  6. hemanth.balaji

    hemanth.balaji New Member

    Joined:
    May 22, 2005
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    I am sorry dude. Typing mistake. What i meant is when i made the following changes in the zipped file found in the url above

    BitBlt( hdc, 400, 30, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);

    the image was showing (u could see a light line in the coordinates 400,30) I am sure its because the image is on the window but hidden by toolbar & tab control. Its behind hem. How do i put it on the toolbar or in the right hand top such that its on the menu bar.
     
  7. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    If you want to change the zorder of any control use the SetWindowPos function. It changes the size, position, and Z order of a child, pop-up, or top-level window.
     
  8. hemanth.balaji

    hemanth.balaji New Member

    Joined:
    May 22, 2005
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    case WM_PAINT:
    {
    BITMAP bm; //BITMAP structure defines the type, width, height, color format, and bit values of a bitmap.
    PAINTSTRUCT ps;

    HDC hdc = BeginPaint(hwnd, &ps);
    HDC hdcMem = CreateCompatibleDC(hdc);

    HBITMAP hbmOld = (HBITMAP) SelectObject(hdcMem, s_hBitmap);

    GetObject(s_hBitmap,sizeof(bm), &bm);

    // SetWindowPos(hwnd, HWND_TOPMOST, 400, 30, 50, 20, SWP_SHOWWINDOW);

    BitBlt( hdc, 400, 30, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);



    SelectObject(hdcMem, hbmOld);

    DeleteDC(hdcMem);

    EndPaint(hwnd, &ps);
    }
    break;

    I made a change using SetWindowPos function, but stll something wrong
     
  9. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    SetWindowPos(hwnd, HWND_TOPMOST, 400, 30, 50, 20, SWP_SHOWWINDOW);

    You are using the hwnd as a parameter.It should be handle to the window having the bitmap as far as I can see from here.
     
  10. hemanth.balaji

    hemanth.balaji New Member

    Joined:
    May 22, 2005
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    But the bitmap is external. So no window had the bitmap. I just wanted to place it on the main window and thats why i put the hwnd as the parameter. But it is hidden by tab controls and toolbar. Thats the whole probelm
     
  11. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    but then hwnd as a parameter will place the main window on top of other window.
     
  12. AhmedHan

    AhmedHan New Member

    Joined:
    Oct 11, 2005
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    I prepared some classes for managing windows.
    Code:
    class CCommon
    {
    	public:
    	DWORD	dwExStyle;
    	char	lpClassName[MAX_LOADSTRING];
    	char	lpWindowName[MAX_LOADSTRING];
    	DWORD	dwStyle;
    	int	x;
    	int	y;
    	int	nWidth;
    	int	nHeight;
    	HWND	hWndParent;
    	HMENU	hMenu;
    	HINSTANCE hProgInst;
    	LPVOID	lpParam;
    	HWND	hWnd;
    	
    	HANDLE hImage;
    	CHAR szImageFile[MAX_LOADSTRING];
    	
    	CCommon()
    	{
    		dwExStyle		= 0;
    		StringCbCopy(lpClassName , MAX_LOADSTRING, "ClassName");
    		StringCbCopy(lpWindowName , MAX_LOADSTRING, "Caption");
    		dwStyle			= WS_VISIBLE | WS_CHILD;
    		x			= 5;
    		y			= 5;
    		nWidth			= 100;
    		nHeight			= 100;
    		hWndParent		= HWND_DESKTOP;
    		hMenu			= NULL;
    		lpParam			= NULL;
    	}
    
    	VOID SetInitials(INT x, INT y, INT nWidth, INT nHeight)
    	{
    		this->x = x;
    		this->y = y;
    		this->nWidth = nWidth;
    		this->nHeight = nHeight;
    	}
    	void Create(void)
    	{
    		hWnd = CreateWindowEx(	(DWORD)		dwExStyle,
    					(LPCTSTR)	lpClassName,
    					(LPCTSTR)	lpWindowName,
    					(DWORD)		dwStyle,
    					(int)		x,
    					(int)		y,
    					(int)		nWidth,
    					(int)		nHeight,
    					(HWND)		hWndParent,
    					(HMENU)		hMenu,
    					(HINSTANCE)	hProgInst,
        					(LPVOID)	lpParam);
    		DWORD ErrCode = GetLastError();
    		if (hWnd == NULL)
    		{
    			MessageBox(NULL, "Error creating control.", "Error", MB_OK);
    			DebugTest(ErrCode);
    		}
    	}
    	void Enable(bool State)
    	{
    		EnableWindow(hWnd, State);
    	}
    	char * GetText(unsigned long int MaxChars)
    	{
    		char * Buffer = new char[MaxChars];
    		SendMessage(hWnd, WM_GETTEXT, (WPARAM) MaxChars, (LPARAM) Buffer);
    		return Buffer;
    		delete Buffer;
    	}
    	void SetText(char * Buffer)
    	{
    		if(!SendMessage(hWnd, WM_SETTEXT, (WPARAM) NULL, (LPARAM) Buffer))
    		{
    			DWORD dwError = GetLastError();
    			DebugTest("Error setting text"); DebugTest(dwError);
    		}
    	}
    	void SetImage(void)
    	{
    		hImage = LoadImage(hInstance, szImageFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    		SendMessage(hWnd, STM_SETIMAGE, (WPARAM) IMAGE_BITMAP, (LPARAM) hImage);
    	}
    };
    class CImage : public CCommon
    {
    	public:
    	
    	CImage()
    	{
    		StringCbCopy(lpClassName , MAX_LOADSTRING, "STATIC");
    		dwStyle |= SS_BITMAP;
    	}
    };
    Then I can manipulate any image :
    Code:
    		CImage Image;
    		Image.SetInitials(5, 5, 400, 400);
    		Image.hWndParent = hWnd;			//Handle to the parent window
    		Image.hProgInst = hInstance;
    		StringCbCopy(Image.lpWindowName, 32, "");	//Not necessary
    		Image.Create();
    		
    		StringCbCopy(Image.szImageFile, 128, "Clouds.bmp");
    		Image.SetImage();
     
  13. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    [comment]AhmedHan why dont you put them as seperate thread in the Codes and Project section.[/comment]
     

Share This Page