[C++] Child window sluit ook parent

Pagina: 1
Acties:
  • 54 views sinds 30-01-2008

  • Dr. Vork
  • Registratie: Oktober 1999
  • Laatst online: 27-02 00:36

Dr. Vork

Moet ik hier iets tiepen?

Topicstarter
Vraag 1: Het probleem met onderstaande code is dat als ik de child window sluit door op het kruisje te drukken de parent ook sluit en dus het hele programma.
Dat zou toch niet zo moeten wezen, want ik heb voor de child window toch een andere window procedure aangegeven.
Vraag 2: Waarom blijft mijn child window inactief?

Ik hoop dat de code duidelijk is.

--code--

C++:
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
#include <windows.h>

const char g_szClassName[] = "myWindowClass";

BOOL RegWinClass(HINSTANCE hInstance, WNDPROC lpfnWndProc)
{
    WNDCLASSEX wc;

    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;
    wc.lpfnWndProc   = lpfnWndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = g_szClassName;
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    return RegisterClassEx(&wc);
}

LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        case WM_DESTROY:
            PostQuitMessage(0);
        break;
        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}

LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        case WM_DESTROY:
        //  PostQuitMessage(0);
        break;
        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
    MSG Msg;
    HWND hwndMain;
    HWND hwndChild1;

    //Make main window
    RegWinClass(hInstance, MainWndProc);
    hwndMain = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        g_szClassName,
        "Main",
        WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
        CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
        NULL, NULL, hInstance, NULL);
    ShowWindow(hwndMain, nCmdShow);
    UpdateWindow(hwndMain);

    //Make child1 window
    RegWinClass(hInstance, ChildWndProc);
    hwndChild1 = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        g_szClassName,
        "Child1",
        WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MAXIMIZEBOX,
        0, 0, 100, 100,
        hwndMain, NULL, hInstance, NULL);
    ShowWindow(hwndChild1, nCmdShow);
    UpdateWindow(hwndChild1);


    //Messageloop
    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
    return Msg.wParam;
}

[ Voor 2% gewijzigd door .oisyn op 06-03-2003 17:42 ]


  • .oisyn
  • Registratie: September 2000
  • Laatst online: 22-08 13:19

.oisyn

Moderator Devschuur®

Demotivational Speaker

tip: gebruik [code=taal]...[/code] tags

.edit: je registreert 2x dezelfde window class.. De 2e keer gaat het dus fout, en wordt de child window dus ook gecreeerd met dezelfde windowproc als de main window. En in die windowproc staat een aanroep naar PostQuitMessage () bij een WM_DESTROY event

daarom dus :)

[ Voor 70% gewijzigd door .oisyn op 06-03-2003 17:46 ]

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.


  • Dr. Vork
  • Registratie: Oktober 1999
  • Laatst online: 27-02 00:36

Dr. Vork

Moet ik hier iets tiepen?

Topicstarter
ok, nu is het zo, maar het doet nog steeds hetzelfde.
edit: nu niet meer, sorry :) bedankt voor de hulp, ik was iets vergeten te veranderen

C++:
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
#include <windows.h>

const char g_szClassName[] = "myWindowClass";
const char g_syClassName[] = "myWindowClass";

LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        case WM_DESTROY:
            PostQuitMessage(0);
        break;
        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}

LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        case WM_DESTROY:
        //  PostQuitMessage(0);
        break;
        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
    MSG Msg;
    HWND hwndMain;
    HWND hwndChild1;

    //Make main window
    WNDCLASSEX wc;

    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;
    wc.lpfnWndProc   = MainWndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = g_szClassName;
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    RegisterClassEx(&wc);

    hwndMain = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        g_szClassName,
        "Main",
        WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
        CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
        NULL, NULL, hInstance, NULL);
    ShowWindow(hwndMain, nCmdShow);
    UpdateWindow(hwndMain);

    //Make child1 window
    WNDCLASSEX wb;

    wb.cbSize        = sizeof(WNDCLASSEX);
    wb.style         = 0;
    wb.lpfnWndProc   = ChildWndProc;
    wb.cbClsExtra    = 0;
    wb.cbWndExtra    = 0;
    wb.hInstance     = hInstance;
    wb.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wb.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wb.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wb.lpszMenuName  = NULL;
    wb.lpszClassName = g_syClassName;
    wb.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    RegisterClassEx(&wb);
    
    hwndChild1 = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        g_syClassName,
        "Child1",
        WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MAXIMIZEBOX,
        0, 0, 100, 100,
        hwndMain, NULL, hInstance, NULL);
    ShowWindow(hwndChild1, nCmdShow);
    UpdateWindow(hwndChild1);


    //Messageloop
    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
    return Msg.wParam;
}

[ Voor 3% gewijzigd door Dr. Vork op 06-03-2003 18:42 ]


  • curry684
  • Registratie: Juni 2000
  • Laatst online: 13-08 16:46

curry684

left part of the evil twins

Nofi, maar kun je asjeblieft opzouten met in totaal 3 keer dezelfde 109 regels code te posten? Uberhaupt had je de 2 vragen over deze code ook in 1 topic kunnen plaatsen, maar in godesnaam 109 regels komt de leesbaarheid niet ten goede. :?

Professionele website nodig?


  • .oisyn
  • Registratie: September 2000
  • Laatst online: 22-08 13:19

.oisyn

Moderator Devschuur®

Demotivational Speaker

DUH!!! De window class names zijn nu toch nog steeds hetzelfde?

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.


  • .oisyn
  • Registratie: September 2000
  • Laatst online: 22-08 13:19

.oisyn

Moderator Devschuur®

Demotivational Speaker

trouwens, ga maar verder in die andere topic... het lijkt me niet echt de bedoeling dat je voor elk wiswasje wat ongeveer met hetzelfde te maken heeft een nieuw topic opent

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.

Pagina: 1

Dit topic is gesloten.