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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Creating buttons and CRect

Creating buttons and CRect

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
21 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.
  • PJ ArendsP PJ Arends

    Place a breakpoint in the OnCreate function just to make sure the code is actually being run. Did you remember to add the ON_WM_CREATE() macro to your message map?


    "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!


    Honoured as one of The Most Helpful Members of 2004

    B Offline
    B Offline
    bcemick
    wrote on last edited by
    #12

    PJ Arends wrote: Did you remember to add the ON_WM_CREATE() macro to your message map? Yes, I did. According to the step-through, it is entering OnCreate and moving to the Create line for the button. It is returning 1, but that, according to the message, is success. So, it's saying that it is creating it. I just don't know where it's creating it at since it's not showing up anywhere on the property sheet. Everything else that I'm doing in OnCreate and OnInit work. Buttons are removed or moved, the menu is added, all of it; everything except creating the buttons.

    PJ ArendsP 1 Reply Last reply
    0
    • B bcemick

      PJ Arends wrote: Did you remember to add the ON_WM_CREATE() macro to your message map? Yes, I did. According to the step-through, it is entering OnCreate and moving to the Create line for the button. It is returning 1, but that, according to the message, is success. So, it's saying that it is creating it. I just don't know where it's creating it at since it's not showing up anywhere on the property sheet. Everything else that I'm doing in OnCreate and OnInit work. Buttons are removed or moved, the menu is added, all of it; everything except creating the buttons.

      PJ ArendsP Offline
      PJ ArendsP Offline
      PJ Arends
      wrote on last edited by
      #13

      Ok, in the debugger check what the value of the button's m_hWnd variable is. Then in Spy++ bring up the window finder dialog (Ctrl + F) and enter that value in the handle edit box. Click Enter. You should now be able to tell which window is the parent of your button, it should be the property sheet, if not what is it?


      "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!


      Honoured as one of The Most Helpful Members of 2004

      Within you lies the power for good; Use it!

      B 1 Reply Last reply
      0
      • PJ ArendsP PJ Arends

        Ok, in the debugger check what the value of the button's m_hWnd variable is. Then in Spy++ bring up the window finder dialog (Ctrl + F) and enter that value in the handle edit box. Click Enter. You should now be able to tell which window is the parent of your button, it should be the property sheet, if not what is it?


        "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!


        Honoured as one of The Most Helpful Members of 2004

        B Offline
        B Offline
        bcemick
        wrote on last edited by
        #14

        According to the debugger, the hWnd of the button is 0x00000000. Spy++ says "specified handle is not vallid". I knew that as soon as I saw it, but I tried it anyway. So, what's happening here? It's being created (it's returning a non-zero value indicating success), but it doesn't have a valid handle. Is it just being created and then destroyed before getting added to the property sheet? Any ideas?

        PJ ArendsP 2 Replies Last reply
        0
        • B bcemick

          According to the debugger, the hWnd of the button is 0x00000000. Spy++ says "specified handle is not vallid". I knew that as soon as I saw it, but I tried it anyway. So, what's happening here? It's being created (it's returning a non-zero value indicating success), but it doesn't have a valid handle. Is it just being created and then destroyed before getting added to the property sheet? Any ideas?

          PJ ArendsP Offline
          PJ ArendsP Offline
          PJ Arends
          wrote on last edited by
          #15

          bcemick wrote: Any ideas? No, that does not make any sense to me. Create() is returning 1 (success) but the buttons HWND is zero (not a window). I am at a loss. Just for the heck of it maybe you can try doing a rebuild all, that will sometimes fix weird errors.


          "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!


          Honoured as one of The Most Helpful Members of 2004

          Within you lies the power for good; Use it!

          1 Reply Last reply
          0
          • B bcemick

            According to the debugger, the hWnd of the button is 0x00000000. Spy++ says "specified handle is not vallid". I knew that as soon as I saw it, but I tried it anyway. So, what's happening here? It's being created (it's returning a non-zero value indicating success), but it doesn't have a valid handle. Is it just being created and then destroyed before getting added to the property sheet? Any ideas?

            PJ ArendsP Offline
            PJ ArendsP Offline
            PJ Arends
            wrote on last edited by
            #16

            Tracing into the MFC source for CButton::Create() we get to this code in CWnd::CreateEx (in Wincore.cpp)

            #ifdef _DEBUG
            if (hWnd == NULL)
            {
            TRACE1("Warning: Window creation failed: GetLastError returns 0x%8.8X\n",
            GetLastError());
            }
            #endif

            if (!AfxUnhookWindowCreate())
            	PostNcDestroy();        // cleanup if CreateWindowEx fails too soon
            
            if (hWnd == NULL)
            	return FALSE;
            ASSERT(hWnd == m\_hWnd); // should have been set in send msg hook
            return TRUE;
            

            So there is no way that Create will return TRUE (1) if the HWND is NULL (0).


            "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!


            Honoured as one of The Most Helpful Members of 2004

            Within you lies the power for good; Use it!

            B 1 Reply Last reply
            0
            • PJ ArendsP PJ Arends

              Tracing into the MFC source for CButton::Create() we get to this code in CWnd::CreateEx (in Wincore.cpp)

              #ifdef _DEBUG
              if (hWnd == NULL)
              {
              TRACE1("Warning: Window creation failed: GetLastError returns 0x%8.8X\n",
              GetLastError());
              }
              #endif

              if (!AfxUnhookWindowCreate())
              	PostNcDestroy();        // cleanup if CreateWindowEx fails too soon
              
              if (hWnd == NULL)
              	return FALSE;
              ASSERT(hWnd == m\_hWnd); // should have been set in send msg hook
              return TRUE;
              

              So there is no way that Create will return TRUE (1) if the HWND is NULL (0).


              "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!


              Honoured as one of The Most Helpful Members of 2004

              B Offline
              B Offline
              bcemick
              wrote on last edited by
              #17

              PJ Arends wrote: So there is no way that Create will return TRUE (1) if the HWND is NULL (0). I know. That's what was so weird about all of this. I swear that's what was happening. I tried rebuild all and now it's returning a non-NULL handle; the handle is still invalid though. I tried moving it into another function to see what would happen. I got hWnd handles, but none of them are valid handles according to Spy++. It is still returning 1 (success). The only thing I can think of is that the button is being created, but it's being destroyed before it can be added to the property sheet (if that makes sense - it sounds better in my head). It's either that or I am missing something so obvious that it would've killed me if it was a snake. One way or another, I'm going to make this work. Any help is greatly appreciated (and you've been great so far). If nothing else, it eliminates a possibility.

              PJ ArendsP 1 Reply Last reply
              0
              • B bcemick

                PJ Arends wrote: So there is no way that Create will return TRUE (1) if the HWND is NULL (0). I know. That's what was so weird about all of this. I swear that's what was happening. I tried rebuild all and now it's returning a non-NULL handle; the handle is still invalid though. I tried moving it into another function to see what would happen. I got hWnd handles, but none of them are valid handles according to Spy++. It is still returning 1 (success). The only thing I can think of is that the button is being created, but it's being destroyed before it can be added to the property sheet (if that makes sense - it sounds better in my head). It's either that or I am missing something so obvious that it would've killed me if it was a snake. One way or another, I'm going to make this work. Any help is greatly appreciated (and you've been great so far). If nothing else, it eliminates a possibility.

                PJ ArendsP Offline
                PJ ArendsP Offline
                PJ Arends
                wrote on last edited by
                #18

                One last guess, I am sure you did but I have to ask anyway because I am running out of ideas, did you make your CButton variable a member of your CPropertySheet derived class? I ask this because the only way the button would be destroyed before it is added to the sheet is if your CButton variable is going out of scope and being destroyed that way.


                "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!


                Honoured as one of The Most Helpful Members of 2004

                Within you lies the power for good; Use it!

                B 1 Reply Last reply
                0
                • PJ ArendsP PJ Arends

                  One last guess, I am sure you did but I have to ask anyway because I am running out of ideas, did you make your CButton variable a member of your CPropertySheet derived class? I ask this because the only way the button would be destroyed before it is added to the sheet is if your CButton variable is going out of scope and being destroyed that way.


                  "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!


                  Honoured as one of The Most Helpful Members of 2004

                  B Offline
                  B Offline
                  bcemick
                  wrote on last edited by
                  #19

                  PJ Arends wrote: did you make your CButton variable a member of your CPropertySheet derived class? ummm....of course I...ummm...you know...umm... :doh: Thank you. I'll go slam my head into a wall repeatedly. Now I just have to figure out how to get into the right place and then line up those other buttons beside it. Which I will. On my own. So I don't look so incredibly dense.

                  PJ ArendsP 1 Reply Last reply
                  0
                  • B bcemick

                    PJ Arends wrote: did you make your CButton variable a member of your CPropertySheet derived class? ummm....of course I...ummm...you know...umm... :doh: Thank you. I'll go slam my head into a wall repeatedly. Now I just have to figure out how to get into the right place and then line up those other buttons beside it. Which I will. On my own. So I don't look so incredibly dense.

                    PJ ArendsP Offline
                    PJ ArendsP Offline
                    PJ Arends
                    wrote on last edited by
                    #20

                    http://www.codeproject.com/script/comments/forums.asp?msg=1047556&forumid=1647#xx1047556xx[^] [shakes head and walks away in utter disbelief, thinking 'why don't those damn kids just listen']:sigh:


                    "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!


                    Honoured as one of The Most Helpful Members of 2004

                    Within you lies the power for good; Use it!

                    B 1 Reply Last reply
                    0
                    • PJ ArendsP PJ Arends

                      http://www.codeproject.com/script/comments/forums.asp?msg=1047556&forumid=1647#xx1047556xx[^] [shakes head and walks away in utter disbelief, thinking 'why don't those damn kids just listen']:sigh:


                      "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!


                      Honoured as one of The Most Helpful Members of 2004

                      B Offline
                      B Offline
                      bcemick
                      wrote on last edited by
                      #21

                      (Kid?) I listened; I really did. I was so sure that I had done it that I almost didn't go check to make sure I had. But, to be on the safe side, I checked. Lo and behold, I had either been attacked by a case of The Stupids and forgotten to do it or deleted it while messing around with it. Either way, thank you for the help.

                      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