#include <windows.h>
#include <shlobj.h>
#include <fstream>
#include <cstdlib>
using namespace std;
#define BTN 0
char name[]="app";
char path[MAX_PATH];
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HWND hwnd;
HWND button;
HINSTANCE hInst;
ofstream out;
int file(HWND);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpstr,int cmd)
{
WNDCLASSEX wc;
MSG msg;
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = name;
wc.style = 0;
wc.cbSize = sizeof(WNDCLASSEX);
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.lpszMenuName =0;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground =(HBRUSH)(COLOR_BTNFACE+1);
if(!RegisterClassEx(&wc))
{
MessageBox(hwnd,"Window Class Registration Failed!\nThis Application Requires Windows NT and above","Error",MB_OK);
return 1;
}
hwnd = CreateWindowEx(
0,
name,
"Ashken",
WS_OVERLAPPEDWINDOW&~(WS_MAXIMIZEBOX|WS_THICKFRAME),
CW_USEDEFAULT,
CW_USEDEFAULT,
150,
100,
0,
NULL,
hInstance,
NULL
);
ShowWindow(hwnd,cmd);
while(GetMessage(&msg,NULL,0,0)>0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam)
{
switch(message)
{
case WM_CREATE:
button = CreateWindow("button","OK",BS_PUSHBUTTON|WS_TABSTOP|WS_CHILD|WS_VISIBLE,30,20,80,30,hwnd,(HMENU)BTN,hInst,0);
break;
case WM_COMMAND:
switch(wparam)
{
case BTN:
file(hwnd);
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wparam,lparam);
}
return 0;
}
int file(HWND hwnd)
{
SHGetSpecialFolderPath(hwnd,path,CSIDL_DESKTOPDIRECTORY,FALSE);
//Name & extension of the file
char fname[MAX_PATH]="\\file.bat";
strcat(path,fname);
out.open(path);
if(!out.is_open())
{
MessageBox(hwnd,path,"Could not create File",MB_OK|MB_ICONERROR);
return 1;
}
//The contents of the File
out<<"echo This is the file created!!!\n\npause";
out.close();
MessageBox(hwnd, path, "File Created at", MB_OK | MB_ICONINFORMATION);
ShellExecute(NULL,"open",path,0,0,SW_NORMAL);
return 0;
}