Kindfenster in ist nur ein clone -.- vom erstfenster



  • Hallo , ich habe ein problem:
    wenn ich ein kindfenstererstelle steht da nur das gleiche drin wie vom 1.fenster

    HWND hwnd = CreateWindow          // Fenster 1
    (
        szName,
        "Dies ist unser erstes kleines Fenster",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
        NULL, // Handle des Elternfensters nicht vorhanden
        NULL,
        hI,
        NULL
    );
    
    ShowWindow   (hwnd, iCmdShow);
    UpdateWindow (hwnd);
    
    HWND hwnd2 = CreateWindow        // Fenster 2
    (
        szName,
        "Dies ist unser zweites kleines Fenster",
        WS_OVERLAPPEDWINDOW,
        200, 200, 200, 50,
        hwnd, // Handle des Elternfensters
        NULL,
        NULL,
        NULL
    );
    
    ShowWindow   (hwnd2, SW_SHOWNORMAL);
    UpdateWindow (hwnd2);
    

    so schön aber wie mache ich das dass ein einen fenster ein Button mit "A" drauf steht und im anderen fenster ein butten mit "B" ???

    ich hoffe ich hab genau mein problem beschrieben



  • also ich meine fenster1 + button "A"
    fenster1 + button "B"

    mfg: MINI-WEICH



  • du musst für das 2. fenster eine eigene WNDCLASS registrieren, mit eigener Callback-Routine und eigenem klassennamen



  • ja aber wie ??? ich hab das schonmal probirt aber der zickt dann mit

    int WINAPI WinMain (HINSTANCE hThisInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpszArgument,
                        int nFunsterStil)
    
    int WINAPI WinMain2 (HINSTANCE hThisInstance2,
                        HINSTANCE hPrevInstance2,
                        LPSTR lpszArgument2,
                        int nFunsterStil2)
    
    ////////////////////////////////////////////
    {
        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 */
    
        /* The Window structure */
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;      
        wincl.style = CS_DBLCLKS;                 
        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 = NULL;                 /* No menu */
        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_BACKGROUND;
    
        /* Register the window class, and if it fails quit the program */
        if (!RegisterClassEx (&wincl))
            return 0;
    
        /* The class is registered, let's create the program*/
        hwnd = CreateWindowEx (
               0,                   /* Extended possibilites for variation */
               szClassName,         /* Classname */
               "Windows App",       /* Title Text */
               WS_OVERLAPPEDWINDOW, /* default window */
               CW_USEDEFAULT,       /* Windows decides the position */
               CW_USEDEFAULT,       /* where the window ends up on the screen */
               544,                 /* The programs width */
               375,                 /* and height in pixels */
               HWND_DESKTOP,        /* The window is a child-window to desktop */
               NULL,                /* No menu */
               hThisInstance,       /* Program Instance handler */
               NULL                 /* No Window Creation data */
               );
    
        /* Make the window visible on the screen */
        ShowWindow (hwnd, nFunsterStil);
    
        /* 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;
    }
    
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    HDC hdc;
     PAINTSTRUCT ps;
     HWND hwndButton;
    
     switch (message)
     {
    
      case WM_PAINT:
          hdc = BeginPaint (hwnd, &ps);
          SetBkColor(hdc, RGB(212,208,200) ); 
          TextOut (hdc, 100, 40, "Telefon Nummer:", 15);
          EndPaint (hwnd, &ps);
    
      return 0;
    
      case WM_DESTROY:
        PostQuitMessage (0);
      return 0;
     }
    
     return DefWindowProc (hwnd, message, wParam, lParam);
    }
    

    aber ab wincl. nimmt der terror sein lauf

    oder erstellt project aber es kommt kein fenster mehr ! -.- nur die beispiel.exe im taskt



  • nein bitte tue das nicht, bitte!!! xD xD

    ne so gehts auch wirklich nicht. es kann nur eine main-funktion geben und in der winapi ist das WinMain, da kannst du nicht einfach eine 2. machen.

    HINSTANCE g_hInst;
    
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
    LRESULT CALLBACK ConPrefProc (HWND, UINT, WPARAM, LPARAM);
    
    int WINAPI WinMain (HINSTANCE hI, HINSTANCE hPrI, LPSTR szCmdLine, int iCmdShow)
    {
    	char MainWin[] = "fenster1";
    	char ConnectWin[] = "fenster2";
    
    	UNREFERENCED_PARAMETER (hPrI);
    	UNREFERENCED_PARAMETER (szCmdLine);
    
    	g_hInst = hI;
    	WNDCLASS wc;
    
    	wc.style = CS_HREDRAW | CS_VREDRAW;
    	wc.lpfnWndProc = WndProc;
    	wc.cbClsExtra = 0;
    	wc.cbWndExtra = 0;
    	wc.hInstance = hI;
    	wc.hIcon = NULL;
    	wc.hCursor = LoadCursor (NULL, IDC_ARROW);
    	wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
    	wc.lpszMenuName = NULL;
    	wc.lpszClassName = MainWin;
    
    	RegisterClass (&wc);
    
    	hMain = CreateWindow (MainWin, "test", WS_OVERLAPPEDWINDOW, 300, 300, x + 410, y + 250, NULL, NULL, hI, NULL);
    	ShowWindow (hMain, iCmdShow);
    	UpdateWindow (hMain);
    
    	wc.lpfnWndProc = ConPrefProc;
    	wc.lpszMenuName = NULL;
    	wc.lpszClassName = ConnectWin;
    
    	RegisterClass (&wc);
    
    	hConnectWnd = CreateWindow (ConnectWin, "test2", WS_SYSMENU | WS_MINIMIZEBOX, 400, 400, x + 285, y + 112, NULL, NULL, hI, NULL);
    	ShowWindow (hConnectWnd, SW_HIDE);
    
    	MSG msg;
    	while (GetMessage (&msg, NULL, 0, 0))
    	{
    		TranslateMessage (&msg);
    		DispatchMessage (&msg);
    	}
    	return msg.wParam;
    }
    
    LRESULT CALLBACK WndProc (HWND hMain, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	switch (message)
    	{
    		case WM_DESTROY:
    			PostQuitMessage (0);
    		return 0;
    	}
    
    	return DefWindowProc (hMain, message, wParam, lParam);
    }
    
    LRESULT CALLBACK ConPrefProc (HWND hConnectWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	switch (message)
    	{
    		case WM_DESTROY:
    			PostQuitMessage (0);
    		return 0;
    	}
    
    	return DefWindowProc (hConnectWnd, message, wParam, lParam);
    }
    

    ist mal ein bsp. sollte so funzen 🙂



  • DANKE!!!!!!!!!!!!!!!!!!



  • so für alle anderen zum complieren berreit !!!

    #include<windows.h>
    
    HINSTANCE g_hInst;
    
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
    LRESULT CALLBACK ConPrefProc (HWND, UINT, WPARAM, LPARAM);
    
    int WINAPI WinMain (HINSTANCE hI, HINSTANCE hPrI, LPSTR szCmdLine, int iCmdShow)
    {
        char MainWin[] = "fenster1";
    
        char ConnectWin[] = "fenster2";
    
        UNREFERENCED_PARAMETER (hPrI);
        UNREFERENCED_PARAMETER (szCmdLine);
    
        g_hInst = hI;
        WNDCLASS wc;
        HWND  hConnectWnd,hMain;
    
        wc.style = CS_HREDRAW | CS_VREDRAW;
        wc.lpfnWndProc = WndProc;
        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hInstance = hI;
        wc.hIcon = NULL;
        wc.hCursor = LoadCursor (NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
        wc.lpszMenuName = NULL;
        wc.lpszClassName = MainWin;
    
        RegisterClass (&wc);
    
        hMain = CreateWindow (MainWin, "test", WS_OVERLAPPEDWINDOW, 300, 300,410, 250, NULL, NULL, hI, NULL);
        ShowWindow (hMain, iCmdShow);
    
        UpdateWindow (hMain);
    
        wc.lpfnWndProc = ConPrefProc;
        wc.lpszMenuName = NULL;
        wc.lpszClassName = ConnectWin;
    
        RegisterClass (&wc);
    
        hConnectWnd = CreateWindow (ConnectWin, "test2", WS_OVERLAPPEDWINDOW , 300, 300, 410, 250, NULL, NULL, hI, NULL);
        ShowWindow (hConnectWnd, iCmdShow);
    
        MSG msg;
        while (GetMessage (&msg, NULL, 0, 0))
        {
            TranslateMessage (&msg);
            DispatchMessage (&msg);
        }
        return msg.wParam;
    }
    
    LRESULT CALLBACK WndProc (HWND hMain, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)
        {
            case WM_DESTROY:
                PostQuitMessage (0);
            return 0;
        }
    
        return DefWindowProc (hMain, message, wParam, lParam);
    }
    
    LRESULT CALLBACK ConPrefProc (HWND hConnectWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)
        {
            case WM_DESTROY:
                PostQuitMessage (0);
            return 0;
        }
    
        return DefWindowProc (hConnectWnd, message, wParam, lParam);
    }
    

    😉 😃 👍 👍



  • so mit text (sorry fürs 3er posten ! ) 😉 😃

    #include<windows.h>
    
    HINSTANCE g_hInst;
    
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
    LRESULT CALLBACK ConPrefProc (HWND, UINT, WPARAM, LPARAM);
    
    int WINAPI WinMain (HINSTANCE hI, HINSTANCE hPrI, LPSTR szCmdLine, int iCmdShow)
    {
        char MainWin[] = "fenster1";
    
        char ConnectWin[] = "fenster2";
    
        UNREFERENCED_PARAMETER (hPrI);
        UNREFERENCED_PARAMETER (szCmdLine);
    
        g_hInst = hI;
        WNDCLASS wc;
        HWND  hConnectWnd,hMain;
    
        wc.style = CS_HREDRAW | CS_VREDRAW;
        wc.lpfnWndProc = WndProc;
        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hInstance = hI;
        wc.hIcon = NULL;
        wc.hCursor = LoadCursor (NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
        wc.lpszMenuName = NULL;
        wc.lpszClassName = MainWin;
    
        RegisterClass (&wc);
    
        hMain = CreateWindow (MainWin, "test", WS_OVERLAPPEDWINDOW, 300, 300,410, 250, NULL, NULL, hI, NULL);
        ShowWindow (hMain, iCmdShow);
    
        UpdateWindow (hMain);
    
        wc.lpfnWndProc = ConPrefProc;
        wc.lpszMenuName = NULL;
        wc.lpszClassName = ConnectWin;
    
        RegisterClass (&wc);
    
        hConnectWnd = CreateWindow (ConnectWin, "test2",WS_SYSMENU | WS_MINIMIZEBOX, 400, 400, 285,112, NULL, NULL, hI, NULL);
        ShowWindow (hConnectWnd, iCmdShow);
    
        MSG msg;
        while (GetMessage (&msg, NULL, 0, 0))
        {
            TranslateMessage (&msg);
            DispatchMessage (&msg);
        }
        return msg.wParam;
    }
    
    LRESULT CALLBACK WndProc (HWND hMain, UINT message, WPARAM wParam, LPARAM lParam)
    {
       HDC hdc;
      PAINTSTRUCT ps;
    
     switch (message)
     {
    
      case WM_PAINT:
          hdc = BeginPaint (hMain, &ps);
          SetBkColor(hdc, RGB(212,208,200) );
          TextOut (hdc, 100, 40, "Fenster A", 9);
          EndPaint (hMain, &ps);
    
      return 0; 
            case WM_DESTROY:
                PostQuitMessage (0);
            return 0;
        }
    
        return DefWindowProc (hMain, message, wParam, lParam);
    }
    
    LRESULT CALLBACK ConPrefProc (HWND hConnectWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        HDC hdc;
      PAINTSTRUCT ps;
    
     switch (message)
     {
    
      case WM_PAINT:
          hdc = BeginPaint (hConnectWnd, &ps);
          SetBkColor(hdc, RGB(212,208,200) );
          TextOut (hdc, 100, 40, "Fenster B", 9);
          EndPaint (hConnectWnd, &ps);
    
      return 0; 
            case WM_DESTROY:
                PostQuitMessage (0);
            return 0;
        }
    
        return DefWindowProc (hConnectWnd, message, wParam, lParam);
    }
    


  • Mini-Weich (Mirco Soft) schrieb:

    (sorry fürs 3er posten ! )

    Wenn Du Dich registrieren lassen würdest, könntest Du Deine eigenen Posts nachträglich bearbeiten. Erspart die Mehrfachposts. 😉


Anmelden zum Antworten