<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Funktion zusammenbasteln]]></title><description><![CDATA[<p>Erst einmal ein Hallo an alle, ich bin neu hier im Forum und bräuchte Hilfe von erfahrenen Programmierern. Um mal eben zu erklären worum es geht:</p>
<p>Ich habe ein simples Dialogfeld erstellt mit drei EditControl Feldern. Darin soll mal ein Key eingegeben werden. Das Eingeben (nur Großbuchstaben und Zahlen) funktioniert soweit, wird etwas anderes eingegeben so erscheint eine Fehlermeldung.</p>
<p>Jetzt habe ich im Prinzip für jedes der drei Eingabefelder die selbe Lösung verwendet, würde das aber gerne auslagern und meiner Meinung nach bieten sich dann Übergaben in Form von Referenzen an. Jedoch steh ich (vielleicht liegt es am Wetter :D) irgendwie auf dem Schlauch und komme nicht weiter.</p>
<p>Hier mal mein Quellcode:</p>
<p>KeyProg.cpp</p>
<pre><code class="language-cpp">// KeyProgDlg.cpp : Implementierungsdatei
//

#include &quot;stdafx.h&quot;
#include &quot;KeyProg.h&quot;
#include &quot;KeyProgDlg.h&quot;

#include &lt;string.h&gt;

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#define MAXCHARS 6

// CAboutDlg-Dialogfeld für Anwendungsbefehl &quot;Info&quot;

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialogfelddaten
	enum { IDD = IDD_ABOUTBOX };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV-Unterstützung

// Implementierung
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()

// CKeyProgDlg-Dialogfeld

CKeyProgDlg::CKeyProgDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CKeyProgDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()-&gt;LoadIcon(IDR_MAINFRAME);
}

void CKeyProgDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_KEY1, m_sField1 );
	DDV_MaxChars(pDX, m_sField1, MAXCHARS);
	DDX_Text(pDX, IDC_KEY2, m_sField2 );
	DDV_MaxChars(pDX, m_sField2, MAXCHARS);
	DDX_Text(pDX, IDC_KEY3, m_sField3 );
	DDV_MaxChars(pDX, m_sField3, MAXCHARS);

}

BEGIN_MESSAGE_MAP(CKeyProgDlg, CDialog)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
	ON_EN_CHANGE(IDC_KEY1, &amp;CKeyProgDlg::OnEnChangeKey1)
	ON_EN_CHANGE(IDC_KEY2, &amp;CKeyProgDlg::OnEnChangeKey2)
	ON_EN_CHANGE(IDC_KEY3, &amp;CKeyProgDlg::OnEnChangeKey3)
END_MESSAGE_MAP()

// CKeyProgDlg-Meldungshandler

BOOL CKeyProgDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Hinzufügen des Menübefehls &quot;Info...&quot; zum Systemmenü.

	// IDM_ABOUTBOX muss sich im Bereich der Systembefehle befinden.
	ASSERT((IDM_ABOUTBOX &amp; 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX &lt; 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu-&gt;AppendMenu(MF_SEPARATOR);
			pSysMenu-&gt;AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Symbol für dieses Dialogfeld festlegen. Wird automatisch erledigt
	//  wenn das Hauptfenster der Anwendung kein Dialogfeld ist
	SetIcon(m_hIcon, TRUE);			// Großes Symbol verwenden
	SetIcon(m_hIcon, FALSE);		// Kleines Symbol verwenden

	// TODO: Hier zusätzliche Initialisierung einfügen

	return FALSE;  // Geben Sie TRUE zurück, außer ein Steuerelement soll den Fokus erhalten
}

void CKeyProgDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID &amp; 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// Wenn Sie dem Dialogfeld eine Schaltfläche &quot;Minimieren&quot; hinzufügen, benötigen Sie 
//  den nachstehenden Code, um das Symbol zu zeichnen. Für MFC-Anwendungen, die das 
//  Dokument/Ansicht-Modell verwenden, wird dies automatisch ausgeführt.

void CKeyProgDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // Gerätekontext zum Zeichnen

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast&lt;WPARAM&gt;(dc.GetSafeHdc()), 0);

		// Symbol in Clientrechteck zentrieren
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&amp;rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Symbol zeichnen
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// Die System ruft diese Funktion auf, um den Cursor abzufragen, der angezeigt wird, während der Benutzer
//  das minimierte Fenster mit der Maus zieht.
HCURSOR CKeyProgDlg::OnQueryDragIcon()
{
	return static_cast&lt;HCURSOR&gt;(m_hIcon);
}

