Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I created a derived class of CStatic, and I must find id of my CStatic but I don't know how I can do

IMPLEMENT_DYNAMIC(CDerStatic, CStatic)

CDerStatic::CDerStatic()
{
	int n_color;
	RGBTRIPLE rgb;
	double red;
	double green;
	double blue;
	COLORREF Color;
	CBrush Brush;
	CSize csSizeOfText;
	CString cs;

	//GetDlgItem();  //software doesn't compile if I add this row

}


What I have tried:

I tried to use GetDlgItem but it isn't right
Posted
Updated 10-Apr-24 3:19am
v4
Comments
Richard MacCutchan 10-Apr-24 8:57am    
"I tried to use GetDlgIten but it isn't right"
And you think that somehow we can guess what your code is doing and fix it for you?
Member 14594285 10-Apr-24 8:59am    
I improved my question
jeron1 10-Apr-24 10:07am    
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdlgitem
GetDlgItem() takes up to 2 input parameters, you have none specified. It returns an HWND which you are not looking at.

You could try (not tested)
C++
HWND hwnd = GetSafeHwnd();
LONG id = GetWindowLong(hwnd, GWL_ID);
 
Share this answer
 
You can also open the RC file with a text editor and search for the control.

IMPORTANT: each control must have an unique ID in your app. So check whether each control has an own identifier and the identifier are resolved in the resource.h to different values.
If that isnt properly handled than you will face trouble like crashes with some mismatching controls.
 
Share this answer
 
The MFC uses CWnd::GetDlgItem and uses an existing pointer to the parent window or dialog as a member of CWnd.

see: https://learn.microsoft.com/en-us/cpp/mfc/reference/cwnd-class?view=msvc-170#getdlgitem

Unfortunately, it is not clear from the question what the non-functioning call currently looks like.
According to the documentation, there are two possible methods for an MFC program:

C
CWnd* GetDlgItem(int nID) const;
void GetDlgItem( int nID, HWND* phWnd) const;

There is also a Win32 API function with the same name for dialog boxes
C
HWND GetDlgItem( [in, optional] HWND hDlg, [in] int nIDDlgItem);
 
Share this answer
 

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