Thread: How do I turn this C++ into a win32 c++ app?

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    35

    How do I turn this C++ into a win32 c++ app?

    PHP Code:
    #include <iostream>
    #include <fstream>
    #include <cstring>

    using namespace std;

    int main()
    {
        
    string r_place;
        
    string word;
        
        
    ifstream f_in("example.txt");//open file to READ
        
        
    cout<<"Enter word you wish to replace"<<endl;
        
    cin>>word;
        
    cin.ignore();
        
        
    int size word.length();//find the length of the word
        
        
    cout<<"Enter word you wish to replace it with"<<endl;
        
    getline(cin,r_place,'\n');
        
        
    cin.ignore();
        
    cout<<"\n\n";
        
        
        
    string search;
        
    ofstream f_out("update.txt");//open file to WRITE
        
        
    while(getline(f_insearch'\n'))//read in a line
        
    {
            
           
        
    string::size_type pos = -1;
        while( ( 
    pos search.find(wordpos+1) ) != string::npos )
        {
            
    search.replace(pos,size,r_place);
            
    //search.erase( (search.begin() + pos), (search.begin() + (pos + size)) );
            //search.insert( pos, r_place );
        
    }
        
    f_out << search << endl;//Write to file
            
            
        
    }
        
    f_in.close(); //close file (reading)
        
    f_out.close(); //close file (writing)
        
    cin.get();
        
        

    How do I put this in a application (Borland c++ 6) with forms (win32).

    For example I have a tick box and if you tick it, and you click a button it finds a code thats linked to the tickbox in an external file and replaces it with a text (also linked to the tick box).

  2. #2
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Well do you know how to create a window yet?
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    35
    Yes.

  4. #4
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Ok, then you will be able to understand my code, or hopefully. I know I got a bit carried away and went and wrote the whole thing in Win32 for you, but here it is. Attached:

    EDIT: Oh yeah, sorry about the comments. I started commenting the code but then I just got carried away and forgot to comment the rest. I hope it's easy enough to figure out though.
    Last edited by jmd15; 11-02-2005 at 04:33 PM.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  5. #5
    Registered User
    Join Date
    Sep 2005
    Posts
    35
    Wow Thanks!!! Works like a dream!!!

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    35
    I'm going to be in prague tomorrow till sunday so I'll only be online again on monday so if I get stuck editting, thats when you'll here me screaming for help. :P

  7. #7
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Glad I could help. I will answer your questions, when you get back. You are going to Prague, as in the capital of the Czech Republic?
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  8. #8
    Registered User
    Join Date
    Sep 2005
    Posts
    35
    Quote Originally Posted by jmd15
    Glad I could help. I will answer your questions, when you get back. You are going to Prague, as in the capital of the Czech Republic?
    Yep, thats the place

  9. #9
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Code:
    #include <windows.h>
    #include <stdio.h>
    #include <string>
    #include <algorithm>
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
    char szClassName[ ] = "WindowsApp",word[256],r_place[256],*words;
    std::string sword,sr_place;
    HWND static1,static2,edit1,edit2,button;
    char happy[256];
    FILE * pFile;
    int size;
    int WINAPI WinMain (HINSTANCE hThisInstance,HINSTANCE hPrevInstance,
                        LPSTR lpszArgument,int nFunsterStil){
        HWND hwnd;
        MSG messages;
        WNDCLASSEX wincl;
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;
        wincl.style = CS_DBLCLKS;
        wincl.cbSize = sizeof (WNDCLASSEX);
        wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
        wincl.lpszMenuName = NULL;
        wincl.cbClsExtra = 0;
        wincl.cbWndExtra = 0;
        wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
        if (!RegisterClassEx (&wincl))
            return 0;
        hwnd = CreateWindowEx (0,szClassName,"Windows App",WS_OVERLAPPEDWINDOW,
               CW_USEDEFAULT,CW_USEDEFAULT,500,250,HWND_DESKTOP,NULL,
               hThisInstance,NULL);
        ShowWindow (hwnd, nFunsterStil);
        while (GetMessage (&messages, NULL, 0, 0)){
            TranslateMessage(&messages);
            DispatchMessage(&messages);
        }
        return messages.wParam;
    }
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
        switch (message){
            case WM_CREATE:
                static1=CreateWindowEx(0,"Static","Replace",WS_CHILD|WS_VISIBLE,20,
                    20,60,25,hwnd,(HMENU)50000,GetModuleHandle(NULL),NULL);
                edit1=CreateWindowEx(0,"Edit","",WS_BORDER|WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL,80,
                    18,100,22,hwnd,(HMENU)50001,GetModuleHandle(NULL),NULL);
                static2=CreateWindowEx(0,"Static","with",WS_CHILD|WS_VISIBLE,190,
                    20,30,25,hwnd,(HMENU)50002,GetModuleHandle(NULL),NULL);
                edit2=CreateWindowEx(0,"Edit","",WS_BORDER|WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL,225,
                    18,100,22,hwnd,(HMENU)50003,GetModuleHandle(NULL),NULL);
                button=CreateWindowEx(0,"Button","Replace",WS_BORDER|WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,335,
                    18,70,22,hwnd,(HMENU)50004,GetModuleHandle(NULL),NULL);
                SendMessage(edit1,EM_LIMITTEXT,256,0);
                SendMessage(edit2,EM_LIMITTEXT,256,0);
                break;
            case WM_COMMAND:
                switch(wParam){
                case 50004:
                    GetWindowText(edit1,word,256);
                    GetWindowText(edit2,r_place,256);
                    sword=word;
                    sr_place=r_place;
                    size=sword.length();
                    if(size==0){
                    MessageBox(hwnd,"You must specify the word to replace","Problem",MB_OK|MB_ICONINFORMATION);
                    }
                    else{
                    std::string search,add;
                    pFile = fopen ("update.txt" , "r");
                    while(fgets(happy,1500,pFile)){
                    search=happy;
                    std::string::size_type pos = -1;
                    while((pos=search.find(sword,pos+1))!=std::string::npos){ 
                    search.replace(pos,size,sr_place);
                    }
                    add+=search+"\n";
                    }
                    fclose(pFile);
                    pFile = fopen ("update.txt" , "w+");
                    *(std::copy(add.begin(), add.end() - add.begin() < 256 ? add.end() : add.begin() + 255, happy)) = 0;
                    fputs(happy,pFile);
                    fclose(pFile);
                    }
                }
                break;
            case WM_DESTROY:
                PostQuitMessage (0);
                break;
            default:
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
        return 0;
    }
    Well, I did it with stdio.h functions...

  10. #10
    Registered User
    Join Date
    Sep 2005
    Posts
    35
    Hmm, How do I open the form view in c++ (borland 6)

  11. #11
    Registered User
    Join Date
    Sep 2005
    Posts
    35
    Anyone?

  12. #12
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Sorry, I use Dev-C++. I personally dislike Borland products, but that's just me.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  13. #13
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    I use Dev-C++ but I dont like the resource editor, are there any good ones freeware?

  14. #14
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Quote Originally Posted by bumfluff
    I use Dev-C++ but I dont like the resource editor, are there any good ones freeware?
    MinGW Studio is the only freeware IDE I can think of that has an integrated visual resource editor.

  15. #15
    Registered User
    Join Date
    Sep 2005
    Posts
    35
    Quote Originally Posted by jmd15
    Sorry, I use Dev-C++. I personally dislike Borland products, but that's just me.
    Ahh ok, I'll try that

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adding a console window to a Win32 app
    By VirtualAce in forum Game Programming
    Replies: 7
    Last Post: 02-01-2009, 01:09 PM
  2. Help with win32 app
    By kwm32 in forum C++ Programming
    Replies: 3
    Last Post: 03-18-2004, 04:54 PM
  3. confusion win32 -console app
    By GanglyLamb in forum C Programming
    Replies: 2
    Last Post: 06-11-2003, 10:12 AM
  4. win32 and consele app.
    By master2000 in forum C++ Programming
    Replies: 5
    Last Post: 12-22-2002, 11:50 AM
  5. Is it possible to get a console up with a win32 app?
    By SilentStrike in forum Windows Programming
    Replies: 2
    Last Post: 12-18-2001, 05:15 PM