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 / id3v1_genres.sql
Created November 3, 2013 17:52
id3v1 genres
INSERT INTO `music`.`genre`
VALUES (0, 'Blues'),
(1, 'Classic Rock'),
(2, 'Country'),
(3, 'Dance'),
(4, 'Disco'),
(5, 'Funk'),
(6, 'Grunge'),
(7, 'Hip-Hop'),
(8, 'Jazz'),
@davidglezz
davidglezz / StrTrimLeft.c
Created November 4, 2013 16:12
This function remove whitespaces from the beginning.
void StrTrimLeft(char *source, char *dest)
{
int nIndex = 0;
while (source[nIndex] == ' ')
nIndex++;
strcpy(dest, &source[nIndex]);
}
@davidglezz
davidglezz / removeQuotes.c
Last active December 27, 2015 09:39
Remove quotes from command line arguments
void removeQuotes(LPSTR szCommand)
{
int nGet = 0, nSet = 0;
while (szCommand[nGet] != '\0')
{
if (szCommand[nGet] == '\"')
nGet++;
else
{
@davidglezz
davidglezz / GetColorsBits.c
Created November 4, 2013 16:17
Get the number of color bits in the current screen device.
int GetColorsBits()
{
HDC hScreenDC = GetDC(0);
int nColorBits = GetDeviceCaps(hScreenDC, BITSPIXEL) * GetDeviceCaps(hScreenDC, PLANES);
ReleaseDC(NULL, hScreenDC);
return nColorBits;
}
@davidglezz
davidglezz / OpenFileDialog.c
Last active December 27, 2015 09:39
Display 'Open File' dialog-box in Windows
//Display 'Open File' dialog-box
BOOL OpenFileDialog(LPSTR lpFilename)
{
OPENFILENAME of;
char szFilter[] = "Music Files (*.ogg)\0*.ogg\0Image Files (*.png)\0*.png\0All files (*.*)\0*.*\0\0";
char szFile[MAX_PATH] = "\0";
char szTitle[] = "Select a file";
char szExt[] = "ogg";
of.lStructSize = sizeof(of);
@davidglezz
davidglezz / CopyEditToClipboard.c
Created November 4, 2013 16:34
Copy textbox to clipboard
// HWND of text element
void CopyEditToClipboard(HWND hWnd)
{
SendMessage(hWnd, EM_SETSEL, 0, 65535L);
SendMessage(hWnd, WM_COPY, 0 , 0);
SendMessage(hWnd, EM_SETSEL, 0, 0);
}
// Example
CopyEditToClipboard(GetDlgItem(hwndDlg, IDC_EDIT_MAIN));
@davidglezz
davidglezz / CenterWindow.c
Last active December 27, 2015 09:39
Center window
void CenterWindow(HWND hWnd)
{
RECT rcWin;
GetWindowRect(hWnd, &rcWin);
SetWindowPos(hWnd, NULL, (GetSystemMetrics(SM_CXFULLSCREEN) - (rcWin.right - rcWin.left + 1)) / 2,
(GetSystemMetrics(SM_CYFULLSCREEN) - (rcWin.bottom - rcWin.top + 1)) / 2,
0, 0, SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
}
@davidglezz
davidglezz / exp2_log2.c
Created November 4, 2013 16:39
Visual Studio doesn't have exp2 and log2
double exp2(double n)
{
return pow(2.0, n);
}
double log2(double n)
{
return log(n) / log(2.0);
}
@davidglezz
davidglezz / screenshot.c
Created November 4, 2013 16:53
make a screenshot and save it to disk. Windows
#include <windows.h>
int main()
{
int width = GetSystemMetrics(SM_CXVIRTUALSCREEN);
int height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
int top = GetSystemMetrics(SM_YVIRTUALSCREEN);
int left = GetSystemMetrics(SM_XVIRTUALSCREEN);
int size = width * height * 3;
int headerSize = sizeof(BITMAPINFOHEADER) + sizeof(BITMAPFILEHEADER);
@davidglezz
davidglezz / AssocQueryString.c
Created November 4, 2013 16:57
This example shows how to obtain the name of the program associated with file type
#include <windows.h>
#include <Shlwapi.h>
#include <stdio.h>
#pragma comment(lib, "shlwapi.lib")
char* assocStr[] =
{
"ASSOCSTR_COMMAND",
"ASSOCSTR_EXECUTABLE",
"ASSOCSTR_FRIENDLYDOCNAME",