<Windows.h> Add a reaction to the button click - display on the form an inscription from the text box

Hi! I have problems with the assignment, and our teacher is absolutely incompetent :((( Pleeease, help with 5 task (Add a reaction to the button click - display on the form an inscription from the text field)
1.Create a Windows form;
2.Add a greeting to the form;
3.Add a text box to the form
4.Add a button to the form;
5.Add a reaction to the button click - display on the form an inscription from the text box


My code

#include <Windows.h>
#include <stdio.h>
#include <iostream>
#define IDC_TEXT 101
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)

{
HWND TextBox;
HDC hdc;
RECT rect;
char szInput[MAX_PATH];

GetWindowText(GetDlgItem(hWnd, IDC_TEXT), szInput, MAX_PATH);
PAINTSTRUCT ps;

char str[150];
switch (msg)
{
case WM_COMMAND:
if (wParam == 100)
MessageBox(hWnd, TEXT("Okey"), TEXT("Dialog"), 0);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rect);
DrawText(hdc, TEXT("Hello, World! "), -1, &rect, DT_TOP | DT_CENTER);
break;
case WM_CREATE:
HWND hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "edit", "",
WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_LEFT,
0, 0, 100, 20,
hWnd, (HMENU)IDC_TEXT,
(HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
break;

}


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

}

int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE h2, LPSTR cmd, int CmShow)
{
static TCHAR szAppName[] = TEXT("HelloWin");
WNDCLASS wc = { 0 };
wc.lpszClassName = TEXT("Myclass");
wc.lpfnWndProc = WndProc;
RegisterClass(&wc);

HWND hWnd = CreateWindow(wc.lpszClassName, TEXT("Win-forma"), WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 500, 500, 0, 0, hInstance, 0);
CreateWindow(TEXT("button"), TEXT("Button"), WS_CHILD | WS_VISIBLE, 100, 100, 200, 100, hWnd, (HMENU)100, hInstance, 0);

MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
assignment
assignment? winapi? teacher? whaaat?

As for the code:

1
2
3
4
5
6
7
8
9
10

#define MY_BUTTON  101 
// use MY_BUTTON as your button id

//inside your window callback
case MY_BUTTON: // your button id
{
     SetWindowText(someLabel, _T("You clicked the button")); //set text control/label

} break;
Last edited on
Sorry, I`m from Belarus and my English is not so good...
Thanks :)
But I haven't looked into it yet :(((((((((((((((((((
Registered users can post here. Sign in or register to post.