<?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[Dialog erscheint nicht wie gewünscht]]></title><description><![CDATA[<p>Hallo Community,</p>
<p>ich habe mich seit kurzen an die WinAPI-Programmierung gewagt.<br />
Nun habe ich beim lesen des forger-win32-Tutorial ein Problem<br />
mit den Dialogen. Das im Tutorial gezeigte Dialog erscheint bei<br />
mir NICHT gleich. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /> <a href="http://mat.tac-design.net/pic/gfx/dialog.png" rel="nofollow">http://mat.tac-design.net/pic/gfx/dialog.png</a><br />
Ich bin ratlos, denn selbst bei absolut exaktem Code erscheint das<br />
Fenster anders. Ich hoffe ihr könnt mir helfen. <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>Ich arbeite mit:<br />
-Win2K<br />
-DevCPP 4.9.8.10 mit MingW-Compiler</p>
<p>Ich poste hier den gesamten Quellcode, da ich absolut keine Ahnung<br />
habe, wo der Fehler sich eingeschlichen haben könnte. Es betrifft den<br />
Aufruf des About-Fensters.</p>
<p><strong>WinMain.cpp</strong></p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &quot;resource.h&quot;

const char g_szClassName[] = &quot;MyWindowClass&quot;;

//Procedure for the About-Dialog
BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
    switch(Message)
    {
        case WM_INITDIALOG:

        return TRUE;
        case WM_COMMAND:
            switch(LOWORD(wParam))[url]
            {
                case IDOK:
                    EndDialog(hwnd, IDOK);
                break;
                case IDCANCEL:
                    EndDialog(hwnd, IDCANCEL);
                break;
            }
        break;
        default:
            return TRUE;
    }
    return TRUE;
}

//The message procedure has to be before WINMAIN!!
//These lines cannot be include!!
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
    case WM_COMMAND:
        switch(LOWORD(wParam))
        {
            case ID_\1:
                {
                 DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);
                }
        }
        break;        
    case WM_LBUTTONDOWN:
        {
                char szFileName[MAX_PATH];
                HINSTANCE hInstance = GetModuleHandle(NULL);
                GetModuleFileName(hInstance, szFileName, MAX_PATH);
                MessageBox(hwnd, szFileName, &quot;This program is:&quot;, MB_OK | MB_ICONINFORMATION);
        }            
        break;    
    case WM_CLOSE:
        DestroyWindow(hwnd);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
    }

    return 0;
}

//*****************************************************************************
//********************************WINMAIN!!************************************
//*****************************************************************************
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;

    //Step 1: Registering the Window Class
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = 0;    //Can usually be set on 0
    wc.lpfnWndProc = WndProc;    //Pointer to the procedur for this window class
    wc.cbClsExtra = 0;    //Usually 0
    wc.cbWndExtra = 0;    //Usually 0
    wc.hInstance = hInstance;    //Handle to the application instance
    wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));    //Large 32x32 Icon
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);    //Cursor displayed over the Window
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);    //Background set to the Window
    wc.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU);    //Name of a menu resource to use for the windows with this class.
    wc.lpszClassName = g_szClassName;    //Name to identify the class with.
    wc.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0);    //Small (usually 16x16) icon to show in the taskbar and in the top left corner of the window.

    RegisterClassEx(&amp;wc);

    // Step 2: Creating the Window
    hwnd = CreateWindowEx(
    WS_EX_APPWINDOW,
    g_szClassName,
    &quot;WinAPI&quot;,
    WS_OVERLAPPEDWINDOW,
    200,    //X-coordinates for the left upper corner of the Window
    80,    //Y-coordinates for the left upper corner of the Window
    500,    //Window size in Pixels, X-coordinate
    380,    //Window size in Pixels, Y-coordinate
    NULL,
    NULL,
    hInstance,
    NULL);

    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    //**************************************************************************
    //************************Here comes the individual code********************
    //**************************************************************************
    //This code will be executed on the startup of the program
    //********************************************************

    //MessageBox (NULL, &quot;Hallo&quot;, &quot;Caption&quot;, MB_OK);

    //End of the startup executed code
    //********************************

    // Step 3: The Message Loop
    while(GetMessage(&amp;Msg, NULL, 0, 0) &gt; 0)
    {
        TranslateMessage(&amp;Msg);
        DispatchMessage(&amp;Msg);
    }
    return Msg.wParam;

}
</code></pre>
<p><strong>resource.h</strong></p>
<pre><code class="language-cpp">#define IDR_MYMENU 101
#define IDI_MYICON 201

