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. CreateWindow

CreateWindow

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelpquestion
13 Posts 6 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.
  • N Offline
    N Offline
    Nick Armstrong
    wrote on last edited by
    #1

    I have a dialog which I have set as a tool window so it is always on top. Within this window I want to dynamically load buttons each with a different bitmap on. Someone has suggested that I use CreateWindow and pass a flag to say it will be of style BUTTON so I use the following code CreateWindow("BUTTON", "sample", BS_BITMAP, 5, 5, 100, 100, m_hWnd, NULL, NULL, NULL); I'm assuming that m_hWnd member variable should be a handle to the dialog box when it is shown, but when tested comes through as NULL and nothing is shown in the dialog box. What am I doing wrong? Thanks for any help in advance Nick

    L C T 3 Replies Last reply
    0
    • N Nick Armstrong

      I have a dialog which I have set as a tool window so it is always on top. Within this window I want to dynamically load buttons each with a different bitmap on. Someone has suggested that I use CreateWindow and pass a flag to say it will be of style BUTTON so I use the following code CreateWindow("BUTTON", "sample", BS_BITMAP, 5, 5, 100, 100, m_hWnd, NULL, NULL, NULL); I'm assuming that m_hWnd member variable should be a handle to the dialog box when it is shown, but when tested comes through as NULL and nothing is shown in the dialog box. What am I doing wrong? Thanks for any help in advance Nick

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      you must call ShowWindow() function after CreateWindow(). F.Julien

      N 1 Reply Last reply
      0
      • N Nick Armstrong

        I have a dialog which I have set as a tool window so it is always on top. Within this window I want to dynamically load buttons each with a different bitmap on. Someone has suggested that I use CreateWindow and pass a flag to say it will be of style BUTTON so I use the following code CreateWindow("BUTTON", "sample", BS_BITMAP, 5, 5, 100, 100, m_hWnd, NULL, NULL, NULL); I'm assuming that m_hWnd member variable should be a handle to the dialog box when it is shown, but when tested comes through as NULL and nothing is shown in the dialog box. What am I doing wrong? Thanks for any help in advance Nick

        C Offline
        C Offline
        Carlos Antollini
        wrote on last edited by
        #3

        You need to call to ShowWindow Function, but you are missing same values in the style parameter like WS_CHILD | WS_VISIBLE whit this last parameter don't you need to call to ShowWindow function. Cheers Carlos Antollini.

        1 Reply Last reply
        0
        • N Nick Armstrong

          I have a dialog which I have set as a tool window so it is always on top. Within this window I want to dynamically load buttons each with a different bitmap on. Someone has suggested that I use CreateWindow and pass a flag to say it will be of style BUTTON so I use the following code CreateWindow("BUTTON", "sample", BS_BITMAP, 5, 5, 100, 100, m_hWnd, NULL, NULL, NULL); I'm assuming that m_hWnd member variable should be a handle to the dialog box when it is shown, but when tested comes through as NULL and nothing is shown in the dialog box. What am I doing wrong? Thanks for any help in advance Nick

          T Offline
          T Offline
          Tomasz Sowinski
          wrote on last edited by
          #4

          Button style should contain WS_CHILD and WS_VISIBLE:

          CreateWindow("BUTTON",
          "sample",
          WS_CHILD | WS_VISIBLE | BS_BITMAP,
          5,
          5,
          100,
          100,
          m_hWnd,
          NULL,
          NULL,
          NULL);

          You should also pass a child window id after m_hWnd. Tomasz Sowinski -- http://www.shooltz.com

          N 1 Reply Last reply
          0
          • L Lost User

            you must call ShowWindow() function after CreateWindow(). F.Julien

            N Offline
            N Offline
            Nick Armstrong
            wrote on last edited by
            #5

            thanks, but do I put those in the constructor of the containing dialog because obviously the buttons will be part of this. When doing this I get an assertion error, I think its talking about a NULL handle to this dialog which I thought would be a problem. Nick

            S 1 Reply Last reply
            0
            • N Nick Armstrong

              thanks, but do I put those in the constructor of the containing dialog because obviously the buttons will be part of this. When doing this I get an assertion error, I think its talking about a NULL handle to this dialog which I thought would be a problem. Nick

              S Offline
              S Offline
              Steen Krogsgaard
              wrote on last edited by
              #6

              Don't call CreateWindow on the buttons in the dialog's constructor - the dialog window won't be created yet so you can't use it as a parent window. Call CreateWindow in CYourDialog::OnCreate() (if you use MFC) or in response to the WM_CREATE msg (if non-MFC) instead. Since it's a dialog you can also put the calls in OnInitDialog/WM_INITDIALOG instead. Cheers Steen. "To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"

              N 1 Reply Last reply
              0
              • S Steen Krogsgaard

                Don't call CreateWindow on the buttons in the dialog's constructor - the dialog window won't be created yet so you can't use it as a parent window. Call CreateWindow in CYourDialog::OnCreate() (if you use MFC) or in response to the WM_CREATE msg (if non-MFC) instead. Since it's a dialog you can also put the calls in OnInitDialog/WM_INITDIALOG instead. Cheers Steen. "To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"

                N Offline
                N Offline
                Nick Armstrong
                wrote on last edited by
                #7

                thanks a lot, that worked fine Nick :-D

                1 Reply Last reply
                0
                • T Tomasz Sowinski

                  Button style should contain WS_CHILD and WS_VISIBLE:

                  CreateWindow("BUTTON",
                  "sample",
                  WS_CHILD | WS_VISIBLE | BS_BITMAP,
                  5,
                  5,
                  100,
                  100,
                  m_hWnd,
                  NULL,
                  NULL,
                  NULL);

                  You should also pass a child window id after m_hWnd. Tomasz Sowinski -- http://www.shooltz.com

                  N Offline
                  N Offline
                  Nick Armstrong
                  wrote on last edited by
                  #8

                  How do I get this child window ID? So far I have the following code: CreateWindow( "BUTTON", "sample", WS_CHILD | WS_VISIBLE | BS_BITMAP, 5, 5, 20, 20, m_hWnd, /*the child window ID will go here*/, NULL, NULL); HBITMAP hBmp = (HBITMAP)::LoadImage(AfxGetInstanceHandle(), "c:\\1.bmp", IMAGE_BITMAP, 16, 16, LR_LOADFROMFILE); ::SendMessage((HWND)hButton, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBmp); Thanks for the help so far Nick

                  T 1 Reply Last reply
                  0
                  • N Nick Armstrong

                    How do I get this child window ID? So far I have the following code: CreateWindow( "BUTTON", "sample", WS_CHILD | WS_VISIBLE | BS_BITMAP, 5, 5, 20, 20, m_hWnd, /*the child window ID will go here*/, NULL, NULL); HBITMAP hBmp = (HBITMAP)::LoadImage(AfxGetInstanceHandle(), "c:\\1.bmp", IMAGE_BITMAP, 16, 16, LR_LOADFROMFILE); ::SendMessage((HWND)hButton, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBmp); Thanks for the help so far Nick

                    T Offline
                    T Offline
                    Tomasz Sowinski
                    wrote on last edited by
                    #9

                    How do I get this child window ID? You don't get this ID, you have to come up with one yourself. This ID is passed back (as LOWORD(wParam) in WM_COMMAND) to the parent window when somebody clicks the button - you'll need to recognize which button was pressed, right? You can use any scheme to create IDs to your buttons. Tomasz Sowinski -- http://www.shooltz.com

                    N 1 Reply Last reply
                    0
                    • T Tomasz Sowinski

                      How do I get this child window ID? You don't get this ID, you have to come up with one yourself. This ID is passed back (as LOWORD(wParam) in WM_COMMAND) to the parent window when somebody clicks the button - you'll need to recognize which button was pressed, right? You can use any scheme to create IDs to your buttons. Tomasz Sowinski -- http://www.shooltz.com

                      N Offline
                      N Offline
                      Nick Armstrong
                      wrote on last edited by
                      #10

                      So for example, I could set it as 966 by doing int hButton = 966; and including hButton under/after the m_hWnd parameter, because I already tried that. If that is correct, there is something else wrong, probably in the loading of the bitmap because when the program is run it show's no bitmap on the button. Nick

                      T 1 Reply Last reply
                      0
                      • N Nick Armstrong

                        So for example, I could set it as 966 by doing int hButton = 966; and including hButton under/after the m_hWnd parameter, because I already tried that. If that is correct, there is something else wrong, probably in the loading of the bitmap because when the program is run it show's no bitmap on the button. Nick

                        T Offline
                        T Offline
                        Tomasz Sowinski
                        wrote on last edited by
                        #11

                        hButton is a window handle, not a child ID. Store value returned from CreateWindow in hButton. Use some predefined constant and pass it as child ID to CreateWindow. Use the same constant when handling WM_COMMAND - you'll be able to respond differently to different buttons being pressed. Tomasz Sowinski -- http://www.shooltz.com

                        N U 2 Replies Last reply
                        0
                        • T Tomasz Sowinski

                          hButton is a window handle, not a child ID. Store value returned from CreateWindow in hButton. Use some predefined constant and pass it as child ID to CreateWindow. Use the same constant when handling WM_COMMAND - you'll be able to respond differently to different buttons being pressed. Tomasz Sowinski -- http://www.shooltz.com

                          N Offline
                          N Offline
                          Nick Armstrong
                          wrote on last edited by
                          #12

                          Sorted, thank you very much, much appreciated. Nick :-D

                          1 Reply Last reply
                          0
                          • T Tomasz Sowinski

                            hButton is a window handle, not a child ID. Store value returned from CreateWindow in hButton. Use some predefined constant and pass it as child ID to CreateWindow. Use the same constant when handling WM_COMMAND - you'll be able to respond differently to different buttons being pressed. Tomasz Sowinski -- http://www.shooltz.com

                            U Offline
                            U Offline
                            uzziah0
                            wrote on last edited by
                            #13

                            This is exactly what I'm doing, but in WM_COMMAND all WPARAM wp ever is is 0x0000FFFF any ideas why? I set it to #define BTN_ONE 301 Thanks

                            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