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
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
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
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
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.
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.
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
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.
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
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();
[comment]AhmedHan why dont you put them as seperate thread in the Codes and Project section.[/comment]