#define ID_FILE_EXIT 9001
#define ID_ABOUT 9002

#define IDD_ABOUT 9101
#define IDC_STATIC 9109
</code></pre>
<p><strong>resource.rc</strong></p>
<pre><code>IDR_MYMENU MENU
BEGIN
    POPUP &quot;&amp;File&quot;
    BEGIN
        MENUITEM &quot;E&amp;xit&quot;, ID_FILE_EXIT
    END

    POPUP &quot;&amp;?&quot;
    BEGIN
        MENUITEM &quot;&amp;About...&quot;, ID_ABOUT
    END
END

//ICON FOR APP
IDI_MYICON ICON &quot;WinAPI.ico&quot;

//**************
//*ABOUT DIALOG*
//**************
IDD_ABOUT DIALOG DISCARDABLE 50, 50, 239, 66
STYLE DS_MODALFRAME | WS_CAPTION | WS_SYSMENU
CAPTION &quot;About this Program...&quot;
FONT 8, &quot;MS Sans Serif&quot;
BEGIN
    DEFPUSHBUTTON &quot;&amp;OK&quot;,IDOK,174,18,50,14
    PUSHBUTTON &quot;&amp;Cancel&quot;,IDCANCEL,174,35,50,14
    GROUPBOX &quot;About this program...&quot;,IDC_STATIC,7,7,225,52
    CTEXT &quot;An example of WINAPI-Dialogs.Coded by Mat&quot;,IDC_STATIC,16,18,144,33
END
</code></pre>
<p>Und sobald, dass ich mit geöffnetem Dialogfenster einem anderen Programm<br />
den Fokus gebe, ist das Programm nur noch per Taskmanager beendbar. Der<br />
Dialog zeigt mir den Ausschnit des vorangehenden Fenster an.<br />
<a href="http://mat.tac-design.net/pic/gfx/dialog2.png" rel="nofollow">http://mat.tac-design.net/pic/gfx/dialog2.png</a></p>
<p>Ich hoffe ihr könnt mir helfen und ich danke Euch schon im Voraus<br />
für eure Hilfe! <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>Freundliche Grüsse</p>
<p>edit: sfds</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/104033/dialog-erscheint-nicht-wie-gewünscht</link><generator>RSS for Node</generator><lastBuildDate>Sat, 02 May 2026 00:24:56 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/104033.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 15 Mar 2005 18:04:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Dialog erscheint nicht wie gewünscht on Tue, 15 Mar 2005 19:19:04 GMT]]></title><description><![CDATA[<p>Hallo Community,</p>
<p>ich habe mich seit kurzen an die WinAPI-Programmierung gewagt.<br />
Nun habe ich beim lesen des forger-win32-Tutorial ein Problem<br />
mit den Dialogen. Das im Tutorial gezeigte Dialog erscheint bei<br />
mir NICHT gleich. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /> <a href="http://mat.tac-design.net/pic/gfx/dialog.png" rel="nofollow">http://mat.tac-design.net/pic/gfx/dialog.png</a><br />
Ich bin ratlos, denn selbst bei absolut exaktem Code erscheint das<br />
Fenster anders. Ich hoffe ihr könnt mir helfen. <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>Ich arbeite mit:<br />
-Win2K<br />
-DevCPP 4.9.8.10 mit MingW-Compiler</p>
<p>Ich poste hier den gesamten Quellcode, da ich absolut keine Ahnung<br />
habe, wo der Fehler sich eingeschlichen haben könnte. Es betrifft den<br />
Aufruf des About-Fensters.</p>
<p><strong>WinMain.cpp</strong></p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &quot;resource.h&quot;

const char g_szClassName[] = &quot;MyWindowClass&quot;;

//Procedure for the About-Dialog
BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
    switch(Message)
    {
        case WM_INITDIALOG:

        return TRUE;
        case WM_COMMAND:
            switch(LOWORD(wParam))[url]
            {
                case IDOK:
                    EndDialog(hwnd, IDOK);
                break;
                case IDCANCEL:
                    EndDialog(hwnd, IDCANCEL);
                break;
            }
        break;
        default:
            return TRUE;
    }
    return TRUE;
}

//The message procedure has to be before WINMAIN!!
//These lines cannot be include!!
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
    case WM_COMMAND:
        switch(LOWORD(wParam))
        {
            case ID_\1:
                {
                 DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);
                }
        }
        break;        
    case WM_LBUTTONDOWN:
        {
                char szFileName[MAX_PATH];
                HINSTANCE hInstance = GetModuleHandle(NULL);
                GetModuleFileName(hInstance, szFileName, MAX_PATH);
                MessageBox(hwnd, szFileName, &quot;This program is:&quot;, MB_OK | MB_ICONINFORMATION);
        }            
        break;    
    case WM_CLOSE:
        DestroyWindow(hwnd);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
    }

    return 0;
}

