#include <Windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
  WNDCLASSEX winClass;
  HWND hwnd;
  MSG msg;

  // Process command line
  LPWSTR *argv = NULL;
  int argc;
  int i;
  unsigned short tilingMode = DEFAULT_TILING_MODE;

  argv = CommandLineToArgvW(GetCommandLineW(), &argc);

  for (i = 0; i < argc; i++) {
    char arg[128];
    wsprintfA(arg, "%S", argv[i]);

    if (i < (argc - 1)) {
      char nextarg[128];
      wsprintfA(nextarg, "%S", argv[i + 1]);

      if (!strcmp(arg, "-o")) {
        alpha = atoi(nextarg);
      } else if (!strcmp(arg, "-i")) {
        if (ignoreCount < MAX_IGNORE) {
          sprintf(ignoreClasses[ignoreCount++], "%s", nextarg);
        }
      } else if (!strcmp(arg, "-a")) {
        include_mode = 1; // Include mode instead of exclude

        if (includeCount < MAX_IGNORE) {
          sprintf(includeClasses[includeCount++], "%s", nextarg);
        }
      } else if (!strcmp(arg, "-m")) {
        int y;
        modkeys = 0;

        for (y = 0; y < strlen(nextarg); y++) {
          switch (nextarg[y])
          {
            case 'c':
              modkeys |= MOD_CONTROL;
              break;
            case 'a':
              modkeys |= MOD_ALT;
              break;
            case 's':
              modkeys |= MOD_SHIFT;
              break;
            case 'w':
              modkeys |= MOD_WIN;
              break;
          }
        }
      } else if (!strcmp(arg, "-t")) {
        tilingMode = atoi(nextarg);
      } else if (!strcmp(arg, "-left")) {
        screen_x = atoi(nextarg);
      } else if (!strcmp(arg, "-top")) {
        screen_y = atoi(nextarg);
      } else if (!strcmp(arg, "-width")) {
        screen_width = atoi(nextarg);
      } else if (!strcmp(arg, "-height")) {
        screen_height = atoi(nextarg);
      }
    }
    if (!strcmp(arg, "-v")) {
      MessageBox(NULL, VERSION, "Version", MB_OK);
      LocalFree(argv);
      return 1;
    } else if (!strcmp(arg, "-l")) {
      lockMouse = 1;
    } else if (!strcmp(arg, "-x")) {
      experimental_mouse = 1;
    } else if (!strcmp(arg, "--one-tag")) {
      one_tag_per_window = 1;
    }
  }

  // Initialize tags
  for (i = 0; i < TAGS; i++) {
    tags[i].nodes = NULL;
    tags[i].last_node = NULL;
    tags[i].current_window = NULL;
    tags[i].tilingMode = tilingMode;
    tags[i].masterarea_count = 1;
  }

  LocalFree(argv);

  winClass.cbSize = sizeof(WNDCLASSEX);
  winClass.style = 0;
  winClass.lpfnWndProc = WndProc;
  winClass.cbClsExtra = 0;
  winClass.cbWndExtra = 0;
  winClass.hInstance = hInstance;
  winClass.hIcon = NULL;
  winClass.hIconSm = NULL;
  winClass.hCursor = NULL;
  winClass.hbrBackground = NULL;
  winClass.lpszMenuName = NULL;
  winClass.lpszClassName = NAME;

  if (!RegisterClassEx(&winClass)) {
    MessageBox(NULL, "Error Registering Window Class", "Error", MB_OK | MB_ICONERROR);
    return 0; // Bail
  }

  hwnd = CreateWindowEx(0, NAME, NAME, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, hInstance, NULL);

  if (!hwnd) {
    MessageBox(NULL, "Error Creating Window", "Error", MB_OK | MB_ICONERROR);
    return 0; // Bail
  }

  if (!screen_x && !screen_y && !screen_width && !screen_height) { // Screen options aren't being specified from the command line so set some defaults
    RECT workarea;
    SystemParametersInfo(SPI_GETWORKAREA, 0, &workarea, 0);
    screen_x = workarea.left;
    screen_y = workarea.top;
    screen_width = workarea.right - workarea.left;
    screen_height = workarea.bottom - workarea.top;
  }

  RegisterHotkeys(hwnd);
  UpdateMousePos(hwnd);

  EnumWindows(EnumWindowsRestore, 0); // Restore windows on startup so they get tiled
  EnumWindows(EnumWindowsProc, 0);

  ArrangeWindows();

  // Get function pointer for RegisterShellHookWindow
  if ( RegisterShellHookWindow_ == NULL )
  {
    RegisterShellHookWindow_ = (BOOL (__stdcall *)(HWND))GetProcAddress(GetModuleHandle("USER32.DLL"), "RegisterShellHookWindow");
    if (RegisterShellHookWindow_ == NULL) {
      MessageBox(NULL, "Could not find RegisterShellHookWindow", "Error", MB_OK | MB_ICONERROR);
      return 0;
    }
  }

  RegisterShellHookWindow_(hwnd);
  shellhookid = RegisterWindowMessage("SHELLHOOK"); // Grab a dynamic id for the SHELLHOOK message to be used later

  while (GetMessage(&msg, NULL, 0, 0) > 0)
  {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }

  return msg.wParam;
} 

C++ Online Compiler

Write, Run & Share C++ code online using OneCompiler's C++ online compiler for free. It's one of the robust, feature-rich online compilers for C++ language, running on the latest version 17. Getting started with the OneCompiler's C++ compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as C++ and start coding!

Read inputs from stdin

OneCompiler's C++ online compiler supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample program which takes name as input and print your name with hello.

#include <iostream>
#include <string>
using namespace std;

int main() 
{
    string name;
    cout << "Enter name:";
    getline (cin, name);
    cout << "Hello " << name;
    return 0;
}

About C++

C++ is a widely used middle-level programming language.

  • Supports different platforms like Windows, various Linux flavours, MacOS etc
  • C++ supports OOPS concepts like Inheritance, Polymorphism, Encapsulation and Abstraction.
  • Case-sensitive
  • C++ is a compiler based language
  • C++ supports structured programming language
  • C++ provides alot of inbuilt functions and also supports dynamic memory allocation.
  • Like C, C++ also allows you to play with memory using Pointers.

Syntax help

Loops

1. If-Else:

When ever you want to perform a set of operations based on a condition If-Else is used.

if(conditional-expression) {
   //code
}
else {
   //code
}

You can also use if-else for nested Ifs and If-Else-If ladder when multiple conditions are to be performed on a single variable.

2. Switch:

Switch is an alternative to If-Else-If ladder.

switch(conditional-expression){    
case value1:    
 // code    
 break;  // optional  
case value2:    
 // code    
 break;  // optional  
......    
    
default:     
 code to be executed when all the above cases are not matched;    
} 

3. For:

For loop is used to iterate a set of statements based on a condition.

for(Initialization; Condition; Increment/decrement){  
  //code  
} 

4. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while (condition) {  
// code 
}  

5. Do-While:

Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.

do {  
 // code 
} while (condition); 

Functions

Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity. Function gets run only when it is called.

How to declare a Function:

return_type function_name(parameters);

How to call a Function:

function_name (parameters)

How to define a Function:

return_type function_name(parameters) {  
 // code
}