new window form a Win32 API in the program

i wanne open a new window whit a push of a button.
----------------------------------------------------

i tink i need t do that whit createWindow but don't no how.


tnx

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

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

void Add_Menu(HWND);
void open_window(HWND);

#define IDM_FILE_NEW 1
#define IDM_FILE_OPEN 2
#define IDM_FILE_QUIT 3
#define FILE_MENU_EXIT 4


int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    PWSTR lpCmdLine, int nCmdShow) {

    MSG  msg;
    WNDCLASSW wc = { 0 };
    wc.lpszClassName = L"0001";
    wc.hInstance = hInstance;
    wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
    wc.lpfnWndProc = WndProc;
    wc.hCursor = LoadCursor(0, IDC_ARROW);

    RegisterClassW(&wc);
    CreateWindowW(wc.lpszClassName, L"0001",
        WS_OVERLAPPEDWINDOW | WS_VISIBLE,
        100, 100, 1400, 800, 0, 0, hInstance, 0);

    while (GetMessage(&msg, NULL, 0, 0)) {

        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return (int)msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
    WPARAM wParam, LPARAM lParam) {

    switch (msg) {

    case WM_CREATE:
        Add_Menu(hwnd);
      
        break;

    case WM_COMMAND:
        

        switch (LOWORD(wParam)) {

        case IDM_FILE_NEW:

            break;
        case FILE_MENU_EXIT:

            break;

        case IDM_FILE_OPEN:
            open_window(hwnd);
            MessageBeep(MB_ICONINFORMATION);
            break;

        case IDM_FILE_QUIT:

            SendMessage(hwnd, WM_CLOSE, 0, 0);
            break;
        }

        break;

    case WM_DESTROY:

        PostQuitMessage(0);
        break;
    }

    return DefWindowProcW(hwnd, msg, wParam, lParam);
}

void Add_Menu(HWND hwnd)
{
    HMENU hMenu = CreateMenu();
    HMENU HfileMenu = CreateMenu();
    HMENU hSubMenu = CreateMenu();
    AppendMenuW(hSubMenu, MF_STRING, NULL, L"SubMenu Item");
    AppendMenuW(HfileMenu, MF_STRING, IDM_FILE_NEW, L"New");
    AppendMenuW(HfileMenu, MF_STRING, IDM_FILE_OPEN, L"Open");
    AppendMenuW(HfileMenu, MF_SEPARATOR, NULL, NULL);
    AppendMenuW(HfileMenu, MF_STRING, FILE_MENU_EXIT, L"Exit");
    AppendMenuW(hMenu, MF_POPUP, (UINT_PTR)HfileMenu, L"File");
    AppendMenuW(hMenu, MF_STRING, NULL, L"Help");

    SetMenu(hwnd, hMenu);


}

void open_window(HWND hwnd)
{
    // CreateWindow


}
i think whit a
1
2
3
4
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
// for the main window 
LRESULT CALLBACK D3_VIEW(HWND, UINT, WPARAM, LPARAM);
// the second window 
the debuger tels me that Severity
Error C4700 uninitialized local variable 'hInstance02' used


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void open_window(HWND hWnd)
{

    HINSTANCE hInstance02;
    WNDCLASSW wc = { 0 };
    wc.lpszClassName = L"0002";
    wc.hInstance = hInstance02;
    wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
    wc.lpfnWndProc = WndProc;
    wc.hCursor = LoadCursor(0, IDC_ARROW);

    RegisterClassW(&wc);


    CreateWindowW(wc.lpszClassName, L"0002",
        WS_OVERLAPPEDWINDOW | WS_VISIBLE,
        100, 100, 1400, 800, 0, 0, hInstance02, 0);


    MessageBeep(MB_ICONINFORMATION);



}
hInstance2 is defined on L4 and is un-initialised. This is used on L7 - hence the error.

In WIn32 programming, it's common to have a global hInstance (as it doesn't change) initialised from the WinMain param.
i add 2 int WINAPI and a callback. and the problem is sloft.
Topic archived. No new replies allowed.