GitLab Commit is coming up on August 3-4. Learn how to innovate together using GitLab, the DevOps platform. Register for free: gitlabcommitvirtual2021.com

Commit 3414adf3 authored by Ken Herbert's avatar Ken Herbert
Browse files

Initial commit

parents
This diff is collapsed.
/*
* PC Name Grabber: A simple program that returns the name of the current
* PC on which the user is working.
*
* Copyright (C) 2012 Ken Herbert
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Email: firedancer.development@gmail.com
* Website: http://firedancer-software.tk
*
*/
#include <winsock.h>
#include "resource.h"
#include <stdio.h>
#include <commctrl.h>
HFONT g_hfFont = NULL;
COLORREF g_rgbText = RGB(0, 0, 0);
COLORREF g_rgbBackground = RGB(255, 255, 255);
COLORREF g_rgbCustom[16] = {0};
const char g_szClassName[] = "PCNameGrabber";
bool bInit = false;
BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case WM_DESTROY:
EndDialog(hwnd, WM_CLOSE);
break;
case IDOK:
EndDialog(hwnd, IDOK);
break;
}
break;
default:
return FALSE;
}
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
HFONT hf;
HDC hdc;
long lfHeight;
hdc = GetDC(NULL);
lfHeight = -MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72);
ReleaseDC(NULL, hdc);
hf = CreateFont(lfHeight, 0, 0, 0, 0, TRUE, 0, 0, 0, 0, 0, 0, 0, "Times New Roman");
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_FILE_EXIT:
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
case ID_HELP_WEBSITE:
ShellExecute(NULL, "open", "http://firedancer-software.tk/", NULL, NULL, SW_SHOWNORMAL);
return 0;
break;
case ID_HELP_ABOUT:
int licRet = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);
if(licRet == -1)
{
MessageBox(hwnd, "Unable to open about dialog", "Error", MB_OK | MB_ICONINFORMATION);
}
return 0;
break;
}
case WM_PAINT:
{
RECT rcClient;
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rcClient);
SetBkColor(hdc, g_rgbBackground);
SetTextColor(hdc, g_rgbText);
WSADATA wsa_data;
if (WSAStartup(MAKEWORD(2, 0), &wsa_data) != 0)
{
MessageBox (NULL, "Error starting Winsock.\r\n\r\nPC Name Grabber will now close.", "PC Name Grabber", MB_OK|MB_ICONERROR);
return 1;
}
char myhostname[256] ;
int rc = gethostname(myhostname, sizeof myhostname);
WSACleanup(); /* Cleanup Winsock */
DrawText(hdc, myhostname, -1, &rcClient, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint(hwnd, &ps);
return 0;
}
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_APPICON));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = MAKEINTRESOURCE(IDR_APPMENU);
wc.lpszClassName = g_szClassName;
wc.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_APPICON), IMAGE_ICON, 16, 16, 0);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"PC Name Grabber",
WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
NULL, NULL, hInstance, NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
Successfully builds with wxDev-C++ build 7.4.0.77
\ No newline at end of file
/*
* PC Name Grabber: A simple program that returns the name of the current
* PC on which the user is working.
*
* Copyright (C) 2012 Ken Herbert
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Email: firedancer.development@gmail.com
* Website: http://firedancer-software.tk
*
*/
// Images & Icons
#define IDI_APPICON 101
// Menu
#define IDR_APPMENU 201
// Menu Controls
#define ID_FILE_EXIT 2001
#define ID_HELP_WEBSITE 2002
#define ID_HELP_ABOUT 2003
// Dialogs
#define IDD_ABOUT 801
#define IDD_LICENCE 802
#define IDC_STATIC -1
/*
* PC Name Grabber: A simple program that returns the name of the current
* PC on which the user is working.
*
* Copyright (C) 2012 Ken Herbert
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Email: firedancer.development@gmail.com
* Website: http://firedancer-software.tk
*
*/
#include "resource.h"
IDI_APPICON ICON "PCNameGrabber.ico"
IDR_APPMENU MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "E&xit", ID_FILE_EXIT
END
POPUP "&Help"
BEGIN
MENUITEM "&Website", ID_HELP_WEBSITE
MENUITEM "&About", ID_HELP_ABOUT
END
END
IDD_ABOUT DIALOG DISCARDABLE 0, 0, 150, 130
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About PC Name Grabber"
FONT 8, "MS Sans Serif"
BEGIN
DEFPUSHBUTTON "&OK",IDOK,50,100,50,14
CTEXT "PC Name Grabber\r\nVersion 2.0.1\r\n\r\nCopyright \xa92012\r\n\r\nKen Herbert\r\n\r\nLicensed under the GNU General\r\nPublic License, version 3 (GPL-3.0)",IDC_STATIC,0,18,150,73
END
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment