0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
but then hwnd as a parameter will place the main window on top of other window.
0
AhmedHan's Avatar, Join Date: Oct 2005
Go4Expert Member
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();
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Offtopic comment:
AhmedHan why dont you put them as seperate thread in the Codes and Project section.