Skip to content

Commit 569f91e

Browse files
committed
Add project files.
1 parent 372a8e7 commit 569f91e

14 files changed

+620
-0
lines changed

Bashground.sln

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25420.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Bashground", "Bashground\Bashground.vcxproj", "{338479DC-C4B1-408A-AE7F-5906EC7831F5}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Release|x64 = Release|x64
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{338479DC-C4B1-408A-AE7F-5906EC7831F5}.Debug|x64.ActiveCfg = Debug|x64
15+
{338479DC-C4B1-408A-AE7F-5906EC7831F5}.Debug|x64.Build.0 = Debug|x64
16+
{338479DC-C4B1-408A-AE7F-5906EC7831F5}.Release|x64.ActiveCfg = Release|x64
17+
{338479DC-C4B1-408A-AE7F-5906EC7831F5}.Release|x64.Build.0 = Release|x64
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

Bashground/Bashground.cpp

+198
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
// Bashground.cpp : Defines the entry point for the application.
2+
//
3+
4+
#include "stdafx.h"
5+
#include "Bashground.h"
6+
7+
#pragma comment(lib, "comctl32.lib")
8+
9+
#define MAX_LOADSTRING 100
10+
11+
// {77D1E74E-A377-4E03-943F-B686C9057A63}
12+
static const GUID NotifyIconGUID =
13+
{ 0x77d1e74e, 0xa377, 0x4e03,{ 0x94, 0x3f, 0xb6, 0x86, 0xc9, 0x5, 0x7a, 0x63 } };
14+
15+
16+
// Global Variables:
17+
HMENU hMenu;
18+
DWORD dwTaskbarCreated;
19+
WCHAR szTitle[MAX_LOADSTRING]; // The title bar text
20+
WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
21+
22+
// Forward declarations of functions included in this code module:
23+
ATOM MyRegisterClass(HINSTANCE hInstance);
24+
HWND InitInstance(HINSTANCE, int);
25+
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
26+
27+
HANDLE LaunchBash();
28+
void RegisterIcon(HWND hWnd);
29+
void DestroyIcon(HWND hWnd);
30+
31+
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
32+
_In_opt_ HINSTANCE hPrevInstance,
33+
_In_ LPWSTR lpCmdLine,
34+
_In_ int nCmdShow)
35+
{
36+
UNREFERENCED_PARAMETER(hPrevInstance);
37+
UNREFERENCED_PARAMETER(lpCmdLine);
38+
39+
// Initialize global strings
40+
LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
41+
LoadStringW(hInstance, IDC_BASHGROUND, szWindowClass, MAX_LOADSTRING);
42+
MyRegisterClass(hInstance);
43+
44+
// Perform application initialization:
45+
HWND hWnd = InitInstance(hInstance, nCmdShow);
46+
if (!hWnd)
47+
{
48+
return FALSE;
49+
}
50+
51+
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_BASHGROUND));
52+
53+
MSG msg;
54+
HANDLE hProcess = LaunchBash();
55+
if (!hProcess) {
56+
MessageBox(nullptr, _T("failed to launch bash.exe"), nullptr, 0);
57+
return 1;
58+
}
59+
RegisterIcon(hWnd);
60+
dwTaskbarCreated = RegisterWindowMessage(_T("TaskbarCreated "));
61+
62+
// Main message loop:
63+
while (GetMessage(&msg, nullptr, 0, 0))
64+
{
65+
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
66+
{
67+
TranslateMessage(&msg);
68+
DispatchMessage(&msg);
69+
}
70+
}
71+
72+
DestroyIcon(hWnd);
73+
TerminateProcess(hProcess, 0);
74+
75+
return (int)msg.wParam;
76+
}
77+
78+
HANDLE LaunchBash() {
79+
PROCESS_INFORMATION pi = { 0 };
80+
STARTUPINFO si = { 0 };
81+
si.cb = sizeof(si);
82+
TCHAR* cmdline = _tcsdup(_T("bash.exe ~"));
83+
CreateProcess(nullptr, cmdline, nullptr, nullptr, FALSE, CREATE_NO_WINDOW, nullptr, nullptr, &si, &pi);
84+
return pi.hProcess;
85+
}
86+
87+
void RegisterIcon(HWND hWnd) {
88+
NOTIFYICONDATA nid = { 0 };
89+
nid.cbSize = sizeof(nid);
90+
nid.hWnd = hWnd;
91+
nid.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
92+
nid.uCallbackMessage = WM_APP;
93+
nid.uVersion = NOTIFYICON_VERSION_4;
94+
StringCchCopy(nid.szTip, ARRAYSIZE(nid.szTip), szTitle);
95+
LoadIconMetric(GetModuleHandle(0), MAKEINTRESOURCE(IDI_SMALL), LIM_SMALL, &(nid.hIcon));
96+
Shell_NotifyIcon(NIM_ADD, &nid);
97+
}
98+
99+
void DestroyIcon(HWND hWnd) {
100+
NOTIFYICONDATA nid = { 0 };
101+
nid.cbSize = sizeof(nid);
102+
nid.hWnd = hWnd;
103+
nid.uFlags = NIF_GUID;
104+
nid.guidItem = NotifyIconGUID;
105+
Shell_NotifyIcon(NIM_DELETE, &nid);
106+
}
107+
108+
//
109+
// FUNCTION: MyRegisterClass()
110+
//
111+
// PURPOSE: Registers the window class.
112+
//
113+
ATOM MyRegisterClass(HINSTANCE hInstance)
114+
{
115+
WNDCLASSEXW wcex = { 0 };
116+
117+
wcex.cbSize = sizeof(WNDCLASSEX);
118+
119+
wcex.lpfnWndProc = WndProc;
120+
wcex.hInstance = hInstance;
121+
wcex.lpszClassName = szWindowClass;
122+
123+
return RegisterClassExW(&wcex);
124+
}
125+
126+
//
127+
// FUNCTION: InitInstance(HINSTANCE, int)
128+
//
129+
// PURPOSE: Saves instance handle and creates main window
130+
//
131+
// COMMENTS:
132+
//
133+
// In this function, we save the instance handle in a global variable and
134+
// create and display the main program window.
135+
//
136+
HWND InitInstance(HINSTANCE hInstance, int nCmdShow)
137+
{
138+
hMenu = CreatePopupMenu();
139+
MENUITEMINFO mi = { 0 };
140+
mi.cbSize = sizeof(mi);
141+
mi.fMask = MIIM_ID | MIIM_STRING;
142+
mi.wID = IDM_EXIT;
143+
mi.dwTypeData = _T("&Exit");
144+
mi.cch = (UINT)_tcslen(mi.dwTypeData);
145+
InsertMenuItem(hMenu, 0, TRUE, &mi);
146+
return CreateWindowW(szWindowClass, szTitle, 0, 0, 0, 0, 0, nullptr, nullptr, hInstance, nullptr);
147+
}
148+
149+
//
150+
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
151+
//
152+
// PURPOSE: Processes messages for the main window.
153+
//
154+
// WM_COMMAND - process the application menu
155+
// WM_PAINT - Paint the main window
156+
// WM_DESTROY - post a quit message and return
157+
//
158+
//
159+
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
160+
{
161+
POINT pt;
162+
if (message == dwTaskbarCreated) {
163+
// taskbar re-ceated, re-register taskbar icon
164+
RegisterIcon(hWnd);
165+
return 0;
166+
}
167+
switch (message)
168+
{
169+
case WM_APP:
170+
if (LOWORD(lParam) == WM_LBUTTONUP)
171+
{
172+
SetActiveWindow(hWnd);
173+
GetCursorPos(&pt);
174+
TrackPopupMenuEx(hMenu, TPM_LEFTALIGN | TPM_BOTTOMALIGN, pt.x, pt.y, hWnd, nullptr);
175+
}
176+
break;
177+
case WM_COMMAND:
178+
{
179+
int wmId = LOWORD(wParam);
180+
// Parse the menu selections:
181+
switch (wmId)
182+
{
183+
case IDM_EXIT:
184+
DestroyWindow(hWnd);
185+
break;
186+
default:
187+
return DefWindowProc(hWnd, message, wParam, lParam);
188+
}
189+
}
190+
break;
191+
case WM_DESTROY:
192+
PostQuitMessage(0);
193+
break;
194+
default:
195+
return DefWindowProc(hWnd, message, wParam, lParam);
196+
}
197+
return 0;
198+
}

Bashground/Bashground.h

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
#include "resource.h"

Bashground/Bashground.ico

45.1 KB
Binary file not shown.

Bashground/Bashground.manifest

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
3+
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
4+
<application>
5+
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
6+
</application>
7+
</compatibility>
8+
<application xmlns="urn:schemas-microsoft-com:asm.v3">
9+
<windowsSettings>
10+
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
11+
</windowsSettings>
12+
</application>
13+
<dependency>
14+
<dependentAssembly>
15+
<assemblyIdentity
16+
type="win32"
17+
name="Microsoft.Windows.Common-Controls"
18+
version="6.0.0.0"
19+
processorArchitecture="*"
20+
publicKeyToken="6595b64144ccf1df"
21+
language="*"
22+
/>
23+
</dependentAssembly>
24+
</dependency>
25+
</assembly>

Bashground/Bashground.rc

6.73 KB
Binary file not shown.

0 commit comments

Comments
 (0)