Click here to Skip to main content
15,920,383 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestiononSize of CDialog Pin
ns28-Feb-06 4:48
ns28-Feb-06 4:48 
QuestionRe: onSize of CDialog Pin
David Crow28-Feb-06 4:52
David Crow28-Feb-06 4:52 
AnswerRe: onSize of CDialog Pin
ns28-Feb-06 5:01
ns28-Feb-06 5:01 
QuestionCEdit question (should be easy) Pin
RobJones28-Feb-06 4:22
RobJones28-Feb-06 4:22 
QuestionRe: CEdit question (should be easy) Pin
David Crow28-Feb-06 4:43
David Crow28-Feb-06 4:43 
AnswerRe: CEdit question (should be easy) Pin
RobJones28-Feb-06 4:49
RobJones28-Feb-06 4:49 
QuestionRe: CEdit question (should be easy) Pin
David Crow28-Feb-06 4:50
David Crow28-Feb-06 4:50 
AnswerRe: CEdit question (should be easy) Pin
RobJones28-Feb-06 6:37
RobJones28-Feb-06 6:37 
Yeah I could have just done that... Instead I have removed the old control and created a new one. If anyone is interested this is the code. Most of this code is from the SuperPad MSDN example for changing word wrap...


void CActivationDlg::OnBnClickedCMask()
{
	UpdateData(TRUE);

	m_bMask = m_bMask ? TRUE : FALSE;

	// preserve original control's state.
	CFont* pFont = m_cKey.GetFont();
	int nLen = m_strKey.GetLength();
	TCHAR* pSaveText = new TCHAR[m_strKey.GetLength()+1];
	GetWindowText(pSaveText, nLen+1);

	DWORD dwStyle = GetWindowLong(m_cKey.GetSafeHwnd(), GWL_STYLE);

	if(!m_bMask) // Remove password mask
		dwStyle &= ~ES_PASSWORD;
	else		// Add password mask
        dwStyle |= ES_PASSWORD;

	// create new edit control with appropriate style and size.
	CActivationDlg* pParent = (CActivationDlg*)m_cKey.GetParent();
	
	CRect rect;
	m_cKey.GetWindowRect(rect);
	pParent->ScreenToClient(rect);

	UINT nID = m_cKey.GetDlgCtrlID();

	HWND hWnd = ::CreateWindowEx(WS_EX_CLIENTEDGE, _T("edit"), NULL, dwStyle,
		rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
		pParent->m_hWnd, (HMENU)nID, AfxGetInstanceHandle(), NULL);

	if (hWnd == NULL)
	{
		delete[] pSaveText;
		return;
	}

	// set the window text to nothing to make sure following set doesn't fail
	m_cKey.SetWindowText(NULL);

	// restore visual state
	::SetWindowText(hWnd, pSaveText);
	delete[] pSaveText;
	if (pFont != NULL)
	{
		ASSERT(pFont->m_hObject != NULL);
		::SendMessage(hWnd, WM_SETFONT, (WPARAM)pFont->m_hObject, 0);
	}

	// detach old window, attach new
	SetDlgCtrlID(nID+1);
	HWND hWndOld = m_cKey.Detach();
	::SetWindowLong(hWndOld, GWL_WNDPROC, (LONG)*GetSuperWndProcAddr());
	ASSERT(m_cKey.m_hWnd == NULL);
	m_cKey.SubclassWindow(hWnd);
	ASSERT(m_cKey.m_hWnd == hWnd);

	UINT nTabStops = 7;
	m_cKey.SetTabStops(nTabStops);

	m_cKey.GetClientRect(&rect);
	m_cKey.SetWindowPos(NULL, 0, 0, 0, 0,
		SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_SHOWWINDOW);
	
	m_cKey.UpdateWindow();

	// destroy old
	::SetWindowPos(hWndOld, NULL, 0, 0, 0, 0,
		SWP_HIDEWINDOW|SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|
		SWP_NOZORDER);
	::DestroyWindow(hWndOld);

	UpdateData(FALSE);
}


Whoever said nothing's impossible never tried slamming a revolving door!

-- modified at 6:45 Wednesday 1st March, 2006g door!
AnswerRe: CEdit question (should be easy) Pin
Dan McCormick28-Feb-06 16:28
Dan McCormick28-Feb-06 16:28 
GeneralRe: CEdit question (should be easy) Pin
RobJones1-Mar-06 0:45
RobJones1-Mar-06 0:45 
GeneralRe: CEdit question (should be easy) Pin
RobJones1-Mar-06 3:22
RobJones1-Mar-06 3:22 
QuestionHow a window can keep focus ? Pin
CHEICKNA TRAORE28-Feb-06 4:21
CHEICKNA TRAORE28-Feb-06 4:21 
QuestionRe: How a window can keep focus ? Pin
David Crow28-Feb-06 4:44
David Crow28-Feb-06 4:44 
AnswerRe: How a window can keep focus ? Pin
CHEICKNA TRAORE28-Feb-06 4:56
CHEICKNA TRAORE28-Feb-06 4:56 
GeneralRe: How a window can keep focus ? Pin
David Crow28-Feb-06 5:04
David Crow28-Feb-06 5:04 
GeneralRe: How a window can keep focus ? Pin
Stephen Hewitt28-Feb-06 12:41
Stephen Hewitt28-Feb-06 12:41 
QuestionHow a window can keep focus ? Pin
CHEICKNA TRAORE28-Feb-06 4:20
CHEICKNA TRAORE28-Feb-06 4:20 
QuestionHow my window keep focus ? Pin
CHEICKNA TRAORE28-Feb-06 4:18
CHEICKNA TRAORE28-Feb-06 4:18 
AnswerRe: How my window keep focus ? Pin
Miszou28-Feb-06 13:07
Miszou28-Feb-06 13:07 
QuestionPreparing Data Structure for Data Capture Pin
chaitanya2228-Feb-06 4:16
chaitanya2228-Feb-06 4:16 
QuestionRe: Preparing Data Structure for Data Capture Pin
David Crow28-Feb-06 4:47
David Crow28-Feb-06 4:47 
AnswerRe: Preparing Data Structure for Data Capture Pin
chaitanya2228-Feb-06 4:52
chaitanya2228-Feb-06 4:52 
QuestionRe: Preparing Data Structure for Data Capture Pin
David Crow28-Feb-06 4:54
David Crow28-Feb-06 4:54 
AnswerRe: Preparing Data Structure for Data Capture Pin
chaitanya2228-Feb-06 5:14
chaitanya2228-Feb-06 5:14 
GeneralRe: Preparing Data Structure for Data Capture Pin
David Crow28-Feb-06 5:26
David Crow28-Feb-06 5:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.