<?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[Subclassing Controls]]></title><description><![CDATA[<p>Moin,</p>
<p>ich habe mir eine GUI zusammengebastelt (Anfänger) und benutze Static-Controls mit Bimaps als Button.</p>
<p>Diese Steuerelemente habe ich nun &quot;gesubclassed&quot;, damit sie wie Buttons reagieren.</p>
<p>Funktionieren tut es soweit, jedoch bin ich mir nicht sicher, ob das so alles seine Richtigkeit hat.</p>
<p>Deshalb meine Frage/Bitte an euch:</p>
<p>Ist das so OK mit dem Subclassing, oder sollte ich das ganze lieber anders machen ... ?</p>
<p>Ich bin über die globalen Variablen der Fenster nicht so ganz glücklich, oder ist das schon i.O. so ...<br />
Außerdem wird immer wieder das Bitmap an das Static-Control gesendet wenn die Maus über den Button fährt, das geht doch bestimmt auch anders, oder ?</p>
<p>Wäre für ein paar Tips und Ratschläge sehr dankbar. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_savoring_food"
      title=":yum:"
      alt="😋"
    /></p>
<pre><code>#include &lt;windows.h&gt;
//#include &lt;commctrl.h&gt;

//#pragma comment(lib, &quot;comctl32.lib&quot;)

#define IDS_CLOSE      1
#define IDS_MINIMIZE   2
#define IDB_START      3
#define IDB_EXIT       4
#define IDB_SELDIR     5

#define IDE_NAME       7
#define IDE_DIR        8

LRESULT CALLBACK WindowProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ButtonProc(HWND, UINT, WPARAM, LPARAM);

void CreateControls(HWND, HINSTANCE);

TCHAR szClassName[] = TEXT(&quot;MyClass&quot;) ;
HINSTANCE hInstance = GetModuleHandle(NULL);
WNDPROC STATIC_PROC[5];
HBITMAP hBitmap[14];

HWND hWnd ;
HWND hBoxClose;
HWND hBoxMinimize;
HWND hBtnStart;
HWND hBtnExit;
HWND hBtnSelDir;

HWND hEdtDateiname;
HWND hEdtDlDir;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow)
{
    MSG         nMsg ;
    WNDCLASSEX  WndClass ;

    WndClass.style         = CS_HREDRAW | CS_VREDRAW | 0x00020000 ;
    WndClass.hInstance     = hInstance ;
    WndClass.lpfnWndProc   = WindowProc ;
    WndClass.cbSize        = sizeof (WNDCLASSEX) ;
    WndClass.cbClsExtra    = 0 ;
    WndClass.cbWndExtra    = 0 ;
    WndClass.hIcon         = LoadIcon   (NULL, IDI_APPLICATION) ;
    WndClass.hIconSm       = LoadIcon   (NULL, IDI_APPLICATION) ;
    WndClass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
    WndClass.lpszMenuName  = NULL ;
    WndClass.hbrBackground = (HBRUSH) CreatePatternBrush((HBITMAP)LoadImage(NULL, TEXT(&quot;backpic.bmp&quot;),
																			IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)) ;
    WndClass.lpszClassName = szClassName ;

    if (!RegisterClassEx (&amp;WndClass))
        return 0 ;

    //InitCommonControls();

    hWnd = CreateWindow(szClassName, TEXT(&quot;CS Kino&quot;),
                        //WS_OVERLAPPEDWINDOW,
                        WS_POPUP,
                        400, 200, 635, 476,
                        NULL, NULL,
                        hInstance, NULL);

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

    while (GetMessage (&amp;nMsg, NULL, 0, 0))
    {
        TranslateMessage(&amp;nMsg);
        DispatchMessage(&amp;nMsg);
    }

    return nMsg.wParam;
}

LRESULT CALLBACK WindowProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HDC hDC ;
    HRGN hRgn;
    PAINTSTRUCT ps;

    switch (message)
    {
        case WM_CREATE :

            // Steuerelemente erstellen
            CreateControls(hWnd, hInstance);
            // Fensterecken abrunden
            hRgn = CreateRoundRectRgn(0, 0, 635, 476, 6, 6);
            SetWindowRgn(hWnd, hRgn, TRUE);
            return 0 ;

        case WM_PAINT :

            hDC = BeginPaint(hWnd, &amp;ps);

            EndPaint(hWnd, &amp;ps);
            return 0 ;

        case WM_NOTIFY :

            return 0;

        case WM_COMMAND :

            switch (wParam)
            {
                case IDB_EXIT :

                    DestroyWindow(hWnd);
                    break;

                case IDS_CLOSE :

                    DestroyWindow(hWnd);
                    break;

                case IDS_MINIMIZE :

                    ShowWindow(hWnd, SW_MINIMIZE);
                    break;
            }
            return 0;

        case WM_LBUTTONDOWN :

            // Fenster-Drag
            SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, (LPARAM)NULL) ;
            return 0 ;

        case WM_DESTROY :

            // Aufräumen ...
            for (int i = 0; i != 10; i++)
            {
                DeleteObject(hBitmap[i]);
            }
            PostQuitMessage (0);
            return 0 ;
    }

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

void CreateControls(HWND hWnd, HINSTANCE hInstance)
{
    char Bitmaps[14][20] = {TEXT(&quot;close0.bmp&quot;),   TEXT(&quot;close1.bmp&quot;), TEXT(&quot;close2.bmp&quot;),
                            TEXT(&quot;min0.bmp&quot;),     TEXT(&quot;min1.bmp&quot;),   TEXT(&quot;min2.bmp&quot;),
                            TEXT(&quot;BtnStrtD.bmp&quot;), TEXT(&quot;BtnStrtH.bmp&quot;),
                            TEXT(&quot;BtnStpD.bmp&quot;),  TEXT(&quot;BtnStpH.bmp&quot;),
                            TEXT(&quot;BtnCnclD.bmp&quot;), TEXT(&quot;BtnCnclH.bmp&quot;),
                            TEXT(&quot;BtnFoldD.bmp&quot;), TEXT(&quot;BtnFoldH.bmp&quot;)};
    // Bitmaps laden
    for (int i = 0; i != 14; i++)
    {
        hBitmap[i] = (HBITMAP)LoadImage(NULL, Bitmaps[i], IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    }
    /////////////////////////////
    // Steuerelemente erstellen
    /////////////////////////////

    // Buttons
    hBoxClose    = CreateWindow(TEXT(&quot;STATIC&quot;), TEXT(&quot;&quot;),
                                WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
                                SS_BITMAP | SS_CENTERIMAGE | SS_NOTIFY,
                                585, 0, 43, 17, hWnd, (HMENU) IDS_CLOSE, hInstance, NULL);

    hBoxMinimize = CreateWindow(TEXT(&quot;STATIC&quot;), TEXT(&quot;&quot;),
                                WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
                                SS_BITMAP | SS_CENTERIMAGE | SS_NOTIFY,
                                559, 0, 26, 17, hWnd, (HMENU) IDS_MINIMIZE, hInstance, NULL);

    hBtnStart    = CreateWindow(TEXT(&quot;STATIC&quot;), TEXT(&quot;&quot;),
                                WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
                                SS_BITMAP | SS_CENTERIMAGE | SS_NOTIFY,
                                520, 350, 80, 27, hWnd, (HMENU) IDB_START, hInstance, NULL);

    hBtnExit     = CreateWindow(TEXT(&quot;STATIC&quot;), TEXT(&quot;&quot;),
                                WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
                                SS_BITMAP | SS_CENTERIMAGE | SS_NOTIFY,
                                520, 390, 80, 27, hWnd, (HMENU) IDB_EXIT, hInstance, NULL);

    hBtnSelDir   = CreateWindow(TEXT(&quot;STATIC&quot;), TEXT(&quot;&quot;),
                                WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
                                SS_BITMAP | SS_CENTERIMAGE | SS_NOTIFY,
                                230, 365, 40, 27, hWnd, (HMENU) IDB_SELDIR, hInstance, NULL);

    // Edit Controls
    hEdtDateiname    = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT(&quot;EDIT&quot;), TEXT(&quot;&quot;),
									  WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
									  ES_LEFT,
									  25, 320, 150, 20, hWnd, (HMENU) IDE_NAME, hInstance, NULL);

    hEdtDlDir        = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT(&quot;EDIT&quot;), TEXT(&quot;&quot;),
									  WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
									  ES_LEFT,
									  25, 368, 200, 20, hWnd, (HMENU) IDE_DIR, hInstance, NULL);

    // Bitmaps setzen
    SendMessage(hBoxClose, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[0]);
    SendMessage(hBoxMinimize, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[3]);

    SendMessage(hBtnStart, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[6]);
    SendMessage(hBtnExit, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[8]);
    SendMessage(hBtnSelDir, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[12]);

    // Subclassing der Steuerelemente
    STATIC_PROC[0] = (WNDPROC)SetWindowLong(hBoxClose, GWLP_WNDPROC, (long)ButtonProc);
    STATIC_PROC[1] = (WNDPROC)SetWindowLong(hBoxMinimize, GWLP_WNDPROC, (long)ButtonProc);
    STATIC_PROC[2] = (WNDPROC)SetWindowLong(hBtnStart, GWLP_WNDPROC, (long)ButtonProc);
    STATIC_PROC[3] = (WNDPROC)SetWindowLong(hBtnExit, GWLP_WNDPROC, (long)ButtonProc);
    STATIC_PROC[4] = (WNDPROC)SetWindowLong(hBtnSelDir, GWLP_WNDPROC, (long)ButtonProc);

}

LRESULT CALLBACK ButtonProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{

    switch(message)
    {

        case WM_MOUSEHOVER:

            if (hDlg == hBoxClose)
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[1]);
            else if (hDlg == hBoxMinimize)
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[4]);
            else if (hDlg == hBtnStart)
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[7]);
            else if (hDlg == hBtnExit)
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[9]);
            else if (hDlg == hBtnSelDir)
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[13]);
            break;

        case WM_MOUSELEAVE:

            if (hDlg == hBoxClose)
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[0]);
            else if (hDlg == hBoxMinimize)
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[3]);
            else if (hDlg == hBtnStart)
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[6]);
            else if (hDlg == hBtnExit)
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[8]);
            else if (hDlg == hBtnSelDir)
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[12]);
            break;

        case WM_LBUTTONUP:

            if (hDlg == hBtnStart)
                SetWindowPos(hDlg, HWND_TOP, 520, 350, 80, 27, SWP_SHOWWINDOW);
            else if (hDlg == hBtnExit)
            {
                SetWindowPos(hDlg, HWND_TOP, 520, 390, 80, 27, SWP_SHOWWINDOW);
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[9]);
                Sleep(100);
                SendMessage(GetParent(hDlg), WM_DESTROY, 0, 0);
            }
            else if (hDlg == hBtnSelDir)
                SetWindowPos(hDlg, HWND_TOP, 230, 365, 40, 27, SWP_SHOWWINDOW);
            break;

        case WM_LBUTTONDOWN:

            if (hDlg == hBoxClose)
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[2]);
            else if (hDlg == hBoxMinimize)
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[5]);
            else if (hDlg == hBtnStart)
                SetWindowPos(hDlg, HWND_TOP, 521, 351, 78, 25, SWP_SHOWWINDOW);
            else if (hDlg == hBtnExit)
                SetWindowPos(hDlg, HWND_TOP, 521, 391, 78, 25, SWP_SHOWWINDOW);
            else if (hDlg == hBtnSelDir)
                SetWindowPos(hDlg, HWND_TOP, 231, 366, 40, 27, SWP_SHOWWINDOW);

            Sleep(100);
            break;

        case WM_MOUSEMOVE:

            TRACKMOUSEEVENT tme;
            tme.cbSize      = sizeof(TRACKMOUSEEVENT);
            tme.dwFlags     = TME_HOVER|TME_LEAVE; // TME_LEAVE 'or'ed
            tme.dwHoverTime = 10; //HOVER_DEFAULT;
            tme.hwndTrack   = hDlg;
            TrackMouseEvent(&amp;tme);
            break;

        case WM_DESTROY:

            PostQuitMessage(0);
            break;

        break;
    }
    if (hDlg == hBoxClose)
        return CallWindowProc(STATIC_PROC[0], hDlg, message, wParam, lParam);
    else if (hDlg == hBoxMinimize)
        return CallWindowProc(STATIC_PROC[1], hDlg, message, wParam, lParam);
    else if (hDlg == hBtnStart)
        return CallWindowProc(STATIC_PROC[2], hDlg, message, wParam, lParam);
    else if (hDlg == hBtnExit)
        return CallWindowProc(STATIC_PROC[3], hDlg, message, wParam, lParam);
    else if (hDlg == hBtnSelDir)
        return CallWindowProc(STATIC_PROC[4], hDlg, message, wParam, lParam);

    return CallWindowProc(STATIC_PROC[0], hDlg, message, wParam, lParam);

}
</code></pre>
<p>Ich hoffe es ist nicht zu unübersichtlich ... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<p>Gruß<br />
Greenhorn</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/215781/subclassing-controls</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Apr 2026 19:33:30 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/215781.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 15 Jun 2008 14:27:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Subclassing Controls on Sun, 15 Jun 2008 14:31:13 GMT]]></title><description><![CDATA[<p>Moin,</p>
<p>ich habe mir eine GUI zusammengebastelt (Anfänger) und benutze Static-Controls mit Bimaps als Button.</p>
<p>Diese Steuerelemente habe ich nun &quot;gesubclassed&quot;, damit sie wie Buttons reagieren.</p>
<p>Funktionieren tut es soweit, jedoch bin ich mir nicht sicher, ob das so alles seine Richtigkeit hat.</p>
<p>Deshalb meine Frage/Bitte an euch:</p>
<p>Ist das so OK mit dem Subclassing, oder sollte ich das ganze lieber anders machen ... ?</p>
<p>Ich bin über die globalen Variablen der Fenster nicht so ganz glücklich, oder ist das schon i.O. so ...<br />
Außerdem wird immer wieder das Bitmap an das Static-Control gesendet wenn die Maus über den Button fährt, das geht doch bestimmt auch anders, oder ?</p>
<p>Wäre für ein paar Tips und Ratschläge sehr dankbar. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_savoring_food"
      title=":yum:"
      alt="😋"
    /></p>
<pre><code>#include &lt;windows.h&gt;
//#include &lt;commctrl.h&gt;

//#pragma comment(lib, &quot;comctl32.lib&quot;)

#define IDS_CLOSE      1
#define IDS_MINIMIZE   2
#define IDB_START      3
#define IDB_EXIT       4
#define IDB_SELDIR     5

#define IDE_NAME       7
#define IDE_DIR        8

LRESULT CALLBACK WindowProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ButtonProc(HWND, UINT, WPARAM, LPARAM);

void CreateControls(HWND, HINSTANCE);

TCHAR szClassName[] = TEXT(&quot;MyClass&quot;) ;
HINSTANCE hInstance = GetModuleHandle(NULL);
WNDPROC STATIC_PROC[5];
HBITMAP hBitmap[14];

HWND hWnd ;
HWND hBoxClose;
HWND hBoxMinimize;
HWND hBtnStart;
HWND hBtnExit;
HWND hBtnSelDir;

HWND hEdtDateiname;
HWND hEdtDlDir;

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow)
{
    MSG         nMsg ;
    WNDCLASSEX  WndClass ;

    WndClass.style         = CS_HREDRAW | CS_VREDRAW | 0x00020000 ;
    WndClass.hInstance     = hInstance ;
    WndClass.lpfnWndProc   = WindowProc ;
    WndClass.cbSize        = sizeof (WNDCLASSEX) ;
    WndClass.cbClsExtra    = 0 ;
    WndClass.cbWndExtra    = 0 ;
    WndClass.hIcon         = LoadIcon   (NULL, IDI_APPLICATION) ;
    WndClass.hIconSm       = LoadIcon   (NULL, IDI_APPLICATION) ;
    WndClass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
    WndClass.lpszMenuName  = NULL ;
    WndClass.hbrBackground = (HBRUSH) CreatePatternBrush((HBITMAP)LoadImage(NULL, TEXT(&quot;backpic.bmp&quot;),
																			IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)) ;
    WndClass.lpszClassName = szClassName ;

    if (!RegisterClassEx (&amp;WndClass))
        return 0 ;

    //InitCommonControls();

    hWnd = CreateWindow(szClassName, TEXT(&quot;CS Kino&quot;),
                        //WS_OVERLAPPEDWINDOW,
                        WS_POPUP,
                        400, 200, 635, 476,
                        NULL, NULL,
                        hInstance, NULL);

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

    while (GetMessage (&amp;nMsg, NULL, 0, 0))
    {
        TranslateMessage(&amp;nMsg);
        DispatchMessage(&amp;nMsg);
    }

    return nMsg.wParam;
}

LRESULT CALLBACK WindowProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HDC hDC ;
    HRGN hRgn;
    PAINTSTRUCT ps;

    switch (message)
    {
        case WM_CREATE :

            // Steuerelemente erstellen
            CreateControls(hWnd, hInstance);
            // Fensterecken abrunden
            hRgn = CreateRoundRectRgn(0, 0, 635, 476, 6, 6);
            SetWindowRgn(hWnd, hRgn, TRUE);
            return 0 ;

        case WM_PAINT :

            hDC = BeginPaint(hWnd, &amp;ps);

            EndPaint(hWnd, &amp;ps);
            return 0 ;

        case WM_NOTIFY :

            return 0;

        case WM_COMMAND :

            switch (wParam)
            {
                case IDB_EXIT :

                    DestroyWindow(hWnd);
                    break;

                case IDS_CLOSE :

                    DestroyWindow(hWnd);
                    break;

                case IDS_MINIMIZE :

                    ShowWindow(hWnd, SW_MINIMIZE);
                    break;
            }
            return 0;

        case WM_LBUTTONDOWN :

            // Fenster-Drag
            SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, (LPARAM)NULL) ;
            return 0 ;

        case WM_DESTROY :

            // Aufräumen ...
            for (int i = 0; i != 10; i++)
            {
                DeleteObject(hBitmap[i]);
            }
            PostQuitMessage (0);
            return 0 ;
    }

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

void CreateControls(HWND hWnd, HINSTANCE hInstance)
{
    char Bitmaps[14][20] = {TEXT(&quot;close0.bmp&quot;),   TEXT(&quot;close1.bmp&quot;), TEXT(&quot;close2.bmp&quot;),
                            TEXT(&quot;min0.bmp&quot;),     TEXT(&quot;min1.bmp&quot;),   TEXT(&quot;min2.bmp&quot;),
                            TEXT(&quot;BtnStrtD.bmp&quot;), TEXT(&quot;BtnStrtH.bmp&quot;),
                            TEXT(&quot;BtnStpD.bmp&quot;),  TEXT(&quot;BtnStpH.bmp&quot;),
                            TEXT(&quot;BtnCnclD.bmp&quot;), TEXT(&quot;BtnCnclH.bmp&quot;),
                            TEXT(&quot;BtnFoldD.bmp&quot;), TEXT(&quot;BtnFoldH.bmp&quot;)};
    // Bitmaps laden
    for (int i = 0; i != 14; i++)
    {
        hBitmap[i] = (HBITMAP)LoadImage(NULL, Bitmaps[i], IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    }
    /////////////////////////////
    // Steuerelemente erstellen
    /////////////////////////////

    // Buttons
    hBoxClose    = CreateWindow(TEXT(&quot;STATIC&quot;), TEXT(&quot;&quot;),
                                WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
                                SS_BITMAP | SS_CENTERIMAGE | SS_NOTIFY,
                                585, 0, 43, 17, hWnd, (HMENU) IDS_CLOSE, hInstance, NULL);

    hBoxMinimize = CreateWindow(TEXT(&quot;STATIC&quot;), TEXT(&quot;&quot;),
                                WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
                                SS_BITMAP | SS_CENTERIMAGE | SS_NOTIFY,
                                559, 0, 26, 17, hWnd, (HMENU) IDS_MINIMIZE, hInstance, NULL);

    hBtnStart    = CreateWindow(TEXT(&quot;STATIC&quot;), TEXT(&quot;&quot;),
                                WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
                                SS_BITMAP | SS_CENTERIMAGE | SS_NOTIFY,
                                520, 350, 80, 27, hWnd, (HMENU) IDB_START, hInstance, NULL);

    hBtnExit     = CreateWindow(TEXT(&quot;STATIC&quot;), TEXT(&quot;&quot;),
                                WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
                                SS_BITMAP | SS_CENTERIMAGE | SS_NOTIFY,
                                520, 390, 80, 27, hWnd, (HMENU) IDB_EXIT, hInstance, NULL);

    hBtnSelDir   = CreateWindow(TEXT(&quot;STATIC&quot;), TEXT(&quot;&quot;),
                                WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
                                SS_BITMAP | SS_CENTERIMAGE | SS_NOTIFY,
                                230, 365, 40, 27, hWnd, (HMENU) IDB_SELDIR, hInstance, NULL);

    // Edit Controls
    hEdtDateiname    = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT(&quot;EDIT&quot;), TEXT(&quot;&quot;),
									  WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
									  ES_LEFT,
									  25, 320, 150, 20, hWnd, (HMENU) IDE_NAME, hInstance, NULL);

    hEdtDlDir        = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT(&quot;EDIT&quot;), TEXT(&quot;&quot;),
									  WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
									  ES_LEFT,
									  25, 368, 200, 20, hWnd, (HMENU) IDE_DIR, hInstance, NULL);

    // Bitmaps setzen
    SendMessage(hBoxClose, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[0]);
    SendMessage(hBoxMinimize, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[3]);

    SendMessage(hBtnStart, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[6]);
    SendMessage(hBtnExit, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[8]);
    SendMessage(hBtnSelDir, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[12]);

    // Subclassing der Steuerelemente
    STATIC_PROC[0] = (WNDPROC)SetWindowLong(hBoxClose, GWLP_WNDPROC, (long)ButtonProc);
    STATIC_PROC[1] = (WNDPROC)SetWindowLong(hBoxMinimize, GWLP_WNDPROC, (long)ButtonProc);
    STATIC_PROC[2] = (WNDPROC)SetWindowLong(hBtnStart, GWLP_WNDPROC, (long)ButtonProc);
    STATIC_PROC[3] = (WNDPROC)SetWindowLong(hBtnExit, GWLP_WNDPROC, (long)ButtonProc);
    STATIC_PROC[4] = (WNDPROC)SetWindowLong(hBtnSelDir, GWLP_WNDPROC, (long)ButtonProc);

}

LRESULT CALLBACK ButtonProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{

    switch(message)
    {

        case WM_MOUSEHOVER:

            if (hDlg == hBoxClose)
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[1]);
            else if (hDlg == hBoxMinimize)
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[4]);
            else if (hDlg == hBtnStart)
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[7]);
            else if (hDlg == hBtnExit)
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[9]);
            else if (hDlg == hBtnSelDir)
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[13]);
            break;

        case WM_MOUSELEAVE:

            if (hDlg == hBoxClose)
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[0]);
            else if (hDlg == hBoxMinimize)
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[3]);
            else if (hDlg == hBtnStart)
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[6]);
            else if (hDlg == hBtnExit)
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[8]);
            else if (hDlg == hBtnSelDir)
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[12]);
            break;

        case WM_LBUTTONUP:

            if (hDlg == hBtnStart)
                SetWindowPos(hDlg, HWND_TOP, 520, 350, 80, 27, SWP_SHOWWINDOW);
            else if (hDlg == hBtnExit)
            {
                SetWindowPos(hDlg, HWND_TOP, 520, 390, 80, 27, SWP_SHOWWINDOW);
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[9]);
                Sleep(100);
                SendMessage(GetParent(hDlg), WM_DESTROY, 0, 0);
            }
            else if (hDlg == hBtnSelDir)
                SetWindowPos(hDlg, HWND_TOP, 230, 365, 40, 27, SWP_SHOWWINDOW);
            break;

        case WM_LBUTTONDOWN:

            if (hDlg == hBoxClose)
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[2]);
            else if (hDlg == hBoxMinimize)
                SendMessage(hDlg, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap[5]);
            else if (hDlg == hBtnStart)
                SetWindowPos(hDlg, HWND_TOP, 521, 351, 78, 25, SWP_SHOWWINDOW);
            else if (hDlg == hBtnExit)
                SetWindowPos(hDlg, HWND_TOP, 521, 391, 78, 25, SWP_SHOWWINDOW);
            else if (hDlg == hBtnSelDir)
                SetWindowPos(hDlg, HWND_TOP, 231, 366, 40, 27, SWP_SHOWWINDOW);

            Sleep(100);
            break;

        case WM_MOUSEMOVE:

            TRACKMOUSEEVENT tme;
            tme.cbSize      = sizeof(TRACKMOUSEEVENT);
            tme.dwFlags     = TME_HOVER|TME_LEAVE; // TME_LEAVE 'or'ed
            tme.dwHoverTime = 10; //HOVER_DEFAULT;
            tme.hwndTrack   = hDlg;
            TrackMouseEvent(&amp;tme);
            break;

        case WM_DESTROY:

            PostQuitMessage(0);
            break;

        break;
    }
    if (hDlg == hBoxClose)
        return CallWindowProc(STATIC_PROC[0], hDlg, message, wParam, lParam);
    else if (hDlg == hBoxMinimize)
        return CallWindowProc(STATIC_PROC[1], hDlg, message, wParam, lParam);
    else if (hDlg == hBtnStart)
        return CallWindowProc(STATIC_PROC[2], hDlg, message, wParam, lParam);
    else if (hDlg == hBtnExit)
        return CallWindowProc(STATIC_PROC[3], hDlg, message, wParam, lParam);
    else if (hDlg == hBtnSelDir)
        return CallWindowProc(STATIC_PROC[4], hDlg, message, wParam, lParam);

    return CallWindowProc(STATIC_PROC[0], hDlg, message, wParam, lParam);

}
</code></pre>
<p>Ich hoffe es ist nicht zu unübersichtlich ... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<p>Gruß<br />
Greenhorn</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1529518</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1529518</guid><dc:creator><![CDATA[C++Greenhorn 0]]></dc:creator><pubDate>Sun, 15 Jun 2008 14:31:13 GMT</pubDate></item><item><title><![CDATA[Reply to Subclassing Controls on Sun, 15 Jun 2008 20:42:24 GMT]]></title><description><![CDATA[<p>Uff...das ist aber viel Code <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /> .</p>
<p>Also mal vorweg: Es macht glaube ich Sinn, die Bitmaps nur einmal zu laden und am Ende freizugeben, da man schon mal öfters mit der Maus drüber hüpft. Weiterhin kannst Du mittels SetWindowLongPtr und GWLP_USERDATA die globalen Variablen umgehen <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="😉"
    /> . Wenn Du C++ kannst, kannst Du Dir eigene Controls, basierend auf einer eigens definierten WndProc/Fensterklasse schreiben und diese in einer Klasse kapseln. Hab ich mal gemacht. Ist später wesentlich angenehmer bei der Verwendung, aber schon einiges an Arbeit, sieht dann z.B. so aus:</p>
<pre><code class="language-cpp">static CButtonControl cBtn;
// ...
cBtn.Create(...);
cBtn.SetBitmaps(...);
cBtn.SetRegion(...);
cBtn.EnableNotifyEx(...);
// ...
// Optional: cBtn.Destroy(); oder halt autom. via Destruktor.
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1529743</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1529743</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Sun, 15 Jun 2008 20:42:24 GMT</pubDate></item><item><title><![CDATA[Reply to Subclassing Controls on Mon, 16 Jun 2008 06:07:40 GMT]]></title><description><![CDATA[<p>Dieser Code ist unsinnig. Warum mappst Du alles auf eine WndProc?<br />
Versuche das verhalten so zu standartisieren, dass die WndProc nicht von den einzelnen Instanen abhängig wird.<br />
Dem Hinweis auf GWLP_USERDATA von Codefinder solltest Du nachgehen. Du könntest dort eine Struktur allokieen, in der Du sowohl die alte WndProc speicherst als auch die Bitmap...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1529873</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1529873</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Mon, 16 Jun 2008 06:07:40 GMT</pubDate></item><item><title><![CDATA[Reply to Subclassing Controls on Mon, 16 Jun 2008 13:52:18 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>vielen Dank für eure Antworten. <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>Also war mein Gefühl schon richtig, dass das nicht das Gelbe vom Ei ist ... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Wie gesagt, bin noch Anfänger in C++ und schmökere halt nebenbei noch den Petzold.<br />
Wahrscheinlich verlange ich mir wieder mal zuviel auf einmal ab ...</p>
<p>Also das mit der eingenen Fenster/Button Klasse habe ich mir auch schon überlegt, aber weiss nicht so recht wie ich da herangehen soll, also welche Strukturen brauche ich usw.<br />
Vor der Arbeit scheue ich mich nicht, daran soll's nicht liegen ...</p>
<p>Ansonsten werde ich mir mal das mit GWLP_USERDATA ansehen und nach Beispielen suchen.<br />
Habe bei M$ auch gesehen, dass man für's Subclassing lieber SetWindowSubclass benutzen soll.<br />
Hmmm ...</p>
<p>Gruß<br />
Greenhorn</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1530152</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1530152</guid><dc:creator><![CDATA[C++Greenhorn 0]]></dc:creator><pubDate>Mon, 16 Jun 2008 13:52:18 GMT</pubDate></item><item><title><![CDATA[Reply to Subclassing Controls on Mon, 16 Jun 2008 14:41:51 GMT]]></title><description><![CDATA[<p>Benutze keine Static-Controls, sondern erstelle Buttons (Klasse &quot;Button&quot;) und zeichne sie selbst mit Ownerdrawing.<br />
Da musst du weder Subclassing betreiben und kannst das Zeichnen auch auf Funktionen auslagern, die du in WM_DRAWITEM aufrufst.</p>
<p>Grüße, Xantus</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1530195</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1530195</guid><dc:creator><![CDATA[Xantus]]></dc:creator><pubDate>Mon, 16 Jun 2008 14:41:51 GMT</pubDate></item><item><title><![CDATA[Reply to Subclassing Controls on Mon, 16 Jun 2008 15:29:51 GMT]]></title><description><![CDATA[<p>Danke Xantus, das ist auch eine Alternative, werd's probieren <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="🙂"
    /> (... oder probiert es mich ???)</p>
<p>Gruß<br />
Greenhorn</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1530219</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1530219</guid><dc:creator><![CDATA[C++Greenhorn 0]]></dc:creator><pubDate>Mon, 16 Jun 2008 15:29:51 GMT</pubDate></item></channel></rss>