#include <windows.h>
#include <tlhelp32.h>
LRESULT CALLBACK MainWndProc (HWND, UINT, WPARAM, LPARAM);
VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime);
char szClassName[ ] = "testClass";
int stop;
UINT_PTR timerid;
HWND hbtn;
WNDCLASSEX wincl = {sizeof(WNDCLASSEX),CS_HREDRAW | CS_VREDRAW,MainWndProc,0,0,0,0,0,(HBRUSH) COLOR_BACKGROUND,NULL,szClassName,0};
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hwnd; /* This is the handle for our window */
MSG msg; /* Here messages to the application are saved */
wincl.hInstance = hThisInstance;
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"test", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
100, /* The programs width */
100, /* 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 */
);
ShowWindow (hwnd, nCmdShow);
UpdateWindow (hwnd);
while (GetMessage (&msg, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&msg);
/* Send message to WindowProcedure */
DispatchMessage(&msg);
}
return msg.wParam;
UNREFERENCED_PARAMETER(lpCmdLine);
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK MainWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
{
hbtn = CreateWindowEx(0,"BUTTON","start",WS_VISIBLE | WS_CHILD, 10, 10,75,25, hwnd, (HMENU)1, wincl.hInstance, 0);
}
break;
case WM_COMMAND:
if ( LOWORD (wParam) ==1)
{
if (!stop) {
SendMessage(hbtn,WM_SETTEXT,0,(LPARAM)"Stop");
timerid = SetTimer(0, 0, 30000, (TIMERPROC)TimerProc);
}
else {
SendMessage(hbtn,WM_SETTEXT,0,(LPARAM)"Start");
KillTimer(0,timerid);
}
stop = !stop;
}
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD
dwTime )
{
int runs = FALSE;
PROCESSENTRY32 pentry;
pentry.dwSize = sizeof(PROCESSENTRY32);
HANDLE hsnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
Process32First(hsnap,&pentry);
do
{
if (strcmp(pentry.szExeFile,"REGEDIT.EXE") == 0) {
runs = TRUE;
break;
}
runs = FALSE;
}while (Process32Next(hsnap,&pentry));
if (runs == FALSE) {
ShellExecute(0,"OPEN","C:\\WINDOWS\\REGEDIT.EXE",0,0,SW_SHOWNORMAL);
}
}