Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in the name of allah

hi everyone

i makes an array "CWnd" class and i want to do "CreateEx" for everyone, but just the first "CreateEx" works and for second and next will error and doesn't work.
i also want set different "Parent" for each (from hwnd).
like : Parent of 1st CWnd is "Cmd" and 2nd is "Calculator" and ... .
can you help me?
what's wrong?

the code i use in create function is like below:

C++
void Theme::CreateTheme(CRect rect,CString Text, CWnd *parent,unsigned short int W,unsigned short int H){

	CString className = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW | CS_OWNDC, NULL, (HBRUSH)GetStockObject(BLACK_BRUSH), NULL);
	CreateEx(0, _T(className),Text, WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, rect, parent, 0);


	Parent = parent;
	cdc=Parent->GetWindowDC();
	w=W;
	h=H;

}



at finally i want to :

C++
Theme t[5];
t[0].CreateTheme(...);
t[1].CreateTheme(...);
t[2].CreateTheme(...);
...


Actually all the Events like "OnPaint" "OnLButtonDown" and ... work except the"OnTimer".
I need to work with "OnTimer" but just this event doesn't work.
can you tell me where the my wrong is?

thanks an advance

______________________________





i declared and use them like below :

____________________________________________________________
C++
Theme theme1;
theme1.CreateTheme(CRect(-2,-2,-1,-1),_T("Hello"),CWnd::FromHandle(hwndDlg),800,500);


Theme theme2;
theme2.CreateTheme(CRect(-2,-2,-1,-1),_T("Hello"),CWnd::FromHandle(hwndDlg),500,300);

____________________________________________________________

in the object "theme1", all of the events work but in the Object "theme2" the "OnTimer()" event doesn't work , of course others event like "OnLButtonDown" and ... work correctly in "theme2".

and this is the contains of .h :


__________________________________________________________________
C++
class Theme : public CWnd{
private:
	
protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support

public:
	CWnd  *Parent;
	CPoint cursor;
	bool drag;
	CString path,imagepath;
	char DialogMove;//0==top to center - 1==center to top - 2==center to down - 3==down to center
	char code,sb;//code = 0=main page - sb=show button=1=ascedung,-1=desceding;
	short int iimage,bstart,bend,//i = index of images-b = index of buttons
	ib;//ib=index of button for clicking and do code
	short int w, h,D;
	float ani_p, ani_max;
	bool ani,mousec;
	CRect WRect,rdesktop;
	CDC *cdc;
	short int lani;
	HWND hwndani;
	Object *Image;
	CRect *Rect;
	bool *BEnable;//enable of buttons-1 = enable
	unsigned char ButtonCount,ImageCount,SysButtonCount;
	bool Created;

	void GotoPage(unsigned char PageNo,unsigned char BStart,unsigned char BEnd);
	void OnLButtonDown();
	void OnLButtonUp();
	void ClearRect(short i,short j,COLORREF color);
	bool IsIn(CPoint point,CRect rect);
	bool IsInRect(CPoint point,CRect rect,CRect Rectangle);
	void Center2Top();
	void Top2Center();
	void Down2Center();
	void Center2Down();
	bool AddImage(unsigned char Index,CString ImagePath,unsigned short int X,short int Y);
	void AddButton(unsigned char Index,CRect rectangle,bool enable);
	void DrawImages(unsigned char alpha,int IImage);
	Theme(unsigned char imagecount,unsigned char buttoncount,unsigned char sysbuttoncount);
	~Theme(void);
	void CreateTheme(CRect rect,CString Text, CWnd *parent,unsigned short int W,unsigned short int H,UINT nID);
	afx_msg void OnPaint();
	afx_msg void OnTimer(UINT nIDEvent);
	
	DECLARE_MESSAGE_MAP()
};

_________________________

and it's source file is :


-------------------------------------
C++
Theme::Theme(unsigned char imagecount,unsigned char buttoncount,unsigned char sysbuttoncount)
{
//Get Project's Path
TCHAR tc[260];
GetCurrentDirectory(260,tc);
path=tc;
imagepath=path+_T("\\Data\\x85P\\");

drag=lani=mousec=iimage=0;
bstart=bend=-1;
code=ib=-1;sb=1;
Created=0;

ButtonCount=buttoncount;
ImageCount=imagecount;
SysButtonCount=sysbuttoncount;
Image=new Object[ImageCount];
Rect=new CRect[ButtonCount];
BEnable=new bool[ButtonCount];
memset(BEnable,0,ButtonCount);

}

void Theme::CreateTheme(CRect rect,CString Text, CWnd *parent,unsigned short int W,unsigned short int H,UINT nID){
	if(!Created){
		CString className = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW | CS_OWNDC, 0,0,0);
		CreateEx(WS_EX_CLIENTEDGE,className,_T("hi"),WS_VISIBLE | WS_CHILD,rect,parent,0,0);
		Created=1;
	}
	Parent = parent;
	cdc=Parent->GetWindowDC();
	w=W;
	h=H;
	//Get Desktop Rect
	CWnd::GetDesktopWindow()->GetWindowRect(&rdesktop);

	OnPaint();

	
	//Move Cursor
	SetTimer(3,10,0);
}
Posted
Updated 21-Dec-14 23:45pm
v5
Comments
Richard MacCutchan 22-Dec-14 5:24am    
You need to provide more information about your code and show where the errors occur. And indeed what errors they are.

In your second block of code you declare an arry, but never initialise it to anything.
Mahdi Nejadsahebi 22-Dec-14 5:42am    
i update my question.
please see above text of question.
thanks again
Richard MacCutchan 22-Dec-14 7:04am    
The first time through your CreateTheme function you set the variable Created to 1, so you will never create any more windows.

Also, you should never call OnPaint directly, you should use the proper messages and functions provided in Windows.
Mahdi Nejadsahebi 22-Dec-14 7:09am    
about the "OnPaint" yes, but about the "Created" variable
it is inner variable:
class Theme:Public CWnd{
public:
bool Created;
};

and in the another Derived varibale form "Theme" it's different from pre "Created" in First Class, doesn't it?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900