Thread: write and replace cout function?

  1. #1
    Registered User I C everything's Avatar
    Join Date
    Apr 2019
    Posts
    101

    Question write and replace cout function?

    Hi
    I have lots of code using Cout to printout things in a console program with several source files
    so moving to a windows program,would it be a good idea to write a different version of cout that outputs to a textbuffer instead,textbuffer that is used in settext in a richedit control?
    or GDI drawtext?
    you tell me you can C,why dont you C your own bugs?

  2. #2
    Registered User
    Join Date
    Apr 2019
    Posts
    808
    dont quote me but i belive cout works on windows and linux

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What do you mean by "Cout"?

    As for output to console versus output to a text buffer in C: there isn't any notion of an output string stream in standard C such that fprintf would work universally, but you can use sprintf and snprintf instead of printf and fprintf when you want to treat a buffer as if it were a file stream.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User I C everything's Avatar
    Join Date
    Apr 2019
    Posts
    101
    Quote Originally Posted by laserlight View Post
    What do you mean by "Cout"?

    As for output to console versus output to a text buffer in C: there isn't any notion of an output string stream in standard C such that fprintf would work universally, but you can use sprintf and snprintf instead of printf and fprintf when you want to treat a buffer as if it were a file stream.
    you can have fun make your own math library,overload some things
    maybe make alternative function that writes to a textbuffer and IF it finds "\n",it advances pointer to nextline
    you tell me you can C,why dont you C your own bugs?

  5. #5
    Registered User I C everything's Avatar
    Join Date
    Apr 2019
    Posts
    101
    maybe easier if I describe whats the goal of this:
    in console its easy to just write out a question and several answer alternatives and choose by pressing a number button
    in a graphic enviroment I want to do the same output of text,but also include mouseover=highlight color of text,mousepress = choose answer
    less advanced is to show up lots of text ala screen full of text
    the alternative way is to use richedit control(same used in MSword interface)
    you tell me you can C,why dont you C your own bugs?

  6. #6
    Registered User
    Join Date
    Apr 2019
    Posts
    808
    not sure about c or c++ but in vb the the mouse over stuff is for the whole control not the text. easiest way round would be to have three labels or whatever (assuming three answers) then the mouseover will be for each label

  7. #7
    Registered User I C everything's Avatar
    Join Date
    Apr 2019
    Posts
    101
    Quote Originally Posted by cooper1200 View Post
    not sure about c or c++ but in vb the the mouse over stuff is for the whole control not the text. easiest way round would be to have three labels or whatever (assuming three answers) then the mouseover will be for each label
    thanks cooper,maybe would be good alternative,maybe use 4 buttons ala tvshow,showup like this
    Question drawn with GDI above and with string handling before output to combine several smaller strings into a bigger string containing whole question
    A. answer C. answer
    B. answer D. answer
    is it possible to create buttons when I need it and delete them when I not need them?

    for the other problem,store big texts in files and read them in textbuffer and settext with that textbuffer into richedit control
    how?redirect text output from console screen to textfiles
    you tell me you can C,why dont you C your own bugs?

  8. #8
    Registered User
    Join Date
    Apr 2019
    Posts
    808
    again im new to c so haven't done any gui stuff so could be talking out of my hat. but in vb you can either show or hide the buttons as you need them or create an array of buttons and load unload them. however i seem to remember that once unloaded they are gone. and cant be reloaded.

    i suspect that if you have differing amounts of answers to different questions i would go with the first option manipulating the co-ordinates of the buttons according to layout required and any unwanted buttons set the visible and enabled attributes to false.

    the reason i mentioned lables above is you can set the text property at run time ie your answers and the user wont be able to change them. then you can use the mouseover event to change either the background attribute or the text bold/colour attribute or of course both.

    you will have to look at what attributes are available for your gui builder for want of a better term.

    hope this helps
    coop

  9. #9
    Registered User I C everything's Avatar
    Join Date
    Apr 2019
    Posts
    101
    you tell me you can C,why dont you C your own bugs?

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I shall move this to Windows programming forum.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #11
    Registered User
    Join Date
    Apr 2019
    Posts
    808
    sorry if my discussion of vb has caused this to be moved.

    the issue with rtb (unless you have more than one) is i don't think you can isolate the answers like you wanted to above (highlighting on mouse over etc) and using images with rtb is a pain in the neck least it was for me.
    coop

  12. #12
    Registered User I C everything's Avatar
    Join Date
    Apr 2019
    Posts
    101
    I think it Wm_command with different number I'd for each button
    Maybe you should try your card game gui version?there are unicode characters for games
    you tell me you can C,why dont you C your own bugs?

  13. #13
    Registered User I C everything's Avatar
    Join Date
    Apr 2019
    Posts
    101
    so far experimenting with buttons and other GDI drawing stuff to learn things
    not good with when I need to use pointers in windows in windows calls and not
    so you need to create pointers to the texts I want to set with & defining the string, and use * in front of variable that is pointer
    Last edited by I C everything; 05-24-2019 at 01:34 PM.
    you tell me you can C,why dont you C your own bugs?

  14. #14
    Registered User I C everything's Avatar
    Join Date
    Apr 2019
    Posts
    101
    I read about topdown and bottomdown programming,but if you write a library and share,isnt that altruistic programming?you might write a library for future use too or all your small code snippets end up in a big program few years in the future

    anyway I dont know whats wrong with this trying to use this for sendmessage settext???

    Code:
    WCHAR szTitle[MAX_LOADSTRING];                  // The title bar textWCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name
    WCHAR buttontext[MAX_LOADSTRING];
    
    
    // Forward declarations of functions included in this code module:
    ATOM                MyRegisterClass(HINSTANCE hInstance);
    BOOL                InitInstance(HINSTANCE, int);
    LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
    INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
    
    
    int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
                         _In_opt_ HINSTANCE hPrevInstance,
                         _In_ LPWSTR    lpCmdLine,
                         _In_ int       nCmdShow)
    {
        UNREFERENCED_PARAMETER(hPrevInstance);
        UNREFERENCED_PARAMETER(lpCmdLine);
    
    
        // TODO: Place code here.
    	
        // Initialize global strings
        LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
        LoadStringW(hInstance, IDC_WINDOWSPROJECT1, szWindowClass, MAX_LOADSTRING);
    	buttontext ="PRESSED";
    last line with buttontext is error
    you tell me you can C,why dont you C your own bugs?

  15. #15
    Registered User I C everything's Avatar
    Join Date
    Apr 2019
    Posts
    101
    It's look like I am on a narrow path,lots of types and type casting
    casting and wchar instead of strings
    Seem it's just keep on practice windows programming until I get it, enjoy it at the challenge it is
    you tell me you can C,why dont you C your own bugs?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to write this cout<< in C
    By dunsta in forum C Programming
    Replies: 2
    Last Post: 04-19-2010, 08:21 AM
  2. Replace function
    By Loic in forum C++ Programming
    Replies: 7
    Last Post: 04-03-2007, 01:20 PM
  3. Replace Function
    By DrFox in forum C++ Programming
    Replies: 7
    Last Post: 06-26-2005, 07:52 AM
  4. replace function
    By garycastillo in forum C Programming
    Replies: 2
    Last Post: 04-16-2002, 03:50 PM
  5. replace function
    By thewarpedone in forum C++ Programming
    Replies: 1
    Last Post: 10-10-2001, 10:09 AM

Tags for this Thread