Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // test4c.cpp : Defines the entry point for the application.
- //
- #define _CRT_SECURE_NO_WARNINGS
- #include "framework.h"
- #include "test4c.h"
- #include <stdio.h>
- #define MAX_LOADSTRING 100
- #define ID_EDIT1 1
- #define ID_EDIT2 2
- #define ID_BUTTON 3
- // Global Variables:
- HINSTANCE hInst; // current instance
- HWND hEditBox1;
- HWND hEditBox2;
- HWND hButton;
- // Forward declarations of functions included in this code module:
- ATOM MyRegisterClass(HINSTANCE hInstance);
- BOOL InitInstance(HINSTANCE, int);
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
- int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
- _In_opt_ HINSTANCE hPrevInstance,
- _In_ LPWSTR lpCmdLine,
- _In_ int nCmdShow)
- {
- UNREFERENCED_PARAMETER(hPrevInstance);
- UNREFERENCED_PARAMETER(lpCmdLine);
- // TODO: Place code here.
- // Initialize global strings
- MyRegisterClass(hInstance);
- // Perform application initialization:
- if (!InitInstance (hInstance, nCmdShow))
- {
- return FALSE;
- }
- MSG msg;
- // Main message loop:
- while (GetMessage(&msg, nullptr, 0, 0))
- {
- if (!TranslateMessage(&msg))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
- return (int) msg.wParam;
- }
- //
- // FUNCTION: MyRegisterClass()
- //
- // PURPOSE: Registers the window class.
- //
- ATOM MyRegisterClass(HINSTANCE hInstance)
- {
- WNDCLASSEXW wcex;
- wcex.cbSize = sizeof(WNDCLASSEX);
- wcex.style = CS_HREDRAW | CS_VREDRAW;
- wcex.lpfnWndProc = WndProc;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 0;
- wcex.hInstance = hInstance;
- wcex.hIcon = LoadIcon(hInstance, IDI_WINLOGO);
- wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
- wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW);
- wcex.lpszMenuName = 0;
- wcex.lpszClassName = L"MYWINDOW";
- wcex.hIconSm = LoadIcon(hInstance, IDI_WINLOGO);
- return RegisterClassExW(&wcex);
- }
- //
- // FUNCTION: InitInstance(HINSTANCE, int)
- //
- // PURPOSE: Saves instance handle and creates main window
- //
- // COMMENTS:
- //
- // In this function, we save the instance handle in a global variable and
- // create and display the main program window.
- //
- BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
- {
- hInst = hInstance; // Store instance handle in our global variable
- HWND hWnd = CreateWindowW(
- L"MYWINDOW",
- L"MYWINDOW",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, 0,
- 319, 85,
- nullptr, nullptr,
- hInstance,
- nullptr
- );
- if (!hWnd)
- {
- return FALSE;
- }
- ShowWindow(hWnd, nCmdShow);
- UpdateWindow(hWnd);
- //ShowWindow(hEditBox1, nCmdShow);
- return TRUE;
- }
- //
- // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
- //
- // PURPOSE: Processes messages for the main window.
- //
- // WM_COMMAND - process the application menu
- // WM_PAINT - Paint the main window
- // WM_DESTROY - post a quit message and return
- //
- //
- LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch (message)
- {
- case WM_CREATE: {
- // edit box 1
- hEditBox1 = CreateWindowEx(
- WS_EX_CLIENTEDGE,
- L"EDIT",
- NULL,
- WS_BORDER | WS_VISIBLE | WS_CHILD | ES_LEFT,
- 12, 12,
- 89, 23,
- hWnd,
- (HMENU)ID_EDIT1,
- NULL,
- NULL
- );
- // text
- CreateWindow(
- L"STATIC",
- L"+",
- WS_VISIBLE | WS_CHILD | SS_LEFT,
- 108, 15,
- 15, 15,
- hWnd,
- NULL,
- NULL,
- NULL
- );
- // edit box 3
- hEditBox2 = CreateWindowEx(
- WS_EX_CLIENTEDGE,
- L"EDIT",
- NULL,
- WS_BORDER | WS_VISIBLE | WS_CHILD | ES_LEFT,
- 125, 12,
- 89, 23,
- hWnd,
- (HMENU)ID_EDIT2,
- NULL,
- NULL
- );
- // button
- hButton = CreateWindow(
- L"BUTTON",
- L"=",
- WS_VISIBLE | WS_CHILD,
- 220, 12,
- 75, 23,
- hWnd,
- (HMENU)ID_BUTTON,
- NULL,
- NULL
- );
- break;
- }
- case WM_PAINT:
- {
- PAINTSTRUCT ps;
- HDC hdc = BeginPaint(hWnd, &ps);
- // TODO: Add any drawing code that uses hdc here...
- EndPaint(hWnd, &ps);
- }
- break;
- case WM_COMMAND: {
- if (LOWORD(wParam) == ID_BUTTON && HIWORD(wParam) == BN_CLICKED) {
- int len;
- wchar_t* wtext;
- char* text;
- len = GetWindowTextLengthW(hEditBox1);
- wtext = new wchar_t[len + 2];
- GetWindowTextW(hEditBox1, wtext, len + 1);
- text = new char[len + 1];
- sprintf(text, "%ws", wtext);
- int number1 = atoi(text);
- delete[] wtext;
- delete[] text;
- len = GetWindowTextLengthW(hEditBox2);
- wtext = new wchar_t[len + 2];
- GetWindowTextW(hEditBox2, wtext, len + 1);
- text = new char[len + 1];
- sprintf(text, "%ws", wtext);
- int number2 = atoi(text);
- delete[] wtext;
- delete[] text;
- char buf[256];
- sprintf(buf, "%d", number1 + number2);
- MessageBoxA(hWnd, buf, "Hi :)", MB_OK);
- }
- break;
- }
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement