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 / 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 / mouseClick.c
Last active December 27, 2015 09:39
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 / 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 / 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 / HideWindows.c
Created November 4, 2013 18:34
Hide windows
#include <windows.h>
int main()
{
// Example: Hide all windows
while(1)
{
HWND window = GetForegroundWindow();
ShowWindow(window, false);
}
@davidglezz
davidglezz / GetComputerName.c
Created November 4, 2013 18:53
GetComputerName Example
#include <windows.h>
#include <stdio.h>
int main()
{
char buffer[256] = "";
DWORD size = sizeof(buffer);
if (GetComputerName(buffer, &size))
{
printf("ComputerName: %s\n", buffer);
@davidglezz
davidglezz / files_winapi.c
Last active December 27, 2015 10:09
Some file operations with the Windows API
#include<windows.h>
#include<iostream>
using namespace std;
// Example of file explorer
int main()
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
@davidglezz
davidglezz / GetUserNameExample.c
Created November 4, 2013 20:37
GetUserName Example
#include <windows.h>
#include <stdio.h>
int main()
{
char buffer[256] = "";
DWORD size = sizeof(buffer);
if (GetUserName(buffer, &size))
{
printf("UserName: %s\n", buffer);
@davidglezz
davidglezz / ConsoleGotoXY.c
Last active December 27, 2015 10:19
Windows Console color & position examples
#include <windows.h>
void write(HANDLE hStdout, const char* message)
{
DWORD t;
WriteConsole(hStdout, (const void*)message, lstrlen(message), &t, NULL);
}
bool gotoxy(HANDLE hStdout, unsigned short x, unsigned short y)
{
@davidglezz
davidglezz / simpleExceptions.cpp
Created November 4, 2013 22:16
Simple c++ ErrorHandler with exceptions example.
#include <iostream>
#include <string>
using namespace std;
int main()
{
int error = 0;
try
{