This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
// Win32 API programs entry point | |
// 1. C might give you a hard time if you don't name the parameters | |
// 2. use __stdcall, which is an alias for WINAPI, which is an alias for APIENTRY, etc... | |
int __stdcall wWinMain( | |
// call it module, not instance (back in the days modules share multiple instances, not anymore). | |
HINSTANCE module, | |
// previous "instance", not often used | |
HINSTANCE previous, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void create_window(HINSTANCE module, LPCTSTR class_name, LPCTSTR title) { | |
// 1. filling WNDCLASS / WNDCLASSEX | |
// wc = {} and wc {.hCursor = ..., .hInstance = ...} don't work in VS2017 | |
WNDCLASS wc = {0}; | |
// Only 3 components are necessary | |
// hCursor sets the cursor for when the mouse is over the window | |
wc.hCursor = LoadCursor(nullptr, IDC_ARROW); | |
// hInstance is the handle to the module's instance | |
// and lpszClassName is the window class name. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LRESULT __stdcall window_proc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) { | |
switch(message) { | |
// calls to BeginPaint and EndPaint are still needed | |
// even when using newer rendering engines | |
case WM_PAINT: | |
{ | |
PAINTSTRUCT ps; | |
VERIFY(BeginPaint(window, &ps)); | |
EndPaint(window, &ps); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// basic version | |
void process_messages1() { | |
MSG message; | |
BOOL result; | |
// GetMessage() blocks and waits for a message | |
// returns 0 when it sees WM_QUIT | |
// returns -1 when something goes wrong | |
// returns a nonzero when there is a valid message to dispatch | |
while (result = GetMessage(&message, 0, 0, 0)) { | |
if (result != -1) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define LEN(A) (sizeof(A) / sizeof((A)[0])) | |
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) | |
// MAX3, MAX4, etc could be implented in terms of MAX, i.e. MAX((a), MAX((b), (c))) | |
#define MAX(a, b) ((a) >= (b) ? (a) : (b)) | |
// C static assert | |
// if expr is true then evaluates sizeof(char[1]) | |
// if expr is false then evaluates sizeof(char[-1]) which is undefined behavior | |
#define SASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdarg.h> # va_list, va_start, va_end | |
#include <stdio.h> # vprintf | |
#include <stdlib.h> # exit | |
void fatal(const char *format, ...) { | |
va_list args; | |
va_start(args, format); | |
printf("Fatal: "); | |
vprintf(format, args); | |
printf("\n"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
youtube-dl --extract-audio --audio-format=mp3 --output="%(title)s.%(ext)s" --batch-file="mus.txt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
youtube-dl --format=mp4 --output="%(title)s.%(ext)s" --restrict-filenames --batch-file="vid.txt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aria2c --input-file=/path/dlist.txt --seed-ratio=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ffmpeg -i input.mp3 -ss hh:mm:ss.lll -t ddd -acodec copy output.mp3 |
OlderNewer