"c++ window code" Code Answer's

You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "c++ window code" answered properly. Developers are finding an appropriate answer about c++ window code related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like c++ window code. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on c++ window code. 

c++ window code

By KieranSwordKieranSword on Feb 24, 2021
// HelloWindowsDesktop.cpp
// compile with: /D_UNICODE /DUNICODE /DWIN32 /D_WINDOWS /c

#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>

// Global variables

// The main window class name.
static TCHAR szWindowClass[] = _T("DesktopApp");

// The string that appears in the application's title bar.
static TCHAR szTitle[] = _T("Windows Desktop Guided Tour Application");

HINSTANCE hInst;

// Forward declarations of functions included in this code module:
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int CALLBACK WinMain(
   _In_ HINSTANCE hInstance,
   _In_opt_ HINSTANCE hPrevInstance,
   _In_ LPSTR     lpCmdLine,
   _In_ int       nCmdShow
)
{
   WNDCLASSEX 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_APPLICATION);
   wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
   wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
   wcex.lpszMenuName   = NULL;
   wcex.lpszClassName  = szWindowClass;
   wcex.hIconSm        = LoadIcon(wcex.hInstance, IDI_APPLICATION);

   if (!RegisterClassEx(&wcex))
   {
      MessageBox(NULL,
         _T("Call to RegisterClassEx failed!"),
         _T("Windows Desktop Guided Tour"),
         NULL);

      return 1;
   }

   // Store instance handle in our global variable
   hInst = hInstance;

   // The parameters to CreateWindow explained:
   // szWindowClass: the name of the application
   // szTitle: the text that appears in the title bar
   // WS_OVERLAPPEDWINDOW: the type of window to create
   // CW_USEDEFAULT, CW_USEDEFAULT: initial position (x, y)
   // 500, 100: initial size (width, length)
   // NULL: the parent of this window
   // NULL: this application does not have a menu bar
   // hInstance: the first parameter from WinMain
   // NULL: not used in this application
   HWND hWnd = CreateWindow(
      szWindowClass,
      szTitle,
      WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, CW_USEDEFAULT,
      500, 100,
      NULL,
      NULL,
      hInstance,
      NULL
   );

   if (!hWnd)
   {
      MessageBox(NULL,
         _T("Call to CreateWindow failed!"),
         _T("Windows Desktop Guided Tour"),
         NULL);

      return 1;
   }

   // The parameters to ShowWindow explained:
   // hWnd: the value returned from CreateWindow
   // nCmdShow: the fourth parameter from WinMain
   ShowWindow(hWnd,
      nCmdShow);
   UpdateWindow(hWnd);

   // Main message loop:
   MSG msg;
   while (GetMessage(&msg, NULL, 0, 0))
   {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
   }

   return (int) msg.wParam;
}

//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  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)
{
   PAINTSTRUCT ps;
   HDC hdc;
   TCHAR greeting[] = _T("Hello, Windows desktop!");

   switch (message)
   {
   case WM_PAINT:
      hdc = BeginPaint(hWnd, &ps);

      // Here your application is laid out.
      // For this introduction, we just print out "Hello, Windows desktop!"
      // in the top left corner.
      TextOut(hdc,
         5, 5,
         greeting, _tcslen(greeting));
      // End application-specific layout section.

      EndPaint(hWnd, &ps);
      break;
   case WM_DESTROY:
      PostQuitMessage(0);
      break;
   default:
      return DefWindowProc(hWnd, message, wParam, lParam);
      break;
   }

   return 0;
}

Source: docs.microsoft.com

Add Comment

1

All those coders who are working on the C++ based application and are stuck on c++ window code can get a collection of related answers to their query. Programmers need to enter their query on c++ window code related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about c++ window code for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of c++ window code while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "c++ window code". Visit this developer's friendly online web community, CodeProZone, and get your queries like c++ window code resolved professionally and stay updated to the latest C++ updates. 

C++ answers related to "c++ window code"

View All C++ queries

C++ queries related to "c++ window code"

c++ window code Visual Studio Code: code not running for C++11 glfw example window c++ render window qt design editor hide window bottom white bar qt disable resizing window how to lock window resize c++ sfml' How to block window resize sfml c++ sdl window full screen c++ create window hide terminal window c++ SFML window sliding window minimum c++ hide window c++ qt window bottom bar c++ code to print hello world how to code in c++ Simple cpp code how to compile and run cpp code in terminal gmod hitman job code tb6600 stepper motor driver arduino code code to find the last digit of a number cpp starting code is TLE means my code is correct but taking more time to computr cpp sample code bellman ford code in c++ running a c++ program in visual studio code cannot edit in read only editor dfenwick tree code c++ c++ code to write 2d array merge sort code in c++ push pop code in c++ bst traversal code in data structure with c++ quicksort in code code for bubble sort in c++ conditional variables code in c++ c++ while loop code double code in c++ ugly number code in c++ c++ check source code function return convert c++ to mips assembly code online esp32 restart from code probability code c++ dynamic programming with code implementation in c++ convert c++ code to c online snake and ladder game code in c++ download c++ code for leap year Register code c++ ask a question and answer it in code c++ c++ code 2d block code implementation of krushkals algorithm c++ rgb code easy c++ code cvtColor source code c++ how to shorten code using using c++ in class with typename c++ code c code to add two numbers bfs traversal code

Browse Other Code Languages

CodeProZone