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 / IsElevated.c
Created November 4, 2013 18:27
This function check that your app is elevated
#include <stdio.h>
#include <windows.h>
// If have compile errors:
// Replace TokenElevation by (TOKEN_INFORMATION_CLASS)20
// Uncomment next struct
/*
typedef struct _TOKEN_ELEVATION {
DWORD TokenIsElevated;
} TOKEN_ELEVATION, *PTOKEN_ELEVATION;
@davidglezz
davidglezz / GetFolder.c
Created November 4, 2013 18:01
Get executable folder
#include <windows.h>
#include <stdio.h>
// Get Current Folder
void GetFolder(char *folderName)
{
GetModuleFileName(GetModuleHandle(NULL), folderName, MAX_PATH);
*(strrchr(folderName, '\\')) = 0;
}
@davidglezz
davidglezz / mouseClick.c
Last active October 12, 2024 23:22
Example of how to simulate a mouse click
#include <windows.h>
int main()
{
//allocate a data
INPUT *data = new INPUT[3];
// Move to position. data
data->type = INPUT_MOUSE;
data->mi.dx = 0; // Position x
@davidglezz
davidglezz / HideCursor.c
Created November 4, 2013 17:06
Hides the cursor on a window. Even the titlebar
// Hide cursor
LRESULT CALLBACK dialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
// put this in your dialogProc
case WM_SETCURSOR:
SetCursor(NULL);
return TRUE;
@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",
@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 / 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 / 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 / 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 / OpenFileDialog.c
Last active October 12, 2024 23:23
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);