Results 1 to 10 of 10

Thread: Input from a File

  1. #1

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Post Input from a File

    PHP Code:
    //Sviesoft Corporation(r)
    //Copyright(c) 1999 - 2001
    //All Rights Reserved
    //
    //Thanks to God, my Mom and the people
    //that have supported me all these years
    //
    //God Bless you all, Amen

    //////////////////////////////////////////////////
    //MONEY DISTRIBUTOR DATABASE FOR CHRISTIAN CAMP//
    ////////////////////////////////////////////////
    //PROVIDED BY TOM ZHANG

    #include <windows.h>
    #include <iostream>
    #include <fstream>
    using namespace std;
    const 
    char tzID[]="myWindowClass";
    char distributoR[MAX_PATH];
    char datA[MAX_PATH];
    HINSTANCE hInst;
    HWND LABEL1;
    #define BUT1 1
    #define TEX1 2
    LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam){
        
    ofstream PO("distributor.dis");
        
    ifstream PP("distributor.dis");
        switch(
    msg){
        case 
    WM_SHOWWINDOW:
    CHECKDATA:if(!PP.is_open()){MessageBox(hwnd,"Error while trying to get the DataBase file","",0);exit (1);}while(!PP.eof()){PP.getline(datA,MAX_PATH);}
              break;
        case 
    WM_CREATE:
            
    LABEL1=CreateWindow("Static","Please Enter your name, Distributor",WS_CHILD|WS_VISIBLE,0,0,400,30,hwnd,NULL,hInst,NULL);
            
    CreateWindowEx(NULL,"button","Distribute",WS_CHILD|WS_VISIBLE,190,100,110,20,hwnd,(HMENU)BUT1,hInst,NULL);
            
    CreateWindowEx(NULL,"edit","",WS_CHILD|WS_VISIBLE,10,100,170,20,hwnd,(HMENU)TEX1,hInst,NULL);
            break;
        case 
    WM_CLOSE:
            
    DestroyWindow(hwnd);
            break;
        case 
    WM_DESTROY:
            
    PostQuitMessage(0);
            break;
        case 
    WM_COMMAND:
            switch(
    LOWORD(wParam)){
            case 
    BUT1:
                
    GetDlgItemText(hwnd,TEX1,distributoR,GetWindowTextLength(GetDlgItem(hwnd,TEX1))+1);
                return 
    0;
                break;
            case 
    TEX1:
                return 
    0;
                break;
            default:
                return 
    0;
            }
        default:
            
    THANKS:if(PO.is_open()){PO<<distributoR<<endl;PO.close();}
                   return 
    DefWindowProc(hwnd,msg,wParam,lParam);
        }
        return 
    0;
    }
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){
        
    WNDCLASSEX tz;
        
    HWND hwnd;
        
    MSG Msg;

        
    tz.cbSize=sizeof(WNDCLASSEX);
        
    tz.style=0;
        
    tz.lpfnWndProc=WndProc;
        
    tz.cbClsExtra=0;
        
    tz.cbWndExtra=0;
        
    tz.hInstance=hInstance;
        
    tz.hIcon=LoadIcon(NULL,IDI_APPLICATION);
        
    tz.hCursor=LoadCursor(NULL,IDC_ARROW);
        
    tz.hbrBackground=(HBRUSH)(COLOR_WINDOW+8);
        
    tz.lpszClassName=tzID;
        
    tz.lpszMenuName=NULL;
        
    tz.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
        if(!
    RegisterClassEx(&tz)){
            
    MessageBox(hwnd,"An Error Occur while Registering this Program, you can contact the programmer at: [email][email protected][/email]","GOD BLESS YOU",2);
            return 
    0;
        }
        
    hwnd=CreateWindowEx(WS_EX_CLIENTEDGE,tzID,"God loves you",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,300,200,NULL,NULL,hInstance,NULL);
        if(
    hwnd==NULL){
            
    MessageBox(hwnd,"An Error Occur while Creating the Windows, contact the programmer at: [email][email protected][/email]","God Bless You",4);
            return 
    0;
        }
        
    ShowWindow(hwnd,nCmdShow);
        
    UpdateWindow(hwnd);
        while(
    GetMessage(&Msg,NULL,0,0)){
            
    TranslateMessage(&Msg);
            
    DispatchMessage(&Msg);
        }
        return 
    Msg.wParam;

    For some reasons I can't read from the file Distributor.dis, though the file already exisits...

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    A few things I noticed:

    1. Labels? You don't need them unless you're using goto which you shouldn't until you fully understand its implications

    2. Formatting! Don't smack everything on one line because it's a ***** to debug

    3. Stop mentioning god or I'll be forced to go on a murderous rampage round Malvern

    And to solve the actual problem, I don't remember if it automatically opens the file but if it does, then you can't open it twice because it will be opened in the constructor of the fstream object. If it doesn't, you need to open it yourself.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    Oh give him a break, it's for a christian camp after all
    Alcohol & calculus don't mix.
    Never drink & derive.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    LOL I thought it was for someone called Christian Camp

    Either way it's religious brainwashing and I won't stand for it
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Post Christian Camp??

    What do you mean Christian Camp? I said Christmas Camp

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Code:
    //////////////////////////////////////////////////
    //MONEY DISTRIBUTOR DATABASE FOR CHRISTIAN CAMP//
    ////////////////////////////////////////////////
    That's what you wrote

    Anyway, did it fix your problem?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7
    New Member Earl of Gonds's Avatar
    Join Date
    Sep 2001
    Location
    Mentomontos
    Posts
    1
    i once knew a guy named christian camp, he was catholic though

  8. #8
    Junior Member Stefan Raab's Avatar
    Join Date
    Sep 2001
    Location
    Under the old core Fish Tank: Orthodox
    Posts
    25
    was he a brutha too?
    in watermelon sugar the deeds were done and done again as my life is done in watermelon sugar.

  9. #9

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Post I solved it myself...

    I solved it myself... I put a getline and a messagebox in the while(!FILE.eof()){}
    Thanks anyway, do you know how to set the text of a label, button, and a edit during Runtime? For instance, I press Button1 and Text1's Text will change to : "sex!"

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  10. #10
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    There is a function to do so. You can always look up at MSDN for the API refrence.
    The function is called:

    SetWindowText()

    and at takes two parameters so if you have a handle to the button, textbox, label..etc, then you can use the similiar code

    Code:
    SetWindowText(THE_HANDLE, "Is sex fun?");
    Baaaaaaaaah

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width