C++ ChildWindow Problem

Binär10010111

Grünschnabel
Hallo Comunity,
ich programmiere seit ein paar wochen mit windows. ich hab jetzt allerdings ein problem mit den ChildWindows. Ich kann sie zwar erstellen und man sieht sie auch, aber ich kann keine Editfelder oder sonstiges in ihnen erstellen (um genau zu einmal hat's funktionier, jetzt nicht mehr keine Ahnung warum). Auserdem kann ich die Fenster nicht auswählen (=Graue Titelleiste). Könnte mir jemand bitte helfen? Hier der Code:

Code:
/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ChildProc(HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "Main";
char szChildName[ ] = "Child";
char str[256];

HINSTANCE GlobalInstance;
HWND hChild;

int WINAPI WinMain (HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */
    HMENU menu;              /*Handel for the Menu*/

    
    GlobalInstance = hInstance;
    
    /* The Window structure */
    wincl.hInstance = hInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = 0;                 /* Menu ID defined in main.h */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH)(COLOR_3DSHADOW+1);

    /* Register the window class, and if it fails quit the program */
    if(!RegisterClassEx(&wincl))
   {
      MessageBox(0, "Could Not Register Window", "Oh Oh...",
         MB_ICONEXCLAMATION | MB_OK);
      return -1;
   }
    wincl.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wincl.hInstance = GlobalInstance;
    wincl.lpszClassName = szChildName;
    wincl.lpfnWndProc = ChildProc;
    /* Register the window class, and if it fails quit the program */
    if(!RegisterClassEx(&wincl))
   {
      MessageBox(0, "Could Not Register Childwindow", "Oh Oh...",
         MB_ICONEXCLAMATION | MB_OK);
      return -1;
   }
    
    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           WS_EX_CLIENTEDGE,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           PRODUCT_NAME,          /* Title Text */
           WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           CW_USEDEFAULT,                 /* The programs width */
           CW_USEDEFAULT,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hInstance,           /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );
    
    /* Make the window visible on the screen */
    ShowWindow (hwnd, nFunsterStil);
    
    /*Load the menu*/
    menu = LoadMenu(hInstance, MAKEINTRESOURCE(ID_MENU));
    ChildMenu = LoadMenu(GlobalInstance, MAKEINTRESOURCE(ID_CHILDMENU));
    SetMenu(hwnd, menu);
    SetMenu(hChild, ChildMenu);
    

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}

/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{   
    switch (message)                  /* handle the messages */
    {
        case WM_DESTROY:
             PostQuitMessage(0);
             break;
        case WM_COMMAND:
             switch(wParam)
             {
                  case ID_WINENEW:
                  {
                       hChild = CreateWindow(
                                szChildName,
                                "Neues ChildWindow",
                                WS_CHILD|WS_VISIBLE|WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU,
                                CW_USEDEFAULT,
                                CW_USEDEFAULT,
                                400,
                                400,
                                hwnd,
                                0,
                                GlobalInstance,
                                NULL);
                                return 0;
                  }
             }
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}

LRESULT CALLBACK ChildProc(HWND hwnd, UINT message,WPARAM wParam, LPARAM lParam)
{
        HWND EdHwnd;
        switch (message)
        {
               case WM_CREATE:
               {
                    EdHwnd = CreateWindowEx(
                             WS_EX_CLIENTEDGE,
                             "EDIT","",
                             WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL,
                             10,
                             10,
                             100,
                             12,
                             hChild,
                             (HMENU)20001,
                             GlobalInstance,
                             NULL);
                             ShowWindow(EdHwnd, SW_SHOW);
                             return 0;
               }              
               default:
                       return DefWindowProc(hwnd, message, wParam, lParam);
        }
        return 0;
}
 
Ich bin jetzt nicht 100% sicher, ob es daran liegt,
aber versuch doch, das EDIT-Window ohne Title-Bar und Sys-Menü zu erstellen.

/EDIT: Sorry, hab mich verguckt.

Warum erstellst du das EDIT-Fenster bei WM_COMMAND?
Wenn du mehrere Child-Fenster haben willst, dann besser nicht über ein globales ChildWindow Handle..

Das bedeutet, dass hChild noch nicht sinnvoll initialisiert ist, zum Zeitpunkt zu dem du ihm ein Menü zuweißt.

Das gleiche Problem mit dem EDIT-Fenster: du erstellst es unter Verwendung des globalen ChildWindow-Handles.
Das ist aber erst nach CreateWindow (wo WM_CREATE ja aufgerufen wird) gültig.
 
Zuletzt bearbeitet:
Zurück