int InputControl(int m_sField1, int m_sField2, int m_sField3)
{

	return m_sField1;
}

void CKeyProgDlg::OnEnChangeKey1()
{
	// TODO:  Falls dies ein RICHEDIT-Steuerelement ist, wird das Kontrollelement
	// diese Benachrichtigung nicht senden, es sei denn, Sie überschreiben die CDialog::OnInitDialog()-
	// Funktion und rufen CRichEditCtrl().SetEventMask() auf
	// mit dem ENM_CHANGE-Flag ORed in der Eingabe.

	// TODO:  Fügen Sie hier Ihren Code für die Kontrollbenachrichtigungsbehandlung ein.

	if(!UpdateData(TRUE))
	{
		return;
	}

	nLength = m_sField1.GetLength();

	LPCTSTR lpsz = m_sField1;

	for(int nAnzahl=0; nAnzahl&lt;nLength; nAnzahl++)
	{

		TCHAR cH;
		cH = lpsz[nAnzahl];

		if((cH &lt; 'A' || cH &gt; 'Z') &amp;&amp; (cH &lt; '0' || cH &gt; '9'))

		{
			AfxMessageBox(IDS_WEDIT);
			return;
		}
	}

	if(nLength == MAXCHARS)
	{
		CWnd* pField2;

		pField2 = GetDlgItem(IDC_KEY2);

				if(pField2)
				{
					pField2-&gt;SetFocus();
				}
	}
}

void CKeyProgDlg::OnEnChangeKey2()
{
	// TODO:  If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO:  Add your control notification handler code here

	if(!UpdateData(TRUE))
	{
		return;
	}

	nLengthtw = m_sField2.GetLength();
	LPCTSTR lpsz2 = m_sField2;

	for(int nAnzahlse=0; nAnzahlse&lt;nLengthtw; nAnzahlse++)
	{

		TCHAR cHS;
		cHS = lpsz2[nAnzahlse];

		if((cHS &lt; 'A' || cHS &gt; 'Z') &amp;&amp; (cHS &lt; '0' || cHS &gt; '9'))

		{
			AfxMessageBox(IDS_WEDIT);
			return;
		}
	}

	if(nLengthtw == MAXCHARS)
	{
		CWnd* pField3;

		pField3 = GetDlgItem(IDC_KEY3);

				if(pField3)
				{

					pField3-&gt;SetFocus();
				}
	}
}

void CKeyProgDlg::OnEnChangeKey3()
{
	// TODO:  If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO:  Add your control notification handler code here

	if(!UpdateData(TRUE))
	{
		return;
	}

	nLengththi = m_sField3.GetLength();
	LPCTSTR lpsz3 = m_sField3;

	for(int nAnzahlthi=0; nAnzahlthi&lt;nLengththi; nAnzahlthi++)
	{

		TCHAR cHT;
		cHT = lpsz3[nAnzahlthi];

		if((cHT &lt; 'A' || cHT &gt; 'Z') &amp;&amp; (cHT &lt; '0' || cHT &gt; '9'))

		{
			AfxMessageBox(IDS_WEDIT);
			return;
		}
	}

	if(nLengththi == MAXCHARS)
	{
		CWnd* pField3;

		pField3 = GetDlgItem(IDOK);

				if(pField3)
				{
					pField3-&gt;SetFocus();
				}
	}
}
</code></pre>
<p>Und dann noch die Header Datei (falls ihr die dringend braucht)</p>
<pre><code class="language-cpp">// KeyProgDlg.h : Headerdatei
//

