Sythe.Org Forums     Register     FAQ     Members List     Calendar     Mark Forums Read    
 
Sythe.Org Forums  
   Runescape Gold

Sythe.org — A Virtual Goods Trading Hub

Make real cash! buying and selling in-game items.

We have a no-scam policy.

You can make thousands playing your favourite games here at Sythe.org.

Just sign up an account and follow the rules!


Take me to

Runescape Markets

Other Game Markets

Support Center

Register an Account

Close
Making a button create a file
Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 07-10-2010, 10:00 PM
Member
BANNED
 
Join Date: May 2010
Posts: 85
Send a message via MSN to Gfxguy
Lightbulb Making a button create a file

I want to make a button on a windows form in visual C++ express edition make a batchfile on the users desktop also i want it to ask if they would like this option to happen if you know how to do this i would very much appreciate the response!
If this isn't possible i would love for you to show me if there is different types of files such as .txt and what not files i can create
Reply With Quote
  #2  
Old 07-11-2010, 05:53 PM
Member
BANNED
 
Join Date: May 2010
Posts: 85
Send a message via MSN to Gfxguy
Default Re: Making a button create a file

So does anyone know?
Reply With Quote
  #3  
Old 07-11-2010, 07:02 PM
cp's Avatar
an cat
Mudkips Java Programmers Visual Basic Programmers Ex-Moderator
 
Join Date: Jan 2007
Location: [+]
Posts: 3,286
Default Re: Making a button create a file

Why don't you go actually learn basic C++? File writing is something you should know if you actually bothered to learn the language.
__________________
Do you like bitcoins? Do you want to buy or sell bitcoins? PM me or check out this thread.
Ex-programming mod, Ex-market mod, Ex-Head User Educator, Ex-Global Mod
Reply With Quote
  #4  
Old 07-11-2010, 10:27 PM
Guru
 
Join Date: Jun 2005
Location: Canada
Posts: 1,844
Default Re: Making a button create a file

Is this a .NET application? Because if it is I would advise to go with C# instead.

Here is an example of writting to a file with c++. Where it opens the file "test", you can specify your own filename and extension, so if you're creating a batch file you would use "test.bat".

http://www.java2s.com/Code/Cpp/File/...leofstream.htm

Hope it helps.
__________________

Reply With Quote
  #5  
Old 10-27-2010, 07:18 AM
Newcomer
 
Join Date: Dec 2009
Posts: 13
Default Re: Making a button create a file

To be compiled with visual C++ 2008 and above

Code:
#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;
}

Last edited by Ashken : 12-10-2011 at 09:57 PM. Reason: code tags & slight modifications
Reply With Quote
  #6  
Old 10-27-2010, 03:46 PM
Govind's Avatar
Hero
Highly Respected Highly Trusted Sythe Verified User
 
Join Date: Apr 2005
Posts: 7,068
Default Re: Making a button create a file

Button presses are trapped by comparing (HWND)lParam to the button handle; I've never known wParam to work for it.

Code:
case WM_COMMAND:
if((HWND)lParam==hButton)
{
//writefile
}
Though honestly if you're a newcomer, stay away from Win32 until you learn the language itself. It's a very steep learning curve.

Last edited by SMR : 10-27-2010 at 03:52 PM.
Reply With Quote
  #7  
Old 10-27-2010, 04:10 PM
Newcomer
 
Join Date: Dec 2009
Posts: 13
Default Re: Making a button create a file

Yep wparam does work too.no matter how much we try it is almost impossible to know everything about a particular language or framework.You are right there is still a lot i don't know about C++, especially algorithms but what i know is enough to get me playing with the big boys' toys.
Reply With Quote
  #8  
Old 10-27-2010, 04:14 PM
Govind's Avatar
Hero
Highly Respected Highly Trusted Sythe Verified User
 
Join Date: Apr 2005
Posts: 7,068
Default Re: Making a button create a file

No, that 'beginner' advice/comment was directed to the author of this thread, not you
Reply With Quote
  #9  
Old 10-27-2010, 05:10 PM
Newcomer
 
Join Date: Dec 2009
Posts: 13
Default Re: Making a button create a file

either way it applies to me too!! good advice,i should wind up on C++ lest i shoot myself in the foot.
Reply With Quote
Reply



Cheap RS Gold Store  Runescape Gold

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

All times are GMT +1. The time now is 05:16 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.6.1