-
Notifications
You must be signed in to change notification settings - Fork 0
/
backgroundImageDeleter.cpp
204 lines (171 loc) · 5.26 KB
/
backgroundImageDeleter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// Joe Noonan
// backgroundImageDeleter.cpp
// PURPOSE: This is the main file to run the application window and processes.
// compile with: /D_UNICODE /DUNICODE /DWIN32 /D_WINDOWS /c
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
#include <fstream>
#include <stdio.h>
#include "resource.h"
using namespace std;
// The main window class name.
static TCHAR szWindowClass[] = _T("DesktopApp");
// The string that appears in the application's title bar.
static TCHAR szTitle[] = _T("Background Image Deleter");
//Icon that the delete button will display
HWND button;
static HICON hIcon;
HINSTANCE hInstance = GetModuleHandle(NULL);
HINSTANCE hInst;
// Forward declarations of functions included in this code module:
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
//Prototype for finding the file path of the the cached background image:
//string getFilepath();
//Prototype for deleting a system file (background image in this case):
BOOL WINAPI DeleteFile(
_In_ LPCTSTR lpFileName
);
int CALLBACK WinMain(
_In_ HINSTANCE hInstance,
_In_ HINSTANCE hPrevInstance,
_In_ LPSTR lpCmdLine,
_In_ int nCmdShow
)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = CreateSolidBrush(RGB(255, 0, 0)); // Paint background red
//wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, IDI_APPLICATION);
if (!RegisterClassEx(&wcex))
{
MessageBox(NULL,
_T("Call to RegisterClassEx failed!"),
_T(" "),
NULL);
return 1;
}
// Store instance handle in our global variable
hInst = hInstance;
// The parameters to CreateWindow explained:
// szWindowClass: the name of the application
// szTitle: the text that appears in the title bar
// WS_OVERLAPPEDWINDOW: the type of window to create
// 1407, 0: initial position (x, y) (top right of screen). Can't figure out how to put it in top right all the time.
// 100, 75: initial size (width, length)
// NULL: the parent of this window
// NULL: this application does not have a menu bar
// hInstance: the first parameter from WinMain
// NULL: not used in this application
HWND hWnd = CreateWindow(
szWindowClass,
szTitle,
WS_OVERLAPPEDWINDOW,
1407, 0,
100, 77,
NULL,
NULL,
hInstance,
NULL
);
if (!hWnd)
{
MessageBox(NULL,
_T("Call to CreateWindow failed!"),
_T(" "),
NULL);
return 1;
}
// The parameters to ShowWindow explained:
// hWnd: the value returned from CreateWindow
// nCmdShow: the fourth parameter from WinMain
ShowWindow(hWnd,
nCmdShow);
UpdateWindow(hWnd);
// Main message loop:
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
TCHAR greeting[] = _T("");//Could enter a user message here if desired.
switch (message)
{
case WM_CREATE:
button = CreateWindow(TEXT("button"), TEXT("DELETE"),
WS_VISIBLE | WS_CHILD | BS_FLAT | BS_ICON,
5, 5, 38, 28, hWnd, (HMENU) 1, NULL, NULL
);
hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1)); //Find out how to have button fill the whole button space.
SendMessage(button, BM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)hIcon);
button = CreateWindow(TEXT("button"), TEXT("DELETE"),
WS_VISIBLE | WS_CHILD | BS_FLAT | BS_ICON,
77, 5, 38, 28, hWnd, (HMENU)1, NULL, NULL
);
hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1)); //Find out how to have button fill the whole button space.
SendMessage(button, BM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)hIcon);
case WM_COMMAND:
if (LOWORD(wParam) == 1) {
//ADD THE CODE FOR DELETING THE PHOTO HERE:
//Possible method for deletion using image comparison and cached image:
// Steps for method 1:
// #1)Use a vbs script that returns the file path for the currently displayed image.
// #2) Pass the file path to the DeleteFile function.
// #3) See if this works then see if Windows OS automaticall moves to the next image avaiable or if I have to write code for that transition.
//Function call for DeleteFile function if the vbsa script gives us the file destination
}
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
//Prints a message to the screen if desired
TextOut(hdc,
5, 5,
greeting, _tcslen(greeting));
// End application-specific layout section.
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
break;
}
return 0;
}
/*
//instead of pipe i could use fork
string getFilepath() {
char* args[] = {"./Win8_WP_Curr_Image_Name.vbs", NULL};
string VBSScriptOutput = "";
pid_t pid = fork();
if (pid == -1)
perror("fork() failed");
if (pid > 0) {
VBSScriptOutput = execvp(args[0], args);
}
}
*/