#pragma once

// CKeyProgDlg-Dialogfeld
class CKeyProgDlg : public CDialog
{
// Konstruktion
public:
	CKeyProgDlg(CWnd* pParent = NULL);	// Standardkonstruktor

// Dialogfelddaten
	enum { IDD = IDD_KEYPROG_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV-Unterstützung

// Implementierung
protected:
	HICON m_hIcon;

	// Generierte Funktionen für die Meldungstabellen
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()
public:

	//int CKeyProgDlg::InputControl (CString m_sField1, CString m_sField2, CString m_sField3);

	CString m_sField1;
	CString m_sField2;
	CString m_sField3;

	int nLength;
	int nLengthtw;
	int nLengththi;

	afx_msg void OnEnChangeKey1();
	afx_msg void OnEnChangeKey2();
	afx_msg void OnEnChangeKey3();
};
</code></pre>
<p>Hätte da jemand von euch eine gute Idee/Tipp/Hilfe für eine Funktion die die Arbeit der drei OnEnChangeKeys übernimmt?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/244458/funktion-zusammenbasteln</link><generator>RSS for Node</generator><lastBuildDate>Sat, 19 Sep 2026 10:18:19 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/244458.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 30 Jun 2009 14:05:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Funktion zusammenbasteln on Tue, 30 Jun 2009 14:05:08 GMT]]></title><description><![CDATA[<p>Erst einmal ein Hallo an alle, ich bin neu hier im Forum und bräuchte Hilfe von erfahrenen Programmierern. Um mal eben zu erklären worum es geht:</p>
<p>Ich habe ein simples Dialogfeld erstellt mit drei EditControl Feldern. Darin soll mal ein Key eingegeben werden. Das Eingeben (nur Großbuchstaben und Zahlen) funktioniert soweit, wird etwas anderes eingegeben so erscheint eine Fehlermeldung.</p>
<p>Jetzt habe ich im Prinzip für jedes der drei Eingabefelder die selbe Lösung verwendet, würde das aber gerne auslagern und meiner Meinung nach bieten sich dann Übergaben in Form von Referenzen an. Jedoch steh ich (vielleicht liegt es am Wetter :D) irgendwie auf dem Schlauch und komme nicht weiter.</p>
<p>Hier mal mein Quellcode:</p>
<p>KeyProg.cpp</p>
<pre><code class="language-cpp">// KeyProgDlg.cpp : Implementierungsdatei
//

#include &quot;stdafx.h&quot;
#include &quot;KeyProg.h&quot;
#include &quot;KeyProgDlg.h&quot;

#include &lt;string.h&gt;

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#define MAXCHARS 6

// CAboutDlg-Dialogfeld für Anwendungsbefehl &quot;Info&quot;

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialogfelddaten
	enum { IDD = IDD_ABOUTBOX };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV-Unterstützung

// Implementierung
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()

// CKeyProgDlg-Dialogfeld

CKeyProgDlg::CKeyProgDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CKeyProgDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()-&gt;LoadIcon(IDR_MAINFRAME);
}

void CKeyProgDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_KEY1, m_sField1 );
	DDV_MaxChars(pDX, m_sField1, MAXCHARS);
	DDX_Text(pDX, IDC_KEY2, m_sField2 );
	DDV_MaxChars(pDX, m_sField2, MAXCHARS);
	DDX_Text(pDX, IDC_KEY3, m_sField3 );
	DDV_MaxChars(pDX, m_sField3, MAXCHARS);

}

