Skip to content

Instantly share code, notes, and snippets.

View davidglezz's full-sized avatar
😃
Happy

David Gonzalez davidglezz

😃
Happy
View GitHub Profile
@davidglezz
davidglezz / Sync-Async_CreateProcess.c
Created November 4, 2013 23:14
Asynchronous & Synchronous process
#include <windows.h>
#include <stdio.h>
static HANDLE myCreateProcess(TCHAR* cmd, BOOL sync)
{
PROCESS_INFORMATION ProcInfo = {0};
STARTUPINFO StartUp = {sizeof(STARTUPINFO)};
if (CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &StartUp, &ProcInfo))
{
@davidglezz
davidglezz / GetKeyState_Example1.cpp
Created November 4, 2013 23:19
GetKeyState Example
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
bool shift = !!(GetKeyState(VK_SHIFT) & 0x8000);
cout << hex;
while (!( GetKeyState(VK_F7) & 0x8000 ))
@davidglezz
davidglezz / LaunchScreensaver.c
Created November 5, 2013 10:52
Launch Screensaver
#include <windows.h>
int main()
{
SendMessage(GetForegroundWindow(), WM_SYSCOMMAND, SC_SCREENSAVE, 0);
}
@davidglezz
davidglezz / MCI_audioPLayerClass.cpp
Created November 5, 2013 10:54
Simple mp3 player class using MCI
#include <windows.h>
#include <iostream>
#include <string>
enum mode {unknown, open, playing, paused, stopped };
class MCI
{
// davidxl.blogspot.com
private:
@davidglezz
davidglezz / HotKeys.c
Created November 5, 2013 11:17
HotKeys demo
#include <windows.h>
#define CTRL_ALT_F1 101
#define CTRL_F2 102
#define ALT_F3 103
#define CTRL_UP 104
#define CTRL_DOWN 105
#define CTRL_RIGHT 106
#define CTRL_LEFT 107
#define EXIT_KEYS 108
@davidglezz
davidglezz / GetSetCursorPos.c
Created November 5, 2013 11:29
Get & Set Cursor position
#include <stdio.h>
#include <windows.h>
int main()
{
// GetCursorPos
puts("Press F8 to next example\n");
POINT p;
while(!GetAsyncKeyState(VK_F8))
{
@davidglezz
davidglezz / sndPlaySound.c
Created November 5, 2013 11:45
Simple PlaySound (wav files) Example
#include <windows.h>
#include <mmsystem.h>
#include <stdio.h>
int main()
{
sndPlaySound("file.wav", SND_ASYNC | SND_FILENAME | SND_LOOP);
getchar();
return 0;
}
@davidglezz
davidglezz / TurnOffMonitor.c
Created November 5, 2013 11:56
Turn off monitor
#include <windows.h>
#define MONITOR_ON -1
#define MONITOR_OFF 2
#define MONITOR_STANBY 1
int main()
{
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF);
}
@davidglezz
davidglezz / ispow2.c
Created November 5, 2013 11:59
ispow2 function
bool ispow2(int x)
{
return !((~(~0U>>1)|x)&x -1) ;
}
@davidglezz
davidglezz / utf16_to_utf8.c
Created January 13, 2014 23:11
utf16_to_utf8 function, untested by me, but I hope it works well, comes from opusfile with some modifications.
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
static char* utf16_to_utf8 (const wchar_t *src)
{
size_t len = wcslen(src), si, di;
char *dst = (char*)malloc(sizeof(*dst)*(3*len+1));