how to add buttons to the window

hi i need how so im using visual studio( windows form application, empty project) and i has no idea how to add buttons to the script below i tried looking it up on google but i couldnt find any can you plz help


#include <iostream>
#include <Windows.h>



LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR nCmdLine, int nCmdShow)
{
const wchar_t CLASS_NAME[] = L"NULL";
WNDCLASS wc = {};
wc.lpfnWndProc = WindowProc;
wc.lpszClassName = CLASS_NAME;
wc.hInstance = hInstance;
RegisterClass(&wc);

HWND hWnd = CreateWindowEx(0, CLASS_NAME, L"Assault Cube", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);

if (hWnd == 0)
return NULL;
ShowWindow(hWnd, nCmdShow);
nCmdShow = 1;
MSG msg = {};
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}

LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:PostQuitMessage(0);
return 0;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 2));
EndPaint(hWnd, &ps);
}
return 0;
case WM_CLOSE:
{
if (MessageBox(hWnd, L"Do you want to exit?", L"EXIT", MB_OKCANCEL) == IDOK)
DestroyWindow(hWnd);
return 0;
}
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
A button is a kind of window created by CreateWindowEx or CreateWindow
Have a look here:
https://msdn.microsoft.com/en-us/library/windows/desktop/hh298354%28v=vs.85%29.aspx
First, that isn't a Window Forms program. Its an SDK style Win32 app.

Second, it isn't a script. Its C++ source code which a compiler will translate into binary.

Third, it isn't in code tags, making the reading of it difficult.

And there are other issues.

But here is a version modified slightly to run on my GCC compiler that shows how to create buttons...

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
#ifndef UNICODE
#define UNICODE
#endif
#ifndef _UNICODE
#define _UNICODE
#endif
#include <Windows.h>
#define BTN_BUTTON1  2000


LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
 switch (uMsg)
 {
   case WM_CREATE:
     {
        HINSTANCE hIns=((LPCREATESTRUCT)lParam)->hInstance;
        CreateWindowEx(0,L"button",L"Love",WS_CHILD|WS_VISIBLE,125,15,80,30,hWnd,(HMENU)BTN_BUTTON1,hIns,0);
        return 0;
     }
   case WM_PAINT:
     {
        PAINTSTRUCT ps;
        HDC hdc = BeginPaint(hWnd, &ps);
        FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 2));
        EndPaint(hWnd, &ps);
        return 0;
     }
   case WM_CLOSE:
     {
        if(MessageBox(hWnd, L"Do you want to exit?", L"EXIT", MB_OKCANCEL) == IDOK)
           DestroyWindow(hWnd);
        return 0;
     }
   case WM_DESTROY:
     {
        PostQuitMessage(0);
        return 0;
     }
 }

  return DefWindowProc(hWnd, uMsg, wParam, lParam);
}


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevIns, LPSTR lpszArgument, int nCmdShow)
{
 const wchar_t CLASS_NAME[] = L"NULL";
 WNDCLASS wc = {};
 wc.lpfnWndProc = WindowProc;
 wc.lpszClassName = CLASS_NAME;
 wc.hInstance = hInstance;
 RegisterClass(&wc);
 HWND hWnd = CreateWindowEx(0, CLASS_NAME, L"Assault Cube", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
 if (hWnd == 0)
     return NULL;
 ShowWindow(hWnd, nCmdShow);
 nCmdShow = 1;
 MSG msg;
 while (GetMessage(&msg, NULL, 0, 0))
 {
   TranslateMessage(&msg);
   DispatchMessage(&msg);
 }

 return 0;
}
Topic archived. No new replies allowed.