<?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[Childwindow mit CreateWindow klappt net]]></title><description><![CDATA[<p>hiho,</p>
<p>folgendes problemchen:</p>
<p>ich möchte mir ein childwindow erzeugen, das ein eingabemaske für texte dienen soll. nun hab ich versucht mir das fenster mit create window zu erzeugen</p>
<pre><code class="language-cpp">hAddWnd = CreateWindow(L&quot;AddWnd&quot;, L&quot;Add Knowledge&quot;, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_CHILD| WS_THICKFRAME | WS_VISIBLE, 200, 300, 600, 800, hWnd, (HMENU) ID_ADDSOLUTION, NULL, NULL);
</code></pre>
<p>leider funktionert das überhaupt nicht.das fenster wird zwar erzeugt, ist aber ausgegraut(disabled) und lässt sich auch nicht bewegen</p>
<p>Wenn ich jetzt aber hinten die Werte &quot;hWnd&quot; und die ID_ADDSOLUTION herauswerfe und die Werte auf NULL setze wird immerhin ein funktionierendes fenster erzeugt. nun verstehe ich nicht ganz was mein problem ist.</p>
<p>Wieso darf ich bei einem child-window nicht das parentwindow einsetzen? und wieso darf ich dem auch keine id zuweisen?</p>
<p>oder was ist mein problem. die msdn doku liefert mir dazu nix hilfreiches.</p>
<p>bin da etwas verwirrt.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/199588/childwindow-mit-createwindow-klappt-net</link><generator>RSS for Node</generator><lastBuildDate>Tue, 28 Apr 2026 14:27:59 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/199588.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 04 Dec 2007 20:25:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Childwindow mit CreateWindow klappt net on Tue, 04 Dec 2007 20:25:18 GMT]]></title><description><![CDATA[<p>hiho,</p>
<p>folgendes problemchen:</p>
<p>ich möchte mir ein childwindow erzeugen, das ein eingabemaske für texte dienen soll. nun hab ich versucht mir das fenster mit create window zu erzeugen</p>
<pre><code class="language-cpp">hAddWnd = CreateWindow(L&quot;AddWnd&quot;, L&quot;Add Knowledge&quot;, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_CHILD| WS_THICKFRAME | WS_VISIBLE, 200, 300, 600, 800, hWnd, (HMENU) ID_ADDSOLUTION, NULL, NULL);
</code></pre>
<p>leider funktionert das überhaupt nicht.das fenster wird zwar erzeugt, ist aber ausgegraut(disabled) und lässt sich auch nicht bewegen</p>
<p>Wenn ich jetzt aber hinten die Werte &quot;hWnd&quot; und die ID_ADDSOLUTION herauswerfe und die Werte auf NULL setze wird immerhin ein funktionierendes fenster erzeugt. nun verstehe ich nicht ganz was mein problem ist.</p>
<p>Wieso darf ich bei einem child-window nicht das parentwindow einsetzen? und wieso darf ich dem auch keine id zuweisen?</p>
<p>oder was ist mein problem. die msdn doku liefert mir dazu nix hilfreiches.</p>
<p>bin da etwas verwirrt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1415016</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1415016</guid><dc:creator><![CDATA[winzenden]]></dc:creator><pubDate>Tue, 04 Dec 2007 20:25:18 GMT</pubDate></item><item><title><![CDATA[Reply to Childwindow mit CreateWindow klappt net on Wed, 05 Dec 2007 15:00:56 GMT]]></title><description><![CDATA[<p>Haste hAddWnd auch statisch? und evtl. solltest du noch nen handle der instance uebergeben.</p>
<p>Gruß Tobi.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1415341</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1415341</guid><dc:creator><![CDATA[T0bi]]></dc:creator><pubDate>Wed, 05 Dec 2007 15:00:56 GMT</pubDate></item><item><title><![CDATA[Reply to Childwindow mit CreateWindow klappt net on Tue, 11 Dec 2007 10:17:17 GMT]]></title><description><![CDATA[<p>klappt leider nicht.</p>
<pre><code class="language-cpp">hAddWnd = CreateWindow(L&quot;AddWnd&quot;, L&quot;Add Knowledge&quot;, WS_OVERLAPPED | WS_CHILD | 
WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_VISIBLE, 200, 300, 600, 800, hWnd, (HMENU) ID_ADDSOLUTION, hInst, NULL);
</code></pre>
<p>wenn ich als instance ((LPCREATESTRUCT)lParam)-&gt;hInstance benutze gibts nen laufzeitfehler.</p>
<p>der handel ist static. was mach ich falsch?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1418623</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1418623</guid><dc:creator><![CDATA[winzenden]]></dc:creator><pubDate>Tue, 11 Dec 2007 10:17:17 GMT</pubDate></item><item><title><![CDATA[Reply to Childwindow mit CreateWindow klappt net on Tue, 11 Dec 2007 10:33:17 GMT]]></title><description><![CDATA[<p>Wie sieht denn deine WNDCLASS aus?</p>
<p>schirrmie</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1418629</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1418629</guid><dc:creator><![CDATA[schirrmie]]></dc:creator><pubDate>Tue, 11 Dec 2007 10:33:17 GMT</pubDate></item><item><title><![CDATA[Reply to Childwindow mit CreateWindow klappt net on Wed, 12 Dec 2007 06:55:41 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX);

	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_KNOWLEDGEBASE));
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= MAKEINTRESOURCE(IDC_KNOWLEDGEBASE);
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

	RegisterClassEx(&amp;wcex);

	wcex.lpszClassName = TEXT(&quot;AddWnd&quot;);
	wcex.lpfnWndProc   = AddProc;
	wcex.hIcon		   = NULL;
	wcex.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);

	return RegisterClassEx(&amp;wcex);
</code></pre>
<p>der untere teil is mein child-window.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1419131</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1419131</guid><dc:creator><![CDATA[winzenden]]></dc:creator><pubDate>Wed, 12 Dec 2007 06:55:41 GMT</pubDate></item><item><title><![CDATA[Reply to Childwindow mit CreateWindow klappt net on Wed, 12 Dec 2007 07:17:25 GMT]]></title><description><![CDATA[<p>Zeig mal bitte Deine AddProc Fensterprozedur. Ich vermute mal an der ist was faul.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1419143</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1419143</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Wed, 12 Dec 2007 07:17:25 GMT</pubDate></item><item><title><![CDATA[Reply to Childwindow mit CreateWindow klappt net on Fri, 14 Dec 2007 16:40:50 GMT]]></title><description><![CDATA[<p>hier, momentan soll darin noch nichts passsieren, einfach nur durchlaufen.<br />
fehtl da etwas, das zwingend notwendig ist ?</p>
<pre><code class="language-cpp">LRESULT CALLBACK AddProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{

	switch(message)
	{
	case WM_CREATE:
		{

		break;
		}

	case WM_SIZE:
		{

		break;
		}

	case WM_COMMAND:
		{
		break;
		}

	case WM_PAINT:
		{
			return 0;
		}

	case WM_CLOSE:
		{
		DestroyWindow(hWnd);
		return (0);
		}
	}

return DefWindowProc(hWnd, message, wParam, lParam);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1420648</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1420648</guid><dc:creator><![CDATA[winzenden]]></dc:creator><pubDate>Fri, 14 Dec 2007 16:40:50 GMT</pubDate></item><item><title><![CDATA[Reply to Childwindow mit CreateWindow klappt net on Fri, 14 Dec 2007 20:44:12 GMT]]></title><description><![CDATA[<p>Ist doch kein Wunder, wenn Du nicht mal WM_PAINT behandelst.<br />
Das führt zu einer Endlosschleife...</p>
<p>Wenn Du eine Nachricht nicht behandelst, dann lass den Handler einfach Weg.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1420781</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1420781</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Fri, 14 Dec 2007 20:44:12 GMT</pubDate></item><item><title><![CDATA[Reply to Childwindow mit CreateWindow klappt net on Sat, 15 Dec 2007 23:32:49 GMT]]></title><description><![CDATA[<p>Hi Martin,<br />
das die Handler weg sollten, wenn man die entsprechende Nachricht nicht behandelt ist klar (bringt ja auch nichts), aber wieso entsteht da eine Endlosschleife? Er hat doch in WM_PAINT nichts à la Aufruf von MessageBox zu stehen! <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>
<p>MfG WilMen <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1421188</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1421188</guid><dc:creator><![CDATA[WilMen]]></dc:creator><pubDate>Sat, 15 Dec 2007 23:32:49 GMT</pubDate></item><item><title><![CDATA[Reply to Childwindow mit CreateWindow klappt net on Sun, 16 Dec 2007 14:00:19 GMT]]></title><description><![CDATA[<p>Martin Richter schrieb:</p>
<blockquote>
<p>Ist doch kein Wunder, wenn Du nicht mal WM_PAINT behandelst.<br />
Das führt zu einer Endlosschleife...</p>
<p>Wenn Du eine Nachricht nicht behandelst, dann lass den Handler einfach Weg.</p>
</blockquote>
<p>ich hab die WM_Paint mal rausgenommen, der effekt ist aber der selbe geblieben. da tut sich einfach nix.....</p>
<p>gibts irgendwo ein bissle sample-code für ein stinknormales childfenster?!</p>
<p>was ich zudem nicht verstehe ist, wenn ich das parentWnd weglasse (also NULL setze den parameter)wird das fenster scheinbar normal erstellt. und ich kann damit arbeiten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1421369</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1421369</guid><dc:creator><![CDATA[winzenden]]></dc:creator><pubDate>Sun, 16 Dec 2007 14:00:19 GMT</pubDate></item><item><title><![CDATA[Reply to Childwindow mit CreateWindow klappt net on Sun, 16 Dec 2007 14:51:27 GMT]]></title><description><![CDATA[<p>Wenn niemals BeginPaint aufgerufen wird, und das geschieht bei Dir bene nicht, wird immer iweder WM_PAINT versendet.</p>
<p>Hats Du mal ein Sample Download von Deiner Source....</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1421389</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1421389</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Sun, 16 Dec 2007 14:51:27 GMT</pubDate></item><item><title><![CDATA[Reply to Childwindow mit CreateWindow klappt net on Sun, 16 Dec 2007 15:45:23 GMT]]></title><description><![CDATA[<p>Hi, probier's mal hiermit:</p>
<pre><code class="language-cpp">hWndChild = CreateWindow (TEXT(&quot;AddWnd&quot;), NULL,
                              WS_CHILDWINDOW | WS_VISIBLE,
                              x, y, nWidth, nHeight,
                              hwnd, (HMENU) (y &lt;&lt; 8 | x),
                              (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE),
                              NULL) ;
</code></pre>
<p>Damit du das Fenster auch siehst bzw. siehst ob es geklappt hat oder nicht, wär es nicht schlecht die AddProc so zu ergänzen (nur zum Testen!!!):</p>
<pre><code class="language-cpp">static RECT rect ;
HDC hDC ;
PAINTSTRUCT ps ;
// ...
case WM_SIZE:
GetClientRect (hWnd, &amp;rect) ;
return 0 ;

case WM_PAINT:
hDC = BeginPaint (hWnd, &amp;ps) ;
Rectangle (hDC, rect.left, rect.top, rect.right, rect.bottom) ;
EndPaint (hWnd, &amp;ps) ;
return 0 ;
//...
</code></pre>
<p>MfG WilMen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1421424</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1421424</guid><dc:creator><![CDATA[WilMen]]></dc:creator><pubDate>Sun, 16 Dec 2007 15:45:23 GMT</pubDate></item><item><title><![CDATA[Reply to Childwindow mit CreateWindow klappt net on Sun, 16 Dec 2007 18:28:20 GMT]]></title><description><![CDATA[<p>Martin Richter schrieb:</p>
<blockquote>
<p>Wenn niemals BeginPaint aufgerufen wird, und das geschieht bei Dir bene nicht, wird immer iweder WM_PAINT versendet.</p>
<p>Hats Du mal ein Sample Download von Deiner Source....</p>
</blockquote>
<p>Öhm nein. Wieso auch? Wieso sollte das erstemal WM_PAINT versendet werden nur weil es zur Auswahl steht? o.O Es könnte allerdings sein dass es mit UpdateWindow erzwungen wird. Aber das endet auch nicht in einer Endlosschleife.</p>
<p>Du solltest alle <em>UpdateWindow&quot;s&quot;();</em> weglassen<br />
Ich denke das Problem liegt darin dass du ein zweiter Objekt von WNDCLASSEX machen solltest a la :</p>
<pre><code class="language-cpp">//das hier bei der WM_COMMAND Ereignissbehandlung(WndProc) hinzufügen
//natürlich mit LParam und richtigen Button etc.
    WNDCLASSEX wcAddex; 

    wcAddex.cbSize = sizeof(WNDCLASSEX); 
//hier dein Code:
    wcAddex.style            = CS_HREDRAW | CS_VREDRAW; 
    wcAddex.lpfnWndProc    = AddProc; //oder wie auch immer das heist
    wcAddex.cbClsExtra        = 0; 
    wcAddex.cbWndExtra        = 0; 
    wcAddex.hInstance        = hInstance; 
    wcAddex.hIcon            = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_KNOWLEDGEBASE)); 
    wcAddex.hCursor        = LoadCursor(NULL, IDC_ARROW); 
    wcAddex.hbrBackground    = (HBRUSH)(COLOR_WINDOW+1); 
    wcAddex.lpszMenuName    = MAKEINTRESOURCE(IDC_KNOWLEDGEBASE); 
    wcAddex.lpszClassName    = szWindowClass; //HIER ANDERER KLASSEN NAME
    wcAddex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); 

    //Hier wird das Fenster registiert
    RegisterClassEx(&amp;wcAddex); 
    //So dann musst du das Fenster noch erstellen aber als eignes eben nicht 
    //Childwindow

    hAddnd = CreateWindowW() //Hier deine Fensterbeschreibung
    ShowWindowW(&amp;hAddnd,nCmdShow);
    //No Need for UpdateWindow. UpdateWindow erzwingt eine WM_PAINT Message 
    //die muss allerdings nicht behandelt werden und endet keinesfalls in einer
    //Endlosschleife
</code></pre>
<p>Mit einem Childwindow wird das wohl ähnlich gehen so oder so ähnlich muss es alllerdings klappen. Noch eine Anmerkunge lass das erste UpdateWindow in deinem InitCode( Code der immer initalisiert wird).<br />
Viel Spass noch.</p>
<p>P.S.: Kann sein das unzählige Fehler im Code sind, aber bei mir hat das schon eimal so geklappt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1421521</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1421521</guid><dc:creator><![CDATA[C-Chris]]></dc:creator><pubDate>Sun, 16 Dec 2007 18:28:20 GMT</pubDate></item><item><title><![CDATA[Reply to Childwindow mit CreateWindow klappt net on Sun, 16 Dec 2007 19:01:32 GMT]]></title><description><![CDATA[<p>Wenn ein WM_PAINT Handler eingebaut ist, der nichts tut, wird sofort wieder WM_PAINT gesendet...<br />
Nur wenn man BeginPaint/EndPaint verwendet wird das Fenster validiert.<br />
Das selbe macht natürlich die DefWindowProc, nur wurde die im ersten Snippelt nicht verwendet.</p>
<p>Das sagt aber dennoch nicht, warum man das Fenster nicht ziehen und aktivieren kann. Man müsste mehr Code sehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1421556</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1421556</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Sun, 16 Dec 2007 19:01:32 GMT</pubDate></item><item><title><![CDATA[Reply to Childwindow mit CreateWindow klappt net on Sun, 16 Dec 2007 19:06:18 GMT]]></title><description><![CDATA[<p>Gentlemen, ich bin ganz seiner Meinung. Er soll endlich mal den kompletten Code posten, sonst führt das hier zu nichts!</p>
<p>MfG WilMen :xmas1:</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1421560</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1421560</guid><dc:creator><![CDATA[WilMen]]></dc:creator><pubDate>Sun, 16 Dec 2007 19:06:18 GMT</pubDate></item><item><title><![CDATA[Reply to Childwindow mit CreateWindow klappt net on Mon, 17 Dec 2007 17:28:14 GMT]]></title><description><![CDATA[<p>ok, hier ist mal der ganze code des hauptprogrammes:</p>
<pre><code>// KnowledgeBase.cpp : Definiert den Einstiegspunkt für die Anwendung.
//

#include &quot;stdafx.h&quot;
#include &quot;main.h&quot;
#include &quot;commctrl.h&quot;
#include &lt;winsock.h&gt;
#include &lt;mysql.h&gt;
#include &quot;CRequestDB.h&quot;
#include &quot;CSearchArg.h&quot;

#define MAX_LOADSTRING 100
#define ID_LISTVIEW			WM_USER+1
#define ID_SEARCHLINE		WM_USER+2
#define ID_GOBUTTON			WM_USER+3
#define LV_WIDTH			WM_USER+4
#define LV_HEIGHT			WM_USER+5
#define ID_ADDSOLUTION		WM_USER+6

// Globale Variablen:
HINSTANCE hInst;								// Aktuelle Instanz
TCHAR szTitle[MAX_LOADSTRING];					// Titelleistentext
TCHAR szWindowClass[MAX_LOADSTRING];			// Klassenname des Hauptfensters
TRACKMOUSEEVENT tme;

// Vorwärtsdeklarationen der in diesem Codemodul enthaltenen Funktionen:
ATOM				MyRegisterClass(HINSTANCE hInstance);
BOOL				InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc       (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK	SearchLineProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK    ListViewProc  (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK	AddProc       (HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK	About         (HWND, UINT, WPARAM, LPARAM);

// Hilfsfunktionen
int CreateColumn(HWND hwnd, int iCol, TCHAR* Text, int iBreite);
int Create2ColItem(HWND hwnd, TCHAR *Text1, TCHAR *Text2);
std::string GetSearchText(HWND hSearchLine);
void OutputQueryResultsToListView(HWND hListView, CRequestDB *myRequest);

static LONG_PTR PrevWndProcSearchLine;
static LONG_PTR PrevWndProcListView;

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

 	// TODO: Hier Code einfügen.
	MSG msg;
	HACCEL hAccelTable;

	// Globale Zeichenfolgen initialisieren
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_KNOWLEDGEBASE, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// Anwendungsinitialisierung ausführen:
	if (!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_KNOWLEDGEBASE));

	// Hauptmeldungsschleife:
	while (GetMessage(&amp;msg, NULL, 0, 0))
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &amp;msg))
		{
			TranslateMessage(&amp;msg);
			DispatchMessage(&amp;msg);
		}
	}

	return (int) msg.wParam;
}

//
//  FUNKTION: MyRegisterClass()
//
//  ZWECK: Registriert die Fensterklasse.
//
//  KOMMENTARE:
//
//    Sie müssen die Funktion verwenden,  wenn Sie möchten, dass der Code
//    mit Win32-Systemen kompatibel ist, bevor die RegisterClassEx-Funktion
//    zu Windows 95 hinzugefügt wurde. Der Aufruf der Funktion ist wichtig,
//    damit die kleinen Symbole, die mit der Anwendung verknüpft sind,
//    richtig formatiert werden.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX);

	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_KNOWLEDGEBASE));
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= MAKEINTRESOURCE(IDC_KNOWLEDGEBASE);
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

	RegisterClassEx(&amp;wcex);

	wcex.lpszClassName = TEXT(&quot;AddWnd&quot;);
	wcex.lpfnWndProc   = AddProc;
	wcex.hIcon		   = NULL;
	wcex.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);

	return RegisterClassEx(&amp;wcex);
}

//
//   FUNKTION: InitInstance(HINSTANCE, int)
//
//   ZWECK: Speichert das Instanzenhandle und erstellt das Hauptfenster.
//
//   KOMMENTARE:
//
//        In dieser Funktion wird das Instanzenhandle in einer globalen Variablen gespeichert, und das
//        Hauptprogrammfenster wird erstellt und angezeigt.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // Instanzenhandle in der globalen Variablen speichern

   int screenWidth  = GetSystemMetrics(SM_CXFULLSCREEN);
   int screenHeight = GetSystemMetrics(SM_CYFULLSCREEN);

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX,
      static_cast&lt;int&gt;((screenWidth  - (screenWidth  / 1.25)) / 2), // Mittig zentrieren X-Achse 
	  static_cast&lt;int&gt;((screenHeight - (screenHeight / 1.25)) / 2), // Mittig zentrieren Y-Achse
	  static_cast&lt;int&gt;(screenWidth  / 1.25), // 
	  static_cast&lt;int&gt;(screenHeight / 1.25),
	  NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

//
//  FUNKTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  ZWECK:  Verarbeitet Meldungen vom Hauptfenster.
//
//  WM_COMMAND	- Verarbeiten des Anwendungsmenüs
//  WM_PAINT	- Zeichnen des Hauptfensters
//  WM_DESTROY	- Beenden-Meldung anzeigen und zurückgeben
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc, hdcTmp;
	static HWND	hListView, hSearchLine, hGoButton, hAddWnd;
	static int iWindowWidth, iWindowHeight;

	switch (message)
	{
	case WM_CREATE:

		/*************************/
		/* Erzeugen der ListView */
		/*************************/

		INITCOMMONCONTROLSEX	inicc;
		inicc.dwSize = sizeof(INITCOMMONCONTROLSEX);
		inicc.dwICC = ICC_LISTVIEW_CLASSES; 
		InitCommonControlsEx(&amp;inicc);

		hListView = CreateWindow(WC_LISTVIEW ,L&quot;&quot;, WS_VISIBLE | WS_BORDER | WS_CHILD | LVS_REPORT | LVS_EDITLABELS,
			0, 0, 0, 0, hWnd, HMENU(ID_LISTVIEW), ((LPCREATESTRUCT)lParam)-&gt;hInstance, NULL);

		PrevWndProcListView = SetWindowLongPtr(hListView, GWLP_WNDPROC, (LONG_PTR) ListViewProc);

		ListView_SetExtendedListViewStyle(hListView, LVS_EX_FULLROWSELECT);
		ListView_SetExtendedListViewStyle(hListView, ListView_GetExtendedListViewStyle(hListView) | LVS_EX_GRIDLINES );

		/******************************************/
		/* Erzeugen der Zeile für den Suchbegriff */
		/******************************************/

		hSearchLine = CreateWindow(L&quot;edit&quot;, L&quot;&quot;, WS_VISIBLE | WS_CHILD | ES_LEFT | WS_TABSTOP ,
									0, 0, 0, 0, hWnd, HMENU(ID_SEARCHLINE), ((LPCREATESTRUCT)lParam)-&gt;hInstance, NULL);

		PrevWndProcSearchLine = SetWindowLongPtr(hSearchLine, GWLP_WNDPROC, (LONG_PTR) SearchLineProc);

		/***********************************************/
		/* Erzeugen des Button für den Start der Suche */
		/***********************************************/

		hGoButton   = CreateWindowEx(WS_EX_WINDOWEDGE, L&quot;button&quot;, L&quot;Go&quot;, WS_VISIBLE | WS_CHILD | WS_TABSTOP, 
									0, 0, 0, 0, hWnd, HMENU(ID_GOBUTTON), ((LPCREATESTRUCT)lParam)-&gt;hInstance, NULL);

		break;

	case WM_SIZE:
		iWindowHeight = LOWORD(lParam);
		iWindowWidth  = LOWORD(lParam);

		//Positionieren und Festlegen der Größe des Listview im Fenster
		MoveWindow(hListView, 0, 
							  static_cast&lt;int&gt;(iWindowHeight / 10), //Unter grauen Block positionieren
							  iWindowWidth, //Ausdehnung im Fenster auf volle Breite 
							  static_cast&lt;int&gt;(iWindowHeight - (iWindowHeight / 10)), //Höhe der ListView = Fensterhöhe, abzüglich grauen Block
							  true);

		//Positionieren und Festlegen der Größe des Eingabfeldes für den Suchbegriff im Fenster

		TEXTMETRIC	tm;

		hdcTmp = GetDC(hWnd);
		GetTextMetrics(hdcTmp, &amp;tm);
		ReleaseDC(hWnd, hdcTmp);

		MoveWindow(hSearchLine, static_cast&lt;int&gt;(iWindowWidth / 5),
								static_cast&lt;int&gt;((iWindowHeight / 10) / 2),
								tm.tmMaxCharWidth * 50,
								tm.tmHeight,
								true);

		SetFocus(hSearchLine);		

		// Positionieren des Buttons

		MoveWindow(hGoButton, static_cast&lt;int&gt;((iWindowWidth / 5) + (tm.tmMaxCharWidth * 50) + 50),
							  static_cast&lt;int&gt;(((iWindowHeight / 10) / 2) - 5),
							  50, tm.tmHeight + 10, true);

		/******************************
		/* LISTVIEW EINTRÄGE TEST ****/
		/******************************

		/* Hinzufügen von 2 Spaltenüberschriften */
		CreateColumn(hListView, 0, L&quot;Lösungs-ID&quot;, 100);
		CreateColumn(hListView, 1, L&quot;Anlesetext&quot;, iWindowWidth - 100); 
		/* Testeintrag für eine Zeile */
		Create2ColItem(hListView, L&quot;EY&quot;, L&quot;SSSS&quot;);
		Create2ColItem(hListView, L&quot;EY2&quot;, L&quot;SSSS2&quot;);

		break;

	case WM_NOTIFY:
		switch(((LPNMHDR) lParam)-&gt;code)
		{
		case(LVN_BEGINLABELEDIT): /* Verhindern, dass man Einträge editieren kann, einfach true zurückgeb. */
			return true;
		}
	case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// Menüauswahl bearbeiten:
		switch (wmId)
		{
		case IDM_ADD_SOLUTION:
			//hAddWnd = CreateWindow(L&quot;AddWnd&quot;, L&quot;Add Knowledge&quot;, WS_OVERLAPPED  |WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_VISIBLE, 200, 300, 600, 400, NULL, NULL, NULL, NULL);
			hAddWnd = CreateWindow(L&quot;AddWnd&quot;, L&quot;Add Knowledge&quot;, WS_OVERLAPPED | WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_VISIBLE, 200, 300, 600, 800, hWnd, (HMENU) ID_ADDSOLUTION, hInst, NULL);
			/*CreateWindowEx(WS_EX_CLIENTEDGE, TEXT(&quot;SUB&quot;), TEXT(&quot;Erfassung des Adressbuchbesitzer&quot;),
										WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_VISIBLE , 320, 240, 480, 150,
										NULL, NULL, NULL, NULL);*/
			//MessageBox(hWnd, L&quot;bin drin&quot;, L&quot;blub&quot;, MB_OK);
			break;
		case IDM_\1:
			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
			break;
		case IDM_EXIT:
			DestroyWindow(hWnd);
			break;
		case ID_GOBUTTON:
			{
			CRequestDB *myRequest = new CRequestDB(hWnd, &quot;localhost&quot;,&quot;root&quot;,&quot;root&quot;,&quot;knowledgebase&quot;,3306);
			CSearchArg  mySearchArg;
			myRequest-&gt;SearchDB(mySearchArg.GetSearchArguments(hSearchLine));
			OutputQueryResultsToListView(hListView, myRequest);
			delete myRequest;
			break;
			}
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		break;

	case WM_PAINT:
		{

		RECT clientArea;

		hdc = BeginPaint(hWnd, &amp;ps);
		HBRUSH hOldBrush = (HBRUSH)SelectObject(hdc,
												CreateSolidBrush(RGB(198,192,192)));

		SelectObject(hdc, CreatePen(PS_SOLID, 0, RGB(198, 192, 192)));

		clientArea.left = 0;
		clientArea.top  = 0;
		clientArea.right = iWindowWidth;
		clientArea.bottom = iWindowHeight / 10;

		Rectangle(hdc,
				  0,
				  0,
				  iWindowWidth,
				  iWindowHeight / 10);

		SetBkColor(hdc, RGB(198,192,192));

		DeleteObject(SelectObject(hdc, hOldBrush));

		/******************************************/

		HFONT hFont = CreateFont(14, 14, 0, 0,
								  FW_BOLD,
								  false, false, false,
								  DEFAULT_CHARSET,
								  OUT_DEFAULT_PRECIS,
								  CLIP_DEFAULT_PRECIS,
								  ANTIALIASED_QUALITY,
								  DEFAULT_PITCH ,
								  L&quot;test&quot;);

		SelectObject(hdc, hFont);
		TextOut(hdc, static_cast&lt;int&gt;(iWindowWidth / 5), /*Exakte x-Position der Suchzeile */
					 static_cast&lt;int&gt;((iWindowHeight / 10) / 2) - (iWindowHeight / 50), /* Y-Position leicht nach oben versetzt, von Y-Pos. der Suchzeile */
					 L&quot;Suchbegriff eingeben:&quot;, 21);

		DeleteObject(hFont);

		EndPaint(hWnd, &amp;ps);
		break;
		}
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}

LRESULT CALLBACK SearchLineProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case WM_KEYDOWN:
		switch(wParam)
		{
		case 0x0D: /* Carrige Return (Entertaste) abfragen */
			HWND hMainWnd = FindWindow(szWindowClass, szTitle);
			SendMessage(hMainWnd, WM_COMMAND, ID_GOBUTTON, NULL); /* Bei Eingabetaste identisch wie mit Buttonklick verhalten */
			break;  
		}
	}

return CallWindowProc ((WNDPROC) PrevWndProcSearchLine, hWnd, message, wParam, lParam);
}

LRESULT CALLBACK ListViewProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{

	switch(message)
	{
		POINT hitPoint;

	case WM_MOUSEMOVE:
		TRACKMOUSEEVENT tme;
		tme.cbSize = sizeof(TRACKMOUSEEVENT);
		tme.dwFlags = TME_HOVER;
		tme.dwHoverTime = HOVER_DEFAULT;
		tme.hwndTrack = hWnd;
		TrackMouseEvent(&amp;tme);
		break;

	case WM_MOUSEHOVER:
		GetCursorPos(&amp;hitPoint);
		LVHITTESTINFO pHitInfo;
		ScreenToClient(hWnd,&amp;hitPoint);
		pHitInfo.pt = hitPoint;
		ListView_HitTest(hWnd, &amp;pHitInfo.pt);
		break;
	}

return CallWindowProc ((WNDPROC) PrevWndProcListView, hWnd, message, wParam, lParam);
}

LRESULT CALLBACK AddProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{

	switch(message)
	{
	case WM_CREATE:
		{

		break;
		}

	case WM_SIZE:
		{

		break;
		}

	case WM_COMMAND:
		{
		break;
		}

	case WM_CLOSE:
		{
		DestroyWindow(hWnd);
		return (0);
		}
	}

return DefWindowProc(hWnd, message, wParam, lParam);
}

// Meldungshandler für Infofeld.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	UNREFERENCED_PARAMETER(lParam);
	switch (message)
	{
	case WM_INITDIALOG:
		return (INT_PTR)TRUE;

	case WM_COMMAND:
		if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
		{
			EndDialog(hDlg, LOWORD(wParam));
			return (INT_PTR)TRUE;
		}
		break;
	}
	return (INT_PTR)FALSE;
}

int CreateColumn(HWND hwndLV, int iCol, TCHAR* Text, int iBreite)
{
	LVCOLUMN lvc;
	lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
	lvc.fmt = LVCFMT_LEFT;
	lvc.cx = iBreite;
	lvc.pszText = Text;  
	lvc.iSubItem = iCol;
	return ListView_InsertColumn(hwndLV, iCol, &amp;lvc);
}

int CreateItem(HWND hwndLV, TCHAR *Text)
{ 
LVITEM lvi = {0};

    lvi.mask = LVIF_TEXT;
    lvi.pszText = Text;
    return ListView_InsertItem(hwndLV, &amp;lvi);
} 

int Create2ColItem(HWND hwndLV, TCHAR *Text1, TCHAR *Text2)
{ 
LVITEM lvi = {0};
int Ret;

    // Initialize LVITEM members that are common to all items. 
    lvi.mask = LVIF_TEXT;
    lvi.pszText = Text1;
    Ret = ListView_InsertItem(hwndLV, &amp;lvi);
    if (Ret&gt;=0) {
        ListView_SetItemText(hwndLV, Ret, 1, Text2);
    }
    return Ret;
}

std::string GetSearchText(HWND hSearchLine)
{

	TCHAR cSearchText[1000];
	char  cMulBySearchText[1000];

	GetWindowText(hSearchLine, cSearchText, 1000);

	WideCharToMultiByte(CP_UTF8, 0, cSearchText, 1000, cMulBySearchText, 1000, NULL, NULL);

	std::string rtnStrng = cMulBySearchText;

	return rtnStrng;

}

void OutputQueryResultsToListView(HWND hListView, CRequestDB *myRequest)
{
	if(myRequest-&gt;GetStatSearchSuccess())
	{
		ListView_DeleteAllItems(hListView);

		while(myRequest-&gt;rowContent = mysql_fetch_row(myRequest-&gt;result))
		{
			std::string id   = myRequest-&gt;rowContent[0];
			std::string text = myRequest-&gt;rowContent[1];

			TCHAR idTC[10];
			TCHAR textTC[100];

			MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, id.c_str(), 10, idTC, 10);
			MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, text.c_str(), 100, textTC, 100);

			Create2ColItem(hListView, idTC, textTC);
		}
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1422168</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1422168</guid><dc:creator><![CDATA[winzenden]]></dc:creator><pubDate>Mon, 17 Dec 2007 17:28:14 GMT</pubDate></item><item><title><![CDATA[Reply to Childwindow mit CreateWindow klappt net on Mon, 17 Dec 2007 19:54:12 GMT]]></title><description><![CDATA[<p>Wenn AddWnd ein eigenständiges Popup Window werdne soll, dann darf es den Stil WS_CHILD nicht haben.</p>
<p>Soll das ein modaler Dialog werden? Dann solltest Du auch DialogBox verwenden.</p>
<p>BTW:<br />
1. InitCommonControlsEx gehört nach InitInstance oder nitApplication und Du solltest gewahr sein, dass diese Funktion evtl. fehlschlägt. In diesem Fall solltest DU das Programm sofort verlassen.<br />
2. Du hast keinerlei Fehlerhandling in Deinem Programm. Das Anlegen eines Fensters kann fehlgehen.<br />
3. Es ist wohl absoluter Blödsinn bei jeder WM_SIZE Meldung zwei neue Spalten in die Listbox hinzuzufügen. Der Code gehört nach WM_CREATE.<br />
4. Dein WM_NOTIFY Code hat kein break. Der Prorammfluß läuft sofort in den nächsten Bock weiter (WM_COMMAND).<br />
5. Du solltest die Variablen, die Du benutzt näher an den Blöcken definieren in denen Sie benutzt werden. Die Paintstruct z.B. kannst Du auch im case-Block für WM_PAINT nutzen.<br />
6. WM_COMMAND muss nicht DefWindowProc ausführen, wenn kein Commandcode zutrifft.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1422259</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1422259</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Mon, 17 Dec 2007 19:54:12 GMT</pubDate></item></channel></rss>