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. How to activate OnFileNew()?

How to activate OnFileNew()?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++helptutorial
5 Posts 3 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.
  • R Offline
    R Offline
    ryuki
    wrote on last edited by
    #1

    I work on a single document app. Now I have the problem that messagehandling doesn't work right. I want to activate the creation of a new document from another point as the main menu and toolbar. For that purpose I included ON_COMMAND(ID_FILE_NEW, OnFileNew) in a view class and tried to start the OnFileNew() function by sending a message to the view class: pvw->SendMessage(ID_FILE_NEW) It doesn't work! When debugging the whole matter I saw that OnFileNew() wasn't activated (and processed). Even if it does, I have to do all by myself (setting default name for empty document and so on). How can I activate the applications OnFileNew Funktion? Why doesn't the message sending work? I hope someone helps me with that (basic MFC) matter.

    K R 2 Replies Last reply
    0
    • R ryuki

      I work on a single document app. Now I have the problem that messagehandling doesn't work right. I want to activate the creation of a new document from another point as the main menu and toolbar. For that purpose I included ON_COMMAND(ID_FILE_NEW, OnFileNew) in a view class and tried to start the OnFileNew() function by sending a message to the view class: pvw->SendMessage(ID_FILE_NEW) It doesn't work! When debugging the whole matter I saw that OnFileNew() wasn't activated (and processed). Even if it does, I have to do all by myself (setting default name for empty document and so on). How can I activate the applications OnFileNew Funktion? Why doesn't the message sending work? I hope someone helps me with that (basic MFC) matter.

      K Offline
      K Offline
      karmendra_js
      wrote on last edited by
      #2

      well friend, i will not go in detail of message handling, but i will concentrate on your basic problem of Starting a new document whenever you click File->New. When you use App Wizard and create a single document app, it automatically does it for you. And if you wnat to do something else on file->new (like automatically saving the previous file without prompting etc anything) then you and Message handler using the Class Wizard to your Mainframe or any view class. Hope that make things clearer, if not make post.:rose: hey did you forget to rate? Plz rate my reply.

      R 1 Reply Last reply
      0
      • R ryuki

        I work on a single document app. Now I have the problem that messagehandling doesn't work right. I want to activate the creation of a new document from another point as the main menu and toolbar. For that purpose I included ON_COMMAND(ID_FILE_NEW, OnFileNew) in a view class and tried to start the OnFileNew() function by sending a message to the view class: pvw->SendMessage(ID_FILE_NEW) It doesn't work! When debugging the whole matter I saw that OnFileNew() wasn't activated (and processed). Even if it does, I have to do all by myself (setting default name for empty document and so on). How can I activate the applications OnFileNew Funktion? Why doesn't the message sending work? I hope someone helps me with that (basic MFC) matter.

        R Offline
        R Offline
        Roger Stoltz
        wrote on last edited by
        #3

        You have to send or rather post a WM_COMMAND message with ID_FILE_NEW as parameter to your view class. Hope this helps -- Roger

        R 1 Reply Last reply
        0
        • K karmendra_js

          well friend, i will not go in detail of message handling, but i will concentrate on your basic problem of Starting a new document whenever you click File->New. When you use App Wizard and create a single document app, it automatically does it for you. And if you wnat to do something else on file->new (like automatically saving the previous file without prompting etc anything) then you and Message handler using the Class Wizard to your Mainframe or any view class. Hope that make things clearer, if not make post.:rose: hey did you forget to rate? Plz rate my reply.

          R Offline
          R Offline
          ryuki
          wrote on last edited by
          #4

          I did not make me clear enough. I used the App Wizard and clicking the New Document button or selecting it in main menu works. I want to start it from another point too. For example a context menu or from another button. If there is a button in another toolbar that launches a funktion that requires a new document, I have to call the OnFileNew Funktion. But it doesn't work at the moment. How can I create a new document from within own classes or functions?

          1 Reply Last reply
          0
          • R Roger Stoltz

            You have to send or rather post a WM_COMMAND message with ID_FILE_NEW as parameter to your view class. Hope this helps -- Roger

            R Offline
            R Offline
            ryuki
            wrote on last edited by
            #5

            Thank you! It works! The right answer is: AfxGetMainWnd()->SendMessage(WM_COMMAND,ID_FILE_NEW);

            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