BEGIN_MESSAGE_MAP(CKeyProgDlg, CDialog)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
	ON_EN_CHANGE(IDC_KEY1, &amp;CKeyProgDlg::OnEnChangeKey1)
	ON_EN_CHANGE(IDC_KEY2, &amp;CKeyProgDlg::OnEnChangeKey2)
	ON_EN_CHANGE(IDC_KEY3, &amp;CKeyProgDlg::OnEnChangeKey3)
END_MESSAGE_MAP()

// CKeyProgDlg-Meldungshandler

BOOL CKeyProgDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Hinzufügen des Menübefehls &quot;Info...&quot; zum Systemmenü.

	// IDM_ABOUTBOX muss sich im Bereich der Systembefehle befinden.
	ASSERT((IDM_ABOUTBOX &amp; 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX &lt; 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu-&gt;AppendMenu(MF_SEPARATOR);
			pSysMenu-&gt;AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Symbol für dieses Dialogfeld festlegen. Wird automatisch erledigt
	//  wenn das Hauptfenster der Anwendung kein Dialogfeld ist
	SetIcon(m_hIcon, TRUE);			// Großes Symbol verwenden
	SetIcon(m_hIcon, FALSE);		// Kleines Symbol verwenden

	// TODO: Hier zusätzliche Initialisierung einfügen

	return FALSE;  // Geben Sie TRUE zurück, außer ein Steuerelement soll den Fokus erhalten
}

void CKeyProgDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID &amp; 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// Wenn Sie dem Dialogfeld eine Schaltfläche &quot;Minimieren&quot; hinzufügen, benötigen Sie 
//  den nachstehenden Code, um das Symbol zu zeichnen. Für MFC-Anwendungen, die das 
//  Dokument/Ansicht-Modell verwenden, wird dies automatisch ausgeführt.

void CKeyProgDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // Gerätekontext zum Zeichnen

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast&lt;WPARAM&gt;(dc.GetSafeHdc()), 0);

		// Symbol in Clientrechteck zentrieren
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&amp;rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Symbol zeichnen
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// Die System ruft diese Funktion auf, um den Cursor abzufragen, der angezeigt wird, während der Benutzer
//  das minimierte Fenster mit der Maus zieht.
HCURSOR CKeyProgDlg::OnQueryDragIcon()
{
	return static_cast&lt;HCURSOR&gt;(m_hIcon);
}

int InputControl(int m_sField1, int m_sField2, int m_sField3)
{

	return m_sField1;
}

void CKeyProgDlg::OnEnChangeKey1()
{
	// TODO:  Falls dies ein RICHEDIT-Steuerelement ist, wird das Kontrollelement
	// diese Benachrichtigung nicht senden, es sei denn, Sie überschreiben die CDialog::OnInitDialog()-
	// Funktion und rufen CRichEditCtrl().SetEventMask() auf
	// mit dem ENM_CHANGE-Flag ORed in der Eingabe.

	// TODO:  Fügen Sie hier Ihren Code für die Kontrollbenachrichtigungsbehandlung ein.

	if(!UpdateData(TRUE))
	{
		return;
	}

	nLength = m_sField1.GetLength();

	LPCTSTR lpsz = m_sField1;

	for(int nAnzahl=0; nAnzahl&lt;nLength; nAnzahl++)
	{

		TCHAR cH;
		cH = lpsz[nAnzahl];

		if((cH &lt; 'A' || cH &gt; 'Z') &amp;&amp; (cH &lt; '0' || cH &gt; '9'))

		{
			AfxMessageBox(IDS_WEDIT);
			return;
		}
	}

	if(nLength == MAXCHARS)
	{
		CWnd* pField2;

		pField2 = GetDlgItem(IDC_KEY2);

				if(pField2)
				{
					pField2-&gt;SetFocus();
				}
	}
}

void CKeyProgDlg::OnEnChangeKey2()
{
	// TODO:  If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO:  Add your control notification handler code here

	if(!UpdateData(TRUE))
	{
		return;
	}

	nLengthtw = m_sField2.GetLength();
	LPCTSTR lpsz2 = m_sField2;

	for(int nAnzahlse=0; nAnzahlse&lt;nLengthtw; nAnzahlse++)
	{

		TCHAR cHS;
		cHS = lpsz2[nAnzahlse];

		if((cHS &lt; 'A' || cHS &gt; 'Z') &amp;&amp; (cHS &lt; '0' || cHS &gt; '9'))

		{
			AfxMessageBox(IDS_WEDIT);
			return;
		}
	}

	if(nLengthtw == MAXCHARS)
	{
		CWnd* pField3;

		pField3 = GetDlgItem(IDC_KEY3);

				if(pField3)
				{

					pField3-&gt;SetFocus();
				}
	}
}

void CKeyProgDlg::OnEnChangeKey3()
{
	// TODO:  If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO:  Add your control notification handler code here

	if(!UpdateData(TRUE))
	{
		return;
	}

	nLengththi = m_sField3.GetLength();
	LPCTSTR lpsz3 = m_sField3;

	for(int nAnzahlthi=0; nAnzahlthi&lt;nLengththi; nAnzahlthi++)
	{

		TCHAR cHT;
		cHT = lpsz3[nAnzahlthi];

		if((cHT &lt; 'A' || cHT &gt; 'Z') &amp;&amp; (cHT &lt; '0' || cHT &gt; '9'))

		{
			AfxMessageBox(IDS_WEDIT);
			return;
		}
	}

	if(nLengththi == MAXCHARS)
	{
		CWnd* pField3;

		pField3 = GetDlgItem(IDOK);

				if(pField3)
				{
					pField3-&gt;SetFocus();
				}
	}
}
</code></pre>
<p>Und dann noch die Header Datei (falls ihr die dringend braucht)</p>
<pre><code class="language-cpp">// KeyProgDlg.h : Headerdatei
//

#pragma once

// CKeyProgDlg-Dialogfeld
class CKeyProgDlg : public CDialog
{
// Konstruktion
public:
	CKeyProgDlg(CWnd* pParent = NULL);	// Standardkonstruktor

// Dialogfelddaten
	enum { IDD = IDD_KEYPROG_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV-Unterstützung

// Implementierung
protected:
	HICON m_hIcon;

	// Generierte Funktionen für die Meldungstabellen
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()
public:

	//int CKeyProgDlg::InputControl (CString m_sField1, CString m_sField2, CString m_sField3);

	CString m_sField1;
	CString m_sField2;
	CString m_sField3;

	int nLength;
	int nLengthtw;
	int nLengththi;

	afx_msg void OnEnChangeKey1();
	afx_msg void OnEnChangeKey2();
	afx_msg void OnEnChangeKey3();
};
</code></pre>
<p>Hätte da jemand von euch eine gute Idee/Tipp/Hilfe für eine Funktion die die Arbeit der drei OnEnChangeKeys übernimmt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1735098</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1735098</guid><dc:creator><![CDATA[bmth]]></dc:creator><pubDate>Tue, 30 Jun 2009 14:05:08 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion zusammenbasteln on Tue, 30 Jun 2009 14:10:51 GMT]]></title><description><![CDATA[<p>bmth schrieb:</p>
<blockquote>
<p>...ich bin neu hier im Forum...</p>
</blockquote>
<p>Das merkt man, da du dir weder den Thread &quot;Wichtig: Du brauchst Hilfe?&quot;, die Forenstruktur oder den Eingangstext in diesem Unterforum durchgelesen hast. Wie so jeder Neuling...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1735101</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1735101</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Tue, 30 Jun 2009 14:10:51 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion zusammenbasteln on Tue, 30 Jun 2009 14:14:28 GMT]]></title><description><![CDATA[<p>Falsches Forum: korrekt wäre MFC.<br />
Hoffentlich wird dein Beitrag bald verschoben.<br />
Simon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1735105</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1735105</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Tue, 30 Jun 2009 14:14:28 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion zusammenbasteln on Tue, 30 Jun 2009 14:15:57 GMT]]></title><description><![CDATA[<p>Hat irgendwer Lust so viel Code zu lesen?! Man kann Probleme auch einfacher beschreiben! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f621.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--pouting_face"
      title=":rage:"
      alt="😡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1735107</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1735107</guid><dc:creator><![CDATA[Jack the Ripper]]></dc:creator><pubDate>Tue, 30 Jun 2009 14:15:57 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion zusammenbasteln on Tue, 30 Jun 2009 14:20:22 GMT]]></title><description><![CDATA[<p>Oben und ganz unten hatte ich ja was zum Problem geschrieben <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Hier noch mal Quellcode der sich auf eines der drei Felder bezieht:</p>
<pre><code class="language-cpp">void CKeyProgDlg::OnEnChangeKey3() 
{ 
    // TODO:  If this is a RICHEDIT control, the control will not 
    // send this notification unless you override the CDialog::OnInitDialog() 
    // function and call CRichEditCtrl().SetEventMask() 
    // with the ENM_CHANGE flag ORed into the mask. 

    // TODO:  Add your control notification handler code here 

    if(!UpdateData(TRUE)) 
    { 
        return; 
    } 

    nLengththi = m_sField3.GetLength(); 
    LPCTSTR lpsz3 = m_sField3; 

    for(int nAnzahlthi=0; nAnzahlthi&lt;nLengththi; nAnzahlthi++) 
    { 

        TCHAR cHT; 
        cHT = lpsz3[nAnzahlthi]; 

        if((cHT &lt; 'A' || cHT &gt; 'Z') &amp;&amp; (cHT &lt; '0' || cHT &gt; '9')) 

        { 
            AfxMessageBox(IDS_WEDIT); 
            return; 
        } 
    } 

    if(nLengththi == MAXCHARS) 
    { 
        CWnd* pField3; 

        pField3 = GetDlgItem(IDOK); 

                if(pField3) 
                { 
                    pField3-&gt;SetFocus(); 
                } 
    } 
}
</code></pre>
<p>Und die Abläufe die hier drin stehen (Kontrolle der Eingaben in Bezug auf Großbuchstaben, Zahlen und Zeichen) soll quasi verallgemeinert werden, in einer Funktion und dann würde ich gerne z.B. die m_sField Angaben als Referenzen übergeben. Für den Fall, dass ich halt noch weitere EditControl Fenster einbaue die genau so überprüft werden sollen. Würde ich das auf dem jetzigen Wege drin stehen haben hätte ich ja das selbe Code Fragment X Mal drin stehen ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1735109</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1735109</guid><dc:creator><![CDATA[bmth]]></dc:creator><pubDate>Tue, 30 Jun 2009 14:20:22 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion zusammenbasteln on Tue, 30 Jun 2009 14:28:42 GMT]]></title><description><![CDATA[<p>Wieso lagerst du es nicht einfach in eine Funktion aus? Wenn ich richtig gesehen habe, ändert sich ja nur das <code>CString</code> Objekt. Also grundsätzlich muss du nur sowas machen:</p>
<pre><code class="language-cpp">void OnEnChangeKeyX(CString const&amp; field)
{
  // ... dein hässlicher Code ...
}

void CKeyProgDlg::OnEnChangeKey1()
{
  OnEnChangeKeyX(m_sField1);
}

void CKeyProgDlg::OnEnChangeKey2()
{
  OnEnChangeKeyX(m_sField2);
}

void CKeyProgDlg::OnEnChangeKey3()
{
  OnEnChangeKeyX(m_sField3);
}
</code></pre>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1735115</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1735115</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Tue, 30 Jun 2009 14:28:42 GMT</pubDate></item></channel></rss>