Multiple Windows

Pages: 12
Hello. How would I make 2 windows?
I would like to have the main window then have an About window like in most programs. I can make the main window but I don't know how to have anymore windows than that.

Thanks.
Specifically for an "About Window" you are actually launching another process that opens a document and may or may not have a handle back to your parent process. So what platform are you aiming for?
An example of what I mean is this, in notepad you click "Help" and click "About Notepad" it opens a new window and shows copyright information and stuff like that.

The main thing I want is to know how to make a new window in the standalone application.

I don't really know what you mean by platform.
Last edited on
Then I need to know what platform (Operating System) you are trying to write for. These commands very from one OS to another because, among other things, of the different security measures put in place by each one.
I'm writing the program on Windows 7 64 bit.
If you wanted to know the IDE/Compiler, I'm using Code::Blocks with the GNU GCC Compiler.
Last edited on
"CreateProcess()" it is: http://msdn.microsoft.com/en-us/library/ms682425(VS.85).aspx
Don't worry if it looks intimidating, it's not terribly complicated. If you have any trouble with it let us know, we'll be here.
I mean like using "CreateWindow" to make a new window without opening a new program.
You could do it that way, then you would have to register the new class for it, write a seperate function to read in the data and so on and so forth sure that could work. But why go through that for a text file?

IMO the easiest way to make your own help file is to write the actual help file in HTML then have the program open those. This allows you to do cool stuff like include hyperlinks to jump between files and it makes drawing tables REALLY easy. But that's really only if you're concerned with showing off.
The About window was just an example for a window. I'm not planning on making a help file or anything I just wanted to make a new window in the program.
In that case then yes, "CreateWindow()" is the one that you want. You would differentiate it's function with the CALLBACK function you set in the 'WNDCLASS' struct that you pass to the "RegisterClass()" function.

This can look complicated but it really isn't, and we are here to help you with any questions.
Would you be able to post an example of it? I'm fairly new to C/C++ so I don't know alot about it.
How new are we talking here? Have you made a Win32 application yet? Have you gone through the tutorial on this site or taken any C++ courses in school yet?

I only ask because there's a lot of code to go through and I'll only write it up if you're really interested and you know what you're looking at.
I've read the tutorials here, and I've been working on a text editor application in C++ using Win32 APIs. I've done a 3rd party version of Basic for almost 2 years now and I have done HTML/CSS for a few months now and going to try VB soon. I've wanted to learn C++ for awhile now just recently found out there were free IDEs/Compilers. And I know what I'm getting into, I've seen how large and hard a program can be to make.
Last edited on
This is an increadibly simple one I just wiped up based on a template in wxDev-C++. To do this properly you'd want to launch a second thread to manage the second windows commands and messages. Notice in Process Explorer how they only launch one process for both windows.

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

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

/*  Make the class name into a global variable  */
char szClassName[ ] = "WindowsApp";

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

{
    HWND hwnd;               /* This is the handle the first window */
    HWND chwnd;              /* This is the handle for the second window */
    MSG messages;            /* Here messages to the application are saved. This is shared in this example */
    WNDCLASSEX wincl;        /* Data structure for the first windowclass */
    WNDCLASSEX chwincl;      /* Data structure for the second windowclass
    
    /*The Windows Structure For The Second Window*/
    chwincl.hInstance = hThisInstance;
    chwincl.lpszClassName = "Child";
    chwincl.lpfnWndProc = ChildProcedure;
    chwincl.style = CS_DBLCLKS;
    chwincl.cbSize = sizeof(WNDCLASSEX);
    chwincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    chwincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    chwincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    chwincl.lpszMenuName = NULL;                 
    chwincl.cbClsExtra = 0;                      
    chwincl.cbWndExtra = 0;                      
    chwincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;    

    /* The First Windows structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);
    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 */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the first windows class, and if it fails quit the program
       returning a 1 so that we know where it failed*/
    if (!RegisterClassEx (&wincl))
        return 1;
    
    /* Register the second windows class, and if it fails quit the program
       returning a 2 so that we know where it failed*/    
    if(!RegisterClassEx(&chwincl))
        return 2;

    /* The class is registered, let's create the first window*/
    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 */
           );
           
    /* Create the second window */
    chwnd = CreateWindowEx( 0,
                            "Child", 
                            "Child Window", 
                            WS_OVERLAPPEDWINDOW, 
                            CW_USEDEFAULT, 
                            CW_USEDEFAULT, 
                            800, 
                            600, 
                            HWND_DESKTOP, 
                            NULL,
                            hThisInstance,
                            NULL);

    /* Display the Fist Window, **you can create a window without displaying it** */
    ShowWindow (hwnd, nFunsterStil);
    /* Display the Second Window */
    ShowWindow (chwnd, nFunsterStil);

    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translates Messages from GetMessage Function */
        TranslateMessage(&messages);
        /* Dipatches Messages */
        DispatchMessage(&messages);
    }

    return messages.wParam;
}



/* CALLBACK for the second window */
LRESULT CALLBACK ChildProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                 
    {
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}

/* CALLBACK for the fist window */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}
Last edited on
Alright that works. Thanks.
Nevermind found solution.
Last edited on
Yup, that would be the "SetWindowPos()" function: http://msdn.microsoft.com/en-us/library/ms633545(VS.85).aspx
with 'SWP_HIDEWINDOW' set in the uFlag argument. Do you know how to get a handle to the target window?
No, I don't know anything about that.
:D This is thread is really inflating my ego LOL!

If the target window is the one you created with the "CreateWindow()" function then the value returned by that function is the handle you want to pass as the first argument to "SetWindowPos()".

Ah, I see you found a solution 1 minute before my post. Does it work?
No, I thought it worked then it didn't.
Pages: 12