<?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[WM_TIMER Problem wegen einer Klasse]]></title><description><![CDATA[<p>Hallo<br />
ich habe in einer Klasse eine Scroll Funktion fuer Text geschrieben:</p>
<pre><code class="language-cpp">LCD::ScrollLineForward(char line,unsigned char* strInput,int iSpeed)
{
.
.
</code></pre>
<p>Nun habe ich das Problem das ich warten muss bis der Text gescrollt ist.<br />
Was ich aber nicht will, da ich den Text hin und her scrollen lassen will.</p>
<p>Wär das alles nicht in einer Klasse hätte ich das mit WM_TIMER gelöst.<br />
Da ich die Klasse aber portabel machen will brauch ich etwas, das<br />
innerhalb der Zeit &quot;iSpeed&quot; wieder in die Funktion(in der Klasse) springt und einen Buchstaben weiter scrollt.<br />
Wie mache ich das?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/75155/wm_timer-problem-wegen-einer-klasse</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 05:38:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/75155.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 27 May 2004 18:41:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to WM_TIMER Problem wegen einer Klasse on Thu, 27 May 2004 18:41:30 GMT]]></title><description><![CDATA[<p>Hallo<br />
ich habe in einer Klasse eine Scroll Funktion fuer Text geschrieben:</p>
<pre><code class="language-cpp">LCD::ScrollLineForward(char line,unsigned char* strInput,int iSpeed)
{
.
.
</code></pre>
<p>Nun habe ich das Problem das ich warten muss bis der Text gescrollt ist.<br />
Was ich aber nicht will, da ich den Text hin und her scrollen lassen will.</p>
<p>Wär das alles nicht in einer Klasse hätte ich das mit WM_TIMER gelöst.<br />
Da ich die Klasse aber portabel machen will brauch ich etwas, das<br />
innerhalb der Zeit &quot;iSpeed&quot; wieder in die Funktion(in der Klasse) springt und einen Buchstaben weiter scrollt.<br />
Wie mache ich das?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/528574</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/528574</guid><dc:creator><![CDATA[Ovaron123]]></dc:creator><pubDate>Thu, 27 May 2004 18:41:30 GMT</pubDate></item><item><title><![CDATA[Reply to WM_TIMER Problem wegen einer Klasse on Thu, 27 May 2004 19:06:08 GMT]]></title><description><![CDATA[<p>Ovaron123 schrieb:</p>
<blockquote>
<p>Wär das alles nicht in einer Klasse hätte ich das mit WM_TIMER gelöst.<br />
Da ich die Klasse aber portabel machen will brauch ich etwas, das<br />
innerhalb der Zeit &quot;iSpeed&quot; wieder in die Funktion(in der Klasse) springt und einen Buchstaben weiter scrollt.<br />
Wie mache ich das?</p>
</blockquote>
<p>Portabel wirst du ohne 100% Prozessor schwer schaffen ...</p>
<p>schon mal über ein SetTimer mit einem static Callback in der Klasse nachgedacht?</p>
<p>M.T.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/528589</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/528589</guid><dc:creator><![CDATA[Manuel]]></dc:creator><pubDate>Thu, 27 May 2004 19:06:08 GMT</pubDate></item><item><title><![CDATA[Reply to WM_TIMER Problem wegen einer Klasse on Thu, 27 May 2004 19:19:10 GMT]]></title><description><![CDATA[<p>Naja mit Portabel meine ich, das ich die Klasse in mehreren Projekten von mir verwenden kann.</p>
<p>Aber das mit dem &quot;static callback&quot; hört sich gut an, bloss wie funktioniert das? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/528601</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/528601</guid><dc:creator><![CDATA[Ovaron123]]></dc:creator><pubDate>Thu, 27 May 2004 19:19:10 GMT</pubDate></item><item><title><![CDATA[Reply to WM_TIMER Problem wegen einer Klasse on Thu, 27 May 2004 19:50:04 GMT]]></title><description><![CDATA[<p>Achso <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Du erstellst in der Klasse eine neue Funktion als static (Erklärung siehe C++ Handbücher) und übergibst diese als Callback bei SetTimer.</p>
<p>M.T.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/528623</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/528623</guid><dc:creator><![CDATA[Manuel]]></dc:creator><pubDate>Thu, 27 May 2004 19:50:04 GMT</pubDate></item><item><title><![CDATA[Reply to WM_TIMER Problem wegen einer Klasse on Thu, 27 May 2004 20:38:33 GMT]]></title><description><![CDATA[<p>Hm hab mal ein bisschen probiert:</p>
<pre><code class="language-cpp">class LCD
{
private:
       int nWritten;
       int DecrExOr(int key,char* szInput, char* szOutput);

       void CALLBACK TimerProc(HWND,UINT,UINT,DWORD);
       int iTimerId;
.
.
</code></pre>
<p>und in der LCD.CPP</p>
<pre><code class="language-cpp">void CALLBACK LCD::TimerProc(HWND,UINT,UINT,DWORD)
{
MessageBox(NULL,&quot;Timer wurde aufgerufen!&quot;,&quot;LCD-CLASS&quot;,MB_ICONEXCLAMATION);
}

LCD::LCD(void)
{
	DecrExOr(XKEY,(char*)&amp;CLASSVERSION,(char*)&amp;LCDCLASSVERSION);  //HilfsVaribale mit entsclüssleter Version füllen.
	hIOW = NULL; 
	ixwidth = 0; iywidth = 0; ipipe = 0;
	iTimerId = SetTimer(NULL,0,20000,this-&gt;TimerProc);
}

LCD::~LCD(void)
{
	KillTimer(NULL,iTimerId);
	if (hIOW!=NULL) //wurde hIOW initalisiert
	{ 
		IowKitCloseDevice(hIOW);
	}
    MessageBox(NULL,&quot;Destruktor wurde Aufgerufen&quot;,&quot;LCD-CLASS&quot;,MB_ICONEXCLAMATION);   //Debug Zwecke
}
</code></pre>
<p>aber es kommt immer ein Fehler und zwar:</p>
<pre><code>Compiling...
LCD.cpp
f:\work\programming\visualnet\test1\LCD.cpp(29) : error C2664: 'SetTimer' : cannot convert parameter 4 from 'void (HWND,UINT,UINT,DWORD)' to 'TIMERPROC'
        None of the functions with this name in scope match the target type
</code></pre>
<p>wie kann ich TimerProc in einer Klasse aufrufen?<br />
this-&gt;TimerProc geht wohl nicht <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>Und wiso Static? Wenn ich mehrere Objekte der Klasse habe hab ich doch bloss ein Timer.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/528626</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/528626</guid><dc:creator><![CDATA[Ovaron123]]></dc:creator><pubDate>Thu, 27 May 2004 20:38:33 GMT</pubDate></item><item><title><![CDATA[Reply to WM_TIMER Problem wegen einer Klasse on Fri, 28 May 2004 09:15:09 GMT]]></title><description><![CDATA[<p>Du musst dann eben selber über die Timer-ID entsprechend unterscheiden.<br />
Oder sowas: <a href="http://www.codeproject.com/cpp/thunk.asp?target=CThunk" rel="nofollow">http://www.codeproject.com/cpp/thunk.asp?target=CThunk</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/528833</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/528833</guid><dc:creator><![CDATA[flenders]]></dc:creator><pubDate>Fri, 28 May 2004 09:15:09 GMT</pubDate></item><item><title><![CDATA[Reply to WM_TIMER Problem wegen einer Klasse on Fri, 28 May 2004 10:42:13 GMT]]></title><description><![CDATA[<p>Also ich weiß nicht, das mit dem CThunk ist mir etwas zu kompliziert.<br />
Das versteh ich noch nicht.<br />
Ich hab da mal was gefunden:<br />
<a href="http://www.codeproject.com/cpp/SetTimer__non-static.asp" rel="nofollow">http://www.codeproject.com/cpp/SetTimer__non-static.asp</a></p>
<p>Der benutzt eine statisch und eine NICHT statische Callback Funktion.<br />
Mit der Statischen ruft er die NICHT statische auf.</p>
<pre><code class="language-cpp">class CSleeperThread : public CWinThread {
public:
  static VOID CALLBACK TimerProc_Wrapper( HWND hwnd, UINT uMsg, 
                                  UINT idEvent, DWORD dwTime );
  VOID CALLBACK TimerProc( HWND hwnd, 
                       UINT uMsg, UINT idEvent, DWORD dwTime );
  void ThreadMain();
  void WakeUp();
private:
  static void * pObject;
  UINT_PTR pTimer;
  CRITICAL_SECTION lock;
};
</code></pre>
<p>Was ich aber hier auch nicht verstehe ist das mit den &quot;CriticalSection&quot;:</p>
<pre><code class="language-cpp">VOID CALLBACK CSleeperThread::TimerProc(HWND hwnd, 
     UINT uMsg, UINT idEvent, DWORD dwTime) {
 ::EnterCriticalSection(&amp;lock);
 if(idEvent == pTimer) {
   KillTimer(NULL, pTimer);  // kill the timer so it won't fire again
   ResumeThread();  // resume the main thread function
 }
 ::LeaveCriticalSection(&amp;lock);
}
</code></pre>
<p>Und wo füge ich hier den Code von meiner Funktion an? nach ::LeaveCriticalSection(&amp;lock);?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/528889</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/528889</guid><dc:creator><![CDATA[Ovaron123]]></dc:creator><pubDate>Fri, 28 May 2004 10:42:13 GMT</pubDate></item><item><title><![CDATA[Reply to WM_TIMER Problem wegen einer Klasse on Fri, 28 May 2004 11:27:19 GMT]]></title><description><![CDATA[<p>Hi,</p>
<blockquote>
<p>Also ich weiß nicht, das mit dem CThunk ist mir etwas zu kompliziert.</p>
</blockquote>
<p>Ich habe dir trotzdem mal ein Beispiel zusammengestellt, das einen Thunk nutzt. Allerdings einen anderen als den von flenders genannten, da er nur unter Visual C++ funktioniert. Dieser sollte eigentlich mit jedem Compiler funktionieren und auf jeder x86er 32 Bit Windows-Platform laufen:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &lt;iostream&gt;
#include &lt;assert.h&gt;

template&lt;typename ObjectType, typename StaticFunctionType&gt; class CallbackThunk 
{
public:
	CallbackThunk(ObjectType* pObject, StaticFunctionType staticFunction)
	{
		*reinterpret_cast&lt;ULONG*&gt;(&amp;instructions_[0]) = 0x042444C7;
		*reinterpret_cast&lt;ULONG*&gt;(&amp;instructions_[4]) = PtrToUlong(pObject);
		*reinterpret_cast&lt;BYTE*&gt;(&amp;instructions_[8]) = 0xE9;
		*reinterpret_cast&lt;ULONG*&gt;(&amp;instructions_[9]) = PtrToUlong(staticFunction) - (PtrToUlong(this) + sizeof(CallbackThunk));

		::FlushInstructionCache(::GetCurrentProcess(), this, sizeof(CallbackThunk));
	}

	operator StaticFunctionType() const
	{
		return getCodeAddress();
	}

	StaticFunctionType getCodeAddress() const
	{
		return StaticFunctionType(this);
	}
private:
	char instructions_[13];
};

template&lt;typename Type&gt; class Timer
{
public:
	Timer(Type* pObject, void (Type::*pOnTimerElapsed)())
		: identifier_(0)
		, callbackThunk_(this, timerCallback)
		, pObject_(pObject)
		, pOnTimerElapsed_(pOnTimerElapsed)
	{
	}

	~Timer()
	{
		if(identifier_ != 0)
		{
			kill();
		}

	}

	void set(UINT interval)
	{
		assert(identifier_ == 0);

		identifier_ = ::SetTimer(NULL, 0, interval, callbackThunk_);
	}

	void kill()
	{
		assert(identifier_ != 0);

		::KillTimer(NULL, identifier_);

		identifier_ = 0;
	}
private:
	static void CALLBACK timerCallback(HWND windowHandle, UINT message, UINT_PTR identifier, DWORD time)
	{
		// Der Thunk hat den Parameter windowHandle, den wir sowieso nicht brauchen,
		// durch den Zeiger auf die Timer-Instanz ersetzt.
		Timer* pTimer = reinterpret_cast&lt;Timer*&gt;(windowHandle);
		pTimer-&gt;call();
	}
	void call()
	{
		// Aufruf der im Konstruktor festgelegten Memberfunktion
		(pObject_-&gt;*pOnTimerElapsed_)();
	}
private:
	UINT_PTR identifier_;
	CallbackThunk&lt;Timer, TIMERPROC&gt; callbackThunk_;
	Type* pObject_;
	void (Type::*pOnTimerElapsed_)();
};

class LCD
{
public:
	LCD()
		: timer_(this, &amp;LCD::onTimerElapsed)
	{
		timer_.set(1000);
	}

	void onTimerElapsed()
	{
		std::cout &lt;&lt; &quot;onTimerElapsed&quot; &lt;&lt; std::endl;
	}
private:
	Timer&lt;LCD&gt; timer_;
};

int main()
{
	LCD lcd;

	MSG message;
	while(GetMessage(&amp;message, NULL, 0, 0))
	{
		DispatchMessage(&amp;message);
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/528917</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/528917</guid><dc:creator><![CDATA[Matthias.]]></dc:creator><pubDate>Fri, 28 May 2004 11:27:19 GMT</pubDate></item></channel></rss>