//*****************************************************************************
//********************************WINMAIN!!************************************
//*****************************************************************************
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;

    //Step 1: Registering the Window Class
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = 0;    //Can usually be set on 0
    wc.lpfnWndProc = WndProc;    //Pointer to the procedur for this window class
    wc.cbClsExtra = 0;    //Usually 0
    wc.cbWndExtra = 0;    //Usually 0
    wc.hInstance = hInstance;    //Handle to the application instance
    wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));    //Large 32x32 Icon
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);    //Cursor displayed over the Window
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);    //Background set to the Window
    wc.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU);    //Name of a menu resource to use for the windows with this class.
    wc.lpszClassName = g_szClassName;    //Name to identify the class with.
    wc.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0);    //Small (usually 16x16) icon to show in the taskbar and in the top left corner of the window.

    RegisterClassEx(&amp;wc);

    // Step 2: Creating the Window
    hwnd = CreateWindowEx(
    WS_EX_APPWINDOW,
    g_szClassName,
    &quot;WinAPI&quot;,
    WS_OVERLAPPEDWINDOW,
    200,    //X-coordinates for the left upper corner of the Window
    80,    //Y-coordinates for the left upper corner of the Window
    500,    //Window size in Pixels, X-coordinate
    380,    //Window size in Pixels, Y-coordinate
    NULL,
    NULL,
    hInstance,
    NULL);

    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    //**************************************************************************
    //************************Here comes the individual code********************
    //**************************************************************************
    //This code will be executed on the startup of the program
    //********************************************************

    //MessageBox (NULL, &quot;Hallo&quot;, &quot;Caption&quot;, MB_OK);

    //End of the startup executed code
    //********************************

    // Step 3: The Message Loop
    while(GetMessage(&amp;Msg, NULL, 0, 0) &gt; 0)
    {
        TranslateMessage(&amp;Msg);
        DispatchMessage(&amp;Msg);
    }
    return Msg.wParam;

}
</code></pre>
<p><strong>resource.h</strong></p>
<pre><code class="language-cpp">#define IDR_MYMENU 101
#define IDI_MYICON 201

#define ID_FILE_EXIT 9001
#define ID_ABOUT 9002

#define IDD_ABOUT 9101
#define IDC_STATIC 9109
</code></pre>
<p><strong>resource.rc</strong></p>
<pre><code>IDR_MYMENU MENU
BEGIN
    POPUP &quot;&amp;File&quot;
    BEGIN
        MENUITEM &quot;E&amp;xit&quot;, ID_FILE_EXIT
    END

    POPUP &quot;&amp;?&quot;
    BEGIN
        MENUITEM &quot;&amp;About...&quot;, ID_ABOUT
    END
END

//ICON FOR APP
IDI_MYICON ICON &quot;WinAPI.ico&quot;

//**************
//*ABOUT DIALOG*
//**************
IDD_ABOUT DIALOG DISCARDABLE 50, 50, 239, 66
STYLE DS_MODALFRAME | WS_CAPTION | WS_SYSMENU
CAPTION &quot;About this Program...&quot;
FONT 8, &quot;MS Sans Serif&quot;
BEGIN
    DEFPUSHBUTTON &quot;&amp;OK&quot;,IDOK,174,18,50,14
    PUSHBUTTON &quot;&amp;Cancel&quot;,IDCANCEL,174,35,50,14
    GROUPBOX &quot;About this program...&quot;,IDC_STATIC,7,7,225,52
    CTEXT &quot;An example of WINAPI-Dialogs.Coded by Mat&quot;,IDC_STATIC,16,18,144,33
END
</code></pre>
<p>Und sobald, dass ich mit geöffnetem Dialogfenster einem anderen Programm<br />
den Fokus gebe, ist das Programm nur noch per Taskmanager beendbar. Der<br />
Dialog zeigt mir den Ausschnit des vorangehenden Fenster an.<br />
<a href="http://mat.tac-design.net/pic/gfx/dialog2.png" rel="nofollow">http://mat.tac-design.net/pic/gfx/dialog2.png</a></p>
<p>Ich hoffe ihr könnt mir helfen und ich danke Euch schon im Voraus<br />
für eure Hilfe! <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>Freundliche Grüsse</p>
<p>edit: sfds</p>
]]></description><link>https://www.c-plusplus.net/forum/post/745293</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/745293</guid><dc:creator><![CDATA[Mat*Spidy]]></dc:creator><pubDate>Tue, 15 Mar 2005 19:19:04 GMT</pubDate></item><item><title><![CDATA[Reply to Dialog erscheint nicht wie gewünscht on Tue, 15 Mar 2005 19:32:50 GMT]]></title><description><![CDATA[<p>1. Grundregel bei der WndProc: Nachrichten, die du bearbeitest, solltest du in der Regel nicht an DefWindowProc weiterreichen. Also nicht break, sondern return verwenden.</p>
<p>WM_CLOSE musst du gar nicht behandeln, DefWindowProc ruft bei der Nachricht schon selbst DestroyWindow auf.</p>
<p>Schwerer ist aber ein anderer Fehler (der führt wohl zum beschriebenen Phänomen): deine AboutDlgProc gibt in jedem Fall TRUE zurück. Wenn eine Nachricht nicht bearbeitet wurde, sollte diese Funktion allerdings FALSE zurückgeben (s. SDK-Doku).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/745390</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/745390</guid><dc:creator><![CDATA[Christoph]]></dc:creator><pubDate>Tue, 15 Mar 2005 19:32:50 GMT</pubDate></item><item><title><![CDATA[Reply to Dialog erscheint nicht wie gewünscht on Wed, 16 Mar 2005 12:36:39 GMT]]></title><description><![CDATA[<p>Danke vielmals!<br />
Ich habe den Fehler korrigiert und jetzt funktioniert alles wie gewünscht.<br />
Die ersten zwei Erklärung habe ich zwar überhaupt nicht verstanden, aber<br />
ich denke nicht, dass das so wichtig ist, oder? <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>Der korrigierte Code:<br />
[cpp]<br />
//Procedure for the About-Dialog<br />
BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)<br />
{<br />
switch(Message)<br />
{<br />
case WM_INITDIALOG:</p>
<p>return TRUE;<br />
case WM_COMMAND:<br />
switch(LOWORD(wParam))<br />
{<br />
case IDOK:<br />
EndDialog(hwnd, IDOK);<br />
break;<br />
case IDCANCEL:<br />
EndDialog(hwnd, IDCANCEL);<br />
break;<br />
}<br />
break;<br />
default:<br />
return <em><strong>FALSE</strong></em>;<br />
}<br />
return TRUE;<br />
}<br />
[/cpp]</p>
<p>Danke nochmals! Hier wird man (endlich) kompetent geholfen! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/745901</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/745901</guid><dc:creator><![CDATA[Mat*Spidy]]></dc:creator><pubDate>Wed, 16 Mar 2005 12:36:39 GMT</pubDate></item></channel></rss>