[C++]Edit-Box wird nicht ausgelesen / Grafik wird nicht gezeichnet



  • Hm... es ist zwar vieleicht etwas viel verlangt, das ihr den Quelltext auf Fehler untersucht, aber ich bin föllig ratlos. Der Conpiler gibt keinen Fehler aus trotzdem funktionierts nicht. Gut, das allein ist keine Seltenheit. 😉
    Uch vermute mal, dass der Fehler irgentwo in der Message-Prozedur liegt, aber ich post mal lieber den ganzen Quelltext.

    #include <windows.h>
    
    #include "units.h"
    #include "spells.h"
    #include "buildings.h"
    
    LRESULT CALLBACK WinProc (HWND, UINT, WPARAM, LPARAM);
    LRESULT CALLBACK FoundProc (HWND, UINT, WPARAM, LPARAM);
    
    int DrawButtons(HWND hFound, char* pic_path, int x, int y);
    int DrawBackground(HWND hwnd);
    
    char szAppName[ ] = "PathFinder";
    char szFoundName[ ] = "Found...";
    
    int WINAPI WinMain (HINSTANCE hThisInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpszArgument,
                        int nFunsterStil)
    
    {
        HWND hwnd;             
        MSG messages;          
        WNDCLASSEX wincl;      
    
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szAppName;
        wincl.lpfnWndProc = WinProc;    
        wincl.style = CS_DBLCLKS;               
        wincl.cbSize = sizeof (WNDCLASSEX);
        wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
        wincl.lpszMenuName = NULL;        
        wincl.cbClsExtra = 0;          
        wincl.cbWndExtra = 0;
        wincl.hbrBackground = (HBRUSH) 19;
    
        if (!RegisterClassEx (&wincl))
            return 0;
    
        //Found-Window structs
        wincl.hbrBackground       = (HBRUSH) 19;
        wincl.hIcon               = NULL;
        wincl.lpfnWndProc         = FoundProc;
        wincl.lpszClassName       = szFoundName;
    
        if (!RegisterClassEx (&wincl))
            return 0;
    
        hwnd = CreateWindowEx (
               0,                 
               szAppName,     
               "PathFinder",      
               WS_OVERLAPPED | WS_SYSMENU, 
               380,      
               240,      
               450,                
               300,               
               HWND_DESKTOP,       
               NULL,               
               hThisInstance,     
               NULL                 
               );
    
        ShowWindow (hwnd, nFunsterStil); 
    
        while (GetMessage (&messages, NULL, 0, 0))
        {
            TranslateMessage(&messages);
            DispatchMessage(&messages);
        }
    
        return messages.wParam;
    }
    
    LRESULT CALLBACK WinProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        HWND hSearch;
        HWND hEnter;
        HWND hFound;
    
        switch (message)             
        {
            case WM_COMMAND:
            {
    
                if (lParam == (LPARAM)hEnter)
                {
    
                    if (HIWORD(wParam) == BN_CLICKED)
                    {
                        char* szSearch;
                        int Ergebniss = 0;
    
                        int iLength;
    
                        iLength = GetWindowTextLength(hSearch);
    
                        GetWindowText(hSearch, szSearch, iLength+1);
    
                        Ergebniss = unit_search(szSearch);
    
                        if(Ergebniss != 0)
                        {             
                             MessageBox (NULL, "Gefunden"  , "Info", MB_ICONINFORMATION);
                        }
                        else
                        {
                            MessageBox (NULL, "Nicht gefunden :-( "  , "Info", MB_ICONINFORMATION);
                        }        
                        free(szSearch);
                    }
                }        
                break;
            }
    
            case WM_CREATE:
            {
                DrawBackground(hwnd);
    
                //Create the Inputbox
                char* szSearch = NULL;
    
                hSearch = CreateWindowEx(WS_EX_CLIENTEDGE,
                                       "edit",
                                       szSearch,    // <- das ist der Inhalt der Editfelds
                                       WS_CHILD | WS_VISIBLE | ES_MULTILINE,
                                       35, 40, 120, 22,
                                       hwnd,
                                       NULL,
                                       ((LPCREATESTRUCT) lParam) -> hInstance,
                                       NULL);
                free(szSearch);
    
                //Create the Enter-Button                       
                hEnter = CreateWindow(  "button",
                                      "Search!",
                                      WS_CHILD | WS_VISIBLE,
                                      60, 80, 70, 22,
                                      hwnd,
                                      NULL,
                                      ((LPCREATESTRUCT) lParam) -> hInstance,
                                      NULL);
    
                //Create the Found-Window
                hFound = CreateWindow(  szFoundName,
                                     NULL,
                                     WS_CHILD | WS_VISIBLE | WS_DLGFRAME | WS_VSCROLL |
                                     ES_AUTOVSCROLL,
                                     200,
                                     5,
                                     230,
                                     248,
                                     hwnd,
                                     NULL,
                                     ((LPCREATESTRUCT) lParam)->hInstance,
                                     NULL);
    
                break;
            }
            case WM_SIZE:
            {
                DrawBackground(hwnd);
                break;
            }                
            case WM_DESTROY:
                PostQuitMessage (0);       
                break;
            default:                  
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
    
        return 0;
    }
    
    //Found-Window
    LRESULT CALLBACK FoundProc (HWND hFound, UINT message, WPARAM wParam, LPARAM lParam)
    {    
        switch (message)             
        {
            case WM_CREATE:
            {
                DrawButtons(hFound, "Human.bmp", 250, 50);
                break;
            }    
            case WM_DESTROY:
                PostQuitMessage (0);       
                break;
            default:                  
                return DefWindowProc (hFound, message, wParam, lParam);
        }
    }
    
    //Draws the buttons in the Scroll-Window
    int DrawButtons(HWND hFound, char* pic_path, int x, int y)
    {
        HANDLE hButton = LoadImage(NULL,pic_path,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
        HDC hdc = GetWindowDC(hFound);
        HDC hdc_ram = CreateCompatibleDC(NULL);
        SelectObject(hdc_ram, hButton);
        BitBlt(hdc, y, x, 30, 30, hdc_ram, 0, 0, SRCCOPY);
    
        return 0;
    }
    
    //Draws the background in the Main-Window
    int DrawBackground(HWND hwnd)
    {
        HANDLE hbitmap = LoadImage(NULL,"GFX\\Background_wc3.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
        HDC hdc = GetWindowDC(hwnd);
        HDC hdc_ram = CreateCompatibleDC(NULL);
        SelectObject(hdc_ram, hbitmap);
        BitBlt(hdc, 0, 30, 400, 280, hdc_ram, 0, 0, SRCCOPY);
    
        return 0;
    }
    


  • 1. GetLastError() und rückgabewerte sind deine freunde. 😉
    2. die hwnd in der msgproc sollten static sein

    LRESULT CALLBACK WinProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        static HWND hSearch;
        static HWND hEnter;
        static HWND hFound;
    


  • Hm.. danke ich werds gleich mal ausprobieren.
    Und den Trick mit dem LastGetError() kannte ich garnicht, danke für den Tip. 🙂


Anmelden zum Antworten