Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Need to call FormatRange member of a richedit control in a modeless dialog from the view class

Need to call FormatRange member of a richedit control in a modeless dialog from the view class

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
13 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lctrncs
    wrote on last edited by
    #1

    I am a amateur programmer trying to print the contents of a richedit control as suggested by the article "how to print the contents of a rich edit control" by Roger Allen. Since my richedit control is in a modeless dialog (instead of a SDI) I am unable to simply use the control variable of the richedit control and the SetTargetDevice and FormatRange members of the RichEditCtrl class in MyView::OnPreparePrinting as suggested: "m_Control.FormatRange(NULL, FALSE)" etc. I have tried a number of (crazy?) things to gain access to the dialog and richedit control that I want to print without success including: CWnd* qDlg; qDlg=CWnd::FindWindow(NULL,_T("Dialog Title")); then trying to access the control etc. Perhaps (probably) this is something simple that I do not yet understand and hope that others can help me solve (and understand) this problem. Any suggestions? Thanks.

    "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

    M 1 Reply Last reply
    0
    • L lctrncs

      I am a amateur programmer trying to print the contents of a richedit control as suggested by the article "how to print the contents of a rich edit control" by Roger Allen. Since my richedit control is in a modeless dialog (instead of a SDI) I am unable to simply use the control variable of the richedit control and the SetTargetDevice and FormatRange members of the RichEditCtrl class in MyView::OnPreparePrinting as suggested: "m_Control.FormatRange(NULL, FALSE)" etc. I have tried a number of (crazy?) things to gain access to the dialog and richedit control that I want to print without success including: CWnd* qDlg; qDlg=CWnd::FindWindow(NULL,_T("Dialog Title")); then trying to access the control etc. Perhaps (probably) this is something simple that I do not yet understand and hope that others can help me solve (and understand) this problem. Any suggestions? Thanks.

      "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      If you have code running in a view class then the modal dialog must be on another thread, right? If so, you should be able to post app-defined messages to the dialog (instead of accessing the control directly from a separate thread). Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      L L 2 Replies Last reply
      0
      • M Mark Salsbery

        If you have code running in a view class then the modal dialog must be on another thread, right? If so, you should be able to post app-defined messages to the dialog (instead of accessing the control directly from a separate thread). Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        L Offline
        L Offline
        led mike
        wrote on last edited by
        #3

        Mark Salsbery wrote:

        If so, you should be able to post app-defined messages to the dialog (instead of accessing the control directly from a separate thread).

        :laugh: It's such a shame there is no way to maintain the application session data in a single location we might call, oh I don't know... a model. That sort of design would negate having to tightly couple different user interface views being that their requirements could change in the future. Wait..... :rolleyes:

        M L 2 Replies Last reply
        0
        • L led mike

          Mark Salsbery wrote:

          If so, you should be able to post app-defined messages to the dialog (instead of accessing the control directly from a separate thread).

          :laugh: It's such a shame there is no way to maintain the application session data in a single location we might call, oh I don't know... a model. That sort of design would negate having to tightly couple different user interface views being that their requirements could change in the future. Wait..... :rolleyes:

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          led mike wrote:

          a model

          I never thought it through that far. I'm wondering HOW this is an issue :) Am I the only one not getting email notifications when someone replies to my posts here? :beer: Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          D L 2 Replies Last reply
          0
          • M Mark Salsbery

            led mike wrote:

            a model

            I never thought it through that far. I'm wondering HOW this is an issue :) Am I the only one not getting email notifications when someone replies to my posts here? :beer: Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            Mark Salsbery wrote:

            Am I the only one not getting email notifications when someone replies to my posts here?

            No, I'm not getting any either.

            "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            M 1 Reply Last reply
            0
            • D David Crow

              Mark Salsbery wrote:

              Am I the only one not getting email notifications when someone replies to my posts here?

              No, I'm not getting any either.

              "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              Thanks :) I got a few today - yay! Mark

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              1 Reply Last reply
              0
              • L led mike

                Mark Salsbery wrote:

                If so, you should be able to post app-defined messages to the dialog (instead of accessing the control directly from a separate thread).

                :laugh: It's such a shame there is no way to maintain the application session data in a single location we might call, oh I don't know... a model. That sort of design would negate having to tightly couple different user interface views being that their requirements could change in the future. Wait..... :rolleyes:

                L Offline
                L Offline
                lctrncs
                wrote on last edited by
                #7

                Thanks for responding led mike. You state,

                led mike wrote:

                It's such a shame there is no way to maintain the application session data in a single location

                Is this true? Or is there a way to accomplish maintaining the session data in a single location – perhaps the model and design you refer to. At the beginning of my project, I spent a great deal of time “Applying UML and Patterns.” However, a serious illness permanently interrupted the collaboration I had with an expert programmer who encouraged me to develop expanded use cases, flow charts and a “conceptual model” of my program. Recognizing that your message might be sarcastic, I reviewed these documents and realized that my program already contains series of functions that provide access to the user and internal data the program employs in its operation. It appears that the interruption of the collaboration with the expert programmer may have occurred at a critical moment in that I had not yet, and still do not, fully understand what I have been doing as I worked to continue the development of my program without my expert collaborator. Perhaps if I had studied programming in college as my collaborator (and many others) did, my task might be easier. However, the modeless dialog I mentioned is the interface to a flat file database I created and from which I hope to print information from numerous records I have synthesized into single record. Therefore, returning transient data present in the richedit control at a certain point in time remains useful (although the advantage of this was not evident during the design of the program). If I understood how to solve my problem (or had correctly anticipated future needs in my model and design) there would no reason to turn to experts like you or a site like CodeProject for a bit of help, a friendly conversation or an educational response. Working in isolation can be a challenge in any discipline (physical biochemistry is a personal favorite), and it is good to have a place where you can ask questions and receive accurate, precise, concise and information rich responses. It is easy to laugh at those who seek to learn from you (and even misdirect them as a means of providing future entertainment), so a community like CodeProject in which shared enjoyment of programming, interpersonal respect and dedication to mutual aid trumps petty personal attacks is critically important. Thank you again for your response, which s

                L 1 Reply Last reply
                0
                • M Mark Salsbery

                  led mike wrote:

                  a model

                  I never thought it through that far. I'm wondering HOW this is an issue :) Am I the only one not getting email notifications when someone replies to my posts here? :beer: Mark

                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                  L Offline
                  L Offline
                  led mike
                  wrote on last edited by
                  #8

                  Mark Salsbery wrote:

                  Am I the only one not getting email notifications when someone replies to my posts here?

                  No, I never got this one. ;)

                  M 1 Reply Last reply
                  0
                  • L led mike

                    Mark Salsbery wrote:

                    Am I the only one not getting email notifications when someone replies to my posts here?

                    No, I never got this one. ;)

                    M Offline
                    M Offline
                    Mark Salsbery
                    wrote on last edited by
                    #9

                    :laugh: Thanks man. Did you get this one? ;P

                    Mark Salsbery Microsoft MVP - Visual C++ :java:

                    L 1 Reply Last reply
                    0
                    • L lctrncs

                      Thanks for responding led mike. You state,

                      led mike wrote:

                      It's such a shame there is no way to maintain the application session data in a single location

                      Is this true? Or is there a way to accomplish maintaining the session data in a single location – perhaps the model and design you refer to. At the beginning of my project, I spent a great deal of time “Applying UML and Patterns.” However, a serious illness permanently interrupted the collaboration I had with an expert programmer who encouraged me to develop expanded use cases, flow charts and a “conceptual model” of my program. Recognizing that your message might be sarcastic, I reviewed these documents and realized that my program already contains series of functions that provide access to the user and internal data the program employs in its operation. It appears that the interruption of the collaboration with the expert programmer may have occurred at a critical moment in that I had not yet, and still do not, fully understand what I have been doing as I worked to continue the development of my program without my expert collaborator. Perhaps if I had studied programming in college as my collaborator (and many others) did, my task might be easier. However, the modeless dialog I mentioned is the interface to a flat file database I created and from which I hope to print information from numerous records I have synthesized into single record. Therefore, returning transient data present in the richedit control at a certain point in time remains useful (although the advantage of this was not evident during the design of the program). If I understood how to solve my problem (or had correctly anticipated future needs in my model and design) there would no reason to turn to experts like you or a site like CodeProject for a bit of help, a friendly conversation or an educational response. Working in isolation can be a challenge in any discipline (physical biochemistry is a personal favorite), and it is good to have a place where you can ask questions and receive accurate, precise, concise and information rich responses. It is easy to laugh at those who seek to learn from you (and even misdirect them as a means of providing future entertainment), so a community like CodeProject in which shared enjoyment of programming, interpersonal respect and dedication to mutual aid trumps petty personal attacks is critically important. Thank you again for your response, which s

                      L Offline
                      L Offline
                      led mike
                      wrote on last edited by
                      #10

                      lctrncs wrote:

                      Recognizing that your message might be sarcastic

                      Yes, and my reply was to Mark. Mark and I joke around some in the forums. At that time in the thread there was no indication that you would be interested in anything other than what Mark suggest, as many here on CodeProject are not. I am happy to see that you are and that you have help. Things will go well for you given the track you are on. Don't worry about not having a formal education. With your attitude, the availability of information on the internet and your colleagues you will do fine. It is very likely that your colleague helped you implement a Model-View-Controller[^] pattern. If so you will find that it satisfies all your requirements.

                      1 Reply Last reply
                      0
                      • M Mark Salsbery

                        :laugh: Thanks man. Did you get this one? ;P

                        Mark Salsbery Microsoft MVP - Visual C++ :java:

                        L Offline
                        L Offline
                        led mike
                        wrote on last edited by
                        #11

                        Leave me alone dude, I have emails from CodeProject to read.... wait.... :-D

                        1 Reply Last reply
                        0
                        • M Mark Salsbery

                          If you have code running in a view class then the modal dialog must be on another thread, right? If so, you should be able to post app-defined messages to the dialog (instead of accessing the control directly from a separate thread). Mark

                          Mark Salsbery Microsoft MVP - Visual C++ :java:

                          L Offline
                          L Offline
                          lctrncs
                          wrote on last edited by
                          #12

                          Thanks for responding Mark. Please assist me by educating me when I am not saying things correctly. I am trying to learn through this process, and working alone and without [programming] training (or any level of programming talent :wtf: ) can make programming a challenge. By “code running in a view class” I assume you are referring to the OnPreparePrinting virtual function I mentioned in my question (or perhaps one or more of the other virtual functions associated with printing from the view class such as OnPrepareDC). Similarly, I assume your reference to “modal dialog” in your response refers to the modeless dialog I mentioned in my question. You suggest that I might accomplish my by sending a message to the dialog (such as EM_FORMATRANGE), which is not directly accessible to the view because it is running in a different thread. One of my problems is that I am not sure that I have correctly created my dialog and my access to it appears inconsistent. In one part of my program (immediately after dialog creation) statements such as mDlg->OnDialogFunction(); appear to work fine, while in other parts of the program (such as OnPreparePrinting) this tactic fails. This may be embarrassingly bad programming practice; however, it accomplishes my goal ;) which is important in the absence of continuous cognizant collaborators. I will explore this clue. Thank you for your assistance.

                          "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

                          M 1 Reply Last reply
                          0
                          • L lctrncs

                            Thanks for responding Mark. Please assist me by educating me when I am not saying things correctly. I am trying to learn through this process, and working alone and without [programming] training (or any level of programming talent :wtf: ) can make programming a challenge. By “code running in a view class” I assume you are referring to the OnPreparePrinting virtual function I mentioned in my question (or perhaps one or more of the other virtual functions associated with printing from the view class such as OnPrepareDC). Similarly, I assume your reference to “modal dialog” in your response refers to the modeless dialog I mentioned in my question. You suggest that I might accomplish my by sending a message to the dialog (such as EM_FORMATRANGE), which is not directly accessible to the view because it is running in a different thread. One of my problems is that I am not sure that I have correctly created my dialog and my access to it appears inconsistent. In one part of my program (immediately after dialog creation) statements such as mDlg->OnDialogFunction(); appear to work fine, while in other parts of the program (such as OnPreparePrinting) this tactic fails. This may be embarrassingly bad programming practice; however, it accomplishes my goal ;) which is important in the absence of continuous cognizant collaborators. I will explore this clue. Thank you for your assistance.

                            "For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash

                            M Offline
                            M Offline
                            Mark Salsbery
                            wrote on last edited by
                            #13

                            Well my reply didn't make sense. Your post clearly states "modeless" - I don't know where I got "modal" from :) I'll try again... Where are you trying to access the rich edit control from? Within the dialog class or from another class? You shouldn't need to find the window. You should be able to keep a CRichEditCtrl member variable in the dialog class. From within the dialog class, you can use that variable directly to manipulate the control. From outside the dialog class, you can either make the control variable public and directly access it through the dialog object, or better yet, add methods to the dialog class which internally use the control member variable to access the control.

                            lctrncs wrote:

                            In one part of my program (immediately after dialog creation) statements such as mDlg->OnDialogFunction(); appear to work fine, while in other parts of the program (such as OnPreparePrinting) this tactic fails.

                            You'll need to make sure your mDlg variable is accessible from wherever you need it. Where (what class) is mDlg located? Mark

                            Mark Salsbery Microsoft MVP - Visual C++ :java:

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups