tutorials.de Buch-Aktion 05/2012
ERLEDIGT
NEIN
ANTWORTEN
2
ZUGRIFFE
888
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    Binär10010111 Binär10010111 ist offline Grünschnabel
    Registriert seit
    Feb 2008
    Beiträge
    2
    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 :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    
    /*  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;
    }
     

  2. #2
    Beichtpfarrer Beichtpfarrer ist offline Mitglied Brokat
    Registriert seit
    Jan 2004
    Ort
    Wannweil
    Beiträge
    302
    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.
    Geändert von Beichtpfarrer (28.02.08 um 18:37 Uhr)
     
    Noch weiter helfen jetzt nur noch google, msdn, Tutorials, Forumssuche, Eingebungen, Glück und ein wenig Hirnanstrengung.

  3. #3
    Binär10010111 Binär10010111 ist offline Grünschnabel
    Registriert seit
    Feb 2008
    Beiträge
    2
    danke für deine hilfe
    ich schau mal ob ichs hinbekomme
     

Ähnliche Themen

  1. ATL Childwindow -> Vollbildmodus
    Von Shadow im Forum VisualStudio & MFC
    Antworten: 4
    Letzter Beitrag: 25.04.06, 11:18
  2. Antworten: 4
    Letzter Beitrag: 22.03.06, 20:50
  3. Titelleiste von ChildWindow
    Von SeeSharpNewBee im Forum .NET Archiv
    Antworten: 2
    Letzter Beitrag: 01.08.05, 13:53
  4. Antworten: 3
    Letzter Beitrag: 12.05.05, 01:53
  5. [MDI] schnelles Zeichnen in ChildWindow
    Von basd im Forum VisualStudio & MFC
    Antworten: 2
    Letzter Beitrag: 17.02.04, 23:31