Creating windows with simply way

Hi there!
I'm trying to create windows (I know how), but it is a little bit complicated.
I have the following 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
//winh.h
#ifndef WINH_H_INCLUDED
#define WINH_H_INCLUDED
#include <windows.h>
#include <windowsx.h>
#define Handle HWND
#define WindowClass WNDCLASSEX
#define WindowsMain int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
#define Win_Proc LRESULT CALLBACK WindowProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)


WindowsMain
{

}
template <typename TYPE, typename NEWTYPE, typename CLASS>
 int WindowShow(HWND hWnd,WNDCLASSEX wc,NEWTYPE WinTitle,CLASS className)
    {

        Win_Proc;
        ZeroMemory(&wc, sizeof(WNDCLASSEX));
        wc.cbSize = sizeof(WNDCLASSEX);
        wc.style = CS_HREDRAW | CS_VREDRAW;
        wc.lpfnWndProc = WindowProc;
        wc.hInstance = hInstance;
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
        wc.lpszClassName = className;
            hWnd = CreateWindowExW(NULL,
                          (L className),    // name of the window class
                          (L WinTitle),   // title of the window
                          WS_OVERLAPPEDWINDOW,    // window style
                          300,    // x-position of the window
                          300,    // y-position of the window
                          500,    // width of the window
                          400,    // height of the window
                          NULL,    // we have no parent window, NULL
                          NULL,    // we aren't using menus, NULL
                          hInstance,    // application handle
                          NULL);    // used with multiple windows, NULL

    // display the window on the screen
    ShowWindow(hWnd, nCmdShow);
    MSG msg;
    while(GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return msg.wParam;
    Win_Proc
{

    switch(message)
    {

        case WM_DESTROY:
            {

                PostQuitMessage(0);
                return 0;
            } break;
    }

    return DefWindowProc (hWnd, message, wParam, lParam);

}
    }
#endif // WINH_H_INCLUDED

//test.cpp
#include "winh.h"

WindowsMain
{
Handle BLABLA;
WindowClass HEYTHERE;
WindowShow(BLABLA,HEYTHERE,"Test","WinClass");
}



But I get some errors. How can I create them with the simply way?
Thanks in advance.
Last edited on
That's pretty carless code.

Anyway, what do you mean by "the simple way"?
This is about as simple as it gets ...

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
//For MS cl Compiler - cl Main.cpp user32.lib
#include <windows.h>

LRESULT CALLBACK fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam,LPARAM lParam)
{
 if(msg==WM_DESTROY)
 {
    PostQuitMessage(0);
    return 0;
 }

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


int WINAPI WinMain(HINSTANCE hIns, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
{
 char szClassName[]="Form1";
 WNDCLASSEX wc={};
 MSG messages;
 HWND hWnd;

 wc.lpszClassName   = szClassName;
 wc.lpfnWndProc     = fnWndProc;
 wc.cbSize          = sizeof (WNDCLASSEX);
 wc.hInstance       = hIns;
 RegisterClassEx(&wc);
 hWnd=CreateWindowEx(0,szClassName,szClassName,WS_OVERLAPPEDWINDOW,100,100,350,300,HWND_DESKTOP,0,hIns,0);
 ShowWindow(hWnd,iShow);
 while(GetMessage(&messages,NULL,0,0))
 {
    TranslateMessage(&messages);
    DispatchMessage(&messages);
 }

 return messages.wParam;
}
Example:
1
2
3
4
5
6
#include "headerwiththeclassandfuncs.h"
int WINAPI...
{
Window something;
something.Show();
}
Last edited on
Good idea. Go for it!
Do you have some idea? I'm a DirectX programmer , and this could help me a LOT.
closed account (N36fSL3A)
Do you want help with your code or with finding how to make a window an easier way?

If you choose the latter then 1 way is to use cross-platform libs such as xwidgets. You could also write your own interface.
I need help with the code, because DirectX needs Windows "window".
Thanks.
closed account (N36fSL3A)
Why not look up a WinAPI tutorial?
Lumpkin - I know how to make windows - but it's too slow. Time is money, so if I make this faster, it will better for me.
Thanks.
closed account (N36fSL3A)
Optimize your program. Are you allocating memory dynamically where you don't have to? Are you using variable types that take up more space than necessary?
Yes, but I don't think that will make my program easier to write... Do you have any idea?
create your own winAPI wrapper in c/c++ to simplify thing for you, although i bet there are available one already:
( https://www.google.com/search?q=winapi+wrapper )
Last edited on
Topic archived. No new replies allowed.