Skip to content

Instantly share code, notes, and snippets.

@daryo918
Created April 29, 2013 22:13
Show Gist options
  • Save daryo918/5485229 to your computer and use it in GitHub Desktop.
Save daryo918/5485229 to your computer and use it in GitHub Desktop.
ping gui windows
#include <windows.h>
#include <cstdio>
#include <cstring>
#include <iostream>
int MN_MENSAJE=1024;
int MN_SALIR=1025;
HINSTANCE miinstance;
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
/* Make the class name into a global variable */
char szClassName[ ] = "CodeBlocksWindowsApp";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
miinstance=hThisInstance;
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
wincl.hbrBackground = (HBRUSH)CreateSolidBrush(RGB(239,239,239));
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Ping", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
275, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (hwnd, nCmdShow);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
const int MN_MENSAJE=1025;
HMENU menu=CreateMenu();
HMENU submenu=CreateMenu();
switch (message) /* handle the messages */
{
case WM_CREATE:
AppendMenu(submenu,MF_STRING,MN_MENSAJE,"&creditos");
AppendMenu(menu,MF_STRING|MF_POPUP,(UINT)submenu,"&Acerca de");
SetMenu(hwnd,menu);
static HFONT hFont = CreateFont(14, 0, 0, 0, 100, 0, 0, 0,0, 0, 0, 0, VARIABLE_PITCH | FF_SWISS, "Helv");
static HWND texto = CreateWindowEx(0,"STATIC", "Inserte la ip:", WS_CHILD|WS_VISIBLE, 0, 0, 90, 25, hwnd, 0, miinstance, NULL);
static HWND campo = CreateWindowEx(0,"EDIT", "", WS_CHILD|WS_VISIBLE, 0, 45, 105, 12, hwnd, 0, miinstance, NULL);
static HWND boton = CreateWindowEx(NULL,"BUTTON","hacer ping",WS_CHILD|WS_VISIBLE|WS_TABSTOP,110,42,100,20,hwnd,0,miinstance,NULL);
static HWND text2 = CreateWindowEx(0,"STATIC", "Salida del comando:", WS_CHILD|WS_VISIBLE, 250, 0, 130, 25, hwnd, 0, miinstance, NULL);
static HWND text3 = CreateWindowEx(0,"STATIC", " ", WS_CHILD|WS_VISIBLE, 250, 30, 230, 225, hwnd, 0, miinstance, NULL);
SendMessage(texto,WM_SETFONT,(WPARAM)hFont,true);
SendMessage(boton,WM_SETFONT,(WPARAM)hFont,true);
SendMessage(campo, WM_SETFONT, (WPARAM) hFont, true);
SendMessage(text2, WM_SETFONT, (WPARAM) hFont, true);
SendMessage(text3, WM_SETFONT, (WPARAM) hFont, true);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case MN_MENSAJE:
MessageBox(hwnd,"codeado por daryo","creditos",MB_OK);
break;
}
if((HWND)lParam==boton)
{
FILE *in;
char ip[100];
char ping[200]="ping ";
char n[700];
char string[700]=" ";
GetWindowText(campo, ip, 255);
if (strcmp(ip,"")!=0)
{
strcat(ping,ip);
in=popen(ping,"r");
while ( fgets(n, 700, in) != NULL )
{
strcat(string,n);
}
SendMessage(text3, WM_SETTEXT, false, (long int) string);
}
else{
MessageBox(hwnd,"no escribio ip","ip lol",MB_OK);
}
}
break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment