How to make a custom window.

haw can I make a basic window in c++?
I didn't find any tutorials.
I learned c++ from a book called sams teach yourself c++ in 24 hours.
here is a link for it----->http://goo.gl/aH1zTB
It didn't contain any information on this.

when I make a basic window on dev C++ it gives me this 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
#include <windows.h>

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

char szClassName[ ] = "WindowsApp";

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

{
    HWND hwnd;               
    MSG messages;            
    WNDCLASSEX wincl;        

    
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      
    wincl.style = CS_DBLCLKS;                 
    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;                 
    wincl.cbClsExtra = 0;                      
    wincl.cbWndExtra = 0;                      
    
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    
    if (!RegisterClassEx (&wincl))
        return 0;

    
    hwnd = CreateWindowEx (
           0,                   
           szClassName,         
           "Windows App",       
           WS_OVERLAPPEDWINDOW, 
           CW_USEDEFAULT,       
           CW_USEDEFAULT,       
           544,                 
           375,                 
           HWND_DESKTOP,        
           NULL,                
           hThisInstance,       
           NULL                 
           );

    
    ShowWindow (hwnd, nFunsterStil);

    
    while (GetMessage (&messages, NULL, 0, 0))
    {
        
        TranslateMessage(&messages);
        
        DispatchMessage(&messages);
    }

    
    return messages.wParam;
}




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

    return 0;
}

But I don't get how it works so i can edit it to make a custom one
Last edited on
Just search on google.Here an example from code::blocks win32 gui app:
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
#include <windows.h>

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

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

int WINAPI WinMain (HINSTANCE hThisInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR lpszArgument,
                     int nCmdShow)
{
    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;      /* 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 = 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 colour 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 */
           "Code::Blocks Template 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, nCmdShow);

    /* 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);       /* 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;
}
Ok I got it but i need to know how to put buttons and things like this.
how do I do it?
closed account (iAk3T05o)
when i get to this part of c++, i'll be using Qt. it's also been used in a bunch of c++ apps that have gui's like Maya, blender etc. because it uses css and looks like designing any kind of button/form will be easier there.
there's also fltk, gtk etc. but qt looks more design oriented
ok
May I ask why you want to do this? For any specific purpose?
When i want to make a gui app i just use c# .Its a lot easier.
for making games with directX
Last edited on
closed account (iAk3T05o)
Ok, Qt isn't suitable for games, most especially directx games.
Is it 3d or 2d directx games?
Hello Gameman. First off:
When i want to make a gui app i just use c# .Its a lot easier.
Don't listen to this garbage.

Qt is not for writing games. It's pretty much only for non-directx/opengl lib apps.

But I don't get how it works so i can edit it to make a custom one
Just learn Win32 API. It isn't that hard. Look for a tutorial on the internet.

Chances are you wont use a lot of things that WinAPI has to offer since you're going to be using mainly DirectX. You wont need to use many things.

-----------------

If you want to switch to OpenGL however, there a several libraries that ease this process such as SFML and SDL.
Last edited on
Thanks Avilius
Hello Gameman. First off:
When i want to make a gui app i just use c# .Its a lot easier.
Don't listen to this garbage.

Qt is not for writing games. It's pretty much only for non-directx/opengl lib apps.


What does qt has to do with c#.And why c# is garbage?
QT has nothing to do with C# whatsoever. I was not calling C# garbage. Every language has it's time and it's place, and C# can be used for game dev, but isn't really for DirectX. If you want to use C#, then use something like mono.

</offtopic>
For making games, I would avoid winAPI. It was too complicated for me. For games I recommend SFML. It works well with openGl, I don't know much about directX. But if you want intense 3D graphics for a game, maybe you should use a ready game engine. There is a slight difference between making games and coding. Look into Blender for example.

www.blender.org

It is tuff to learn, but much fun and Holy Crap! For real dude, the power blows me away!
Blender isn't really a game engine, and I'd recommend you stay away from it for game creation unless you're creating models.

WinAPI is pretty much your only option for creating a DirectX game, it's recommended you simply write a wrapper over it. I've written a wrapper over it for a side project I'm doing and I don't touch it at all.
The latest version of blender is also a game engine included. But like I said, I don't know much about directX except it was meant to be used for the xbox.
closed account (iAk3T05o)
The engine in blender has been there for a very long time, not just in the new one.
I'd definitely not recommend the Blender Game Engine. Please avoid derailing this thread.
I like the blender game engine. Check out this demo game.

http://www.youtube.com/watch?v=BGqyvX4P6Pg
Topic archived. No new replies allowed.