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. Why does creating a static window from a console app cause havok?

Why does creating a static window from a console app cause havok?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhtmlcomdesignsysadmin
12 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.
  • I Offline
    I Offline
    IGx89
    wrote on last edited by
    #1

    Why does the following code, when running, causes some programs to hang while starting (before presenting any UI), including Windows Explorer/Internet Explorer (when double-clicking an HTML file in Windows Explorer) and the AnalogX PacketMon installer[^]?

    #include <iostream>
    #include <tchar.h>
    #include <windows.h>

    int _tmain(int argc, _TCHAR* argv[])
    {
    HWND gWnd = CreateWindow(_T("STATIC"), _T("SomeWindow"), WS_POPUP, 20, 20, 200, 200, 0, 0, 0, 0);
    getchar();
    return 0;
    }

    D 1 Reply Last reply
    0
    • I IGx89

      Why does the following code, when running, causes some programs to hang while starting (before presenting any UI), including Windows Explorer/Internet Explorer (when double-clicking an HTML file in Windows Explorer) and the AnalogX PacketMon installer[^]?

      #include <iostream>
      #include <tchar.h>
      #include <windows.h>

      int _tmain(int argc, _TCHAR* argv[])
      {
      HWND gWnd = CreateWindow(_T("STATIC"), _T("SomeWindow"), WS_POPUP, 20, 20, 200, 200, 0, 0, 0, 0);
      getchar();
      return 0;
      }

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

      Why are you trying to create a GUI component in a console application?


      "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

      I 1 Reply Last reply
      0
      • D David Crow

        Why are you trying to create a GUI component in a console application?


        "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

        I Offline
        I Offline
        IGx89
        wrote on last edited by
        #3

        I'm using a library (not easily modified) that does that call. If I change "STATIC" to "STATIC_" (or probably anything else), the problem disappears.

        D L 2 Replies Last reply
        0
        • I IGx89

          I'm using a library (not easily modified) that does that call. If I change "STATIC" to "STATIC_" (or probably anything else), the problem disappears.

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

          What exactly is it that you are trying to do? CreateWindow() is a GUI, not a console, function that creates a window. It also sends messages (something that a console application knows nothing about) to the window's procedure.


          "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

          I 1 Reply Last reply
          0
          • I IGx89

            I'm using a library (not easily modified) that does that call. If I change "STATIC" to "STATIC_" (or probably anything else), the problem disappears.

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

            It sounds like the problem is to do with resource IDs. The tigress is here :-D

            I 1 Reply Last reply
            0
            • D David Crow

              What exactly is it that you are trying to do? CreateWindow() is a GUI, not a console, function that creates a window. It also sends messages (something that a console application knows nothing about) to the window's procedure.


              "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

              I Offline
              I Offline
              IGx89
              wrote on last edited by
              #6

              I know it's not proper, but it's in a (internal) library that would be hard to modify. Because using something other than STATIC doesn't appear to cause problems, it seems like there might be a way to get it to work (a define? another header file?). I basically just want to understand why using STATIC causes problems and using anything else doesn't cause problems. I like to know the causes of problems, not just the solutions.

              D 1 Reply Last reply
              0
              • L Lost User

                It sounds like the problem is to do with resource IDs. The tigress is here :-D

                I Offline
                I Offline
                IGx89
                wrote on last edited by
                #7

                Can you elaborate on that?

                L 1 Reply Last reply
                0
                • I IGx89

                  I know it's not proper, but it's in a (internal) library that would be hard to modify. Because using something other than STATIC doesn't appear to cause problems, it seems like there might be a way to get it to work (a define? another header file?). I basically just want to understand why using STATIC causes problems and using anything else doesn't cause problems. I like to know the causes of problems, not just the solutions.

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

                  IGx89 wrote: Because using something other than STATIC doesn't appear to cause problems... Have you entertained the thought that "doesn't appear" might be the key phrase here? Just because you do not see a problem does not mean a problem ceases to exist. IGx89 wrote: I like to know the causes of problems, not just the solutions. Unless you have not shown all of the code, you're trying to solve something that is the product of a bad design. Why are you trying, or even thinking that it's possible, to create a static window from within a console application? Much the same result can be achieved by trying to use getch() or printf() in a GUI application. Yes it might compile/link fine, but a "crash" of some sort is emminent.


                  "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

                  1 Reply Last reply
                  0
                  • I IGx89

                    Can you elaborate on that?

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

                    It is to do with resource ID numbers, STATIC is used to define the resource id for static labels on forms. The tigress is here :-D

                    D J 2 Replies Last reply
                    0
                    • L Lost User

                      It is to do with resource ID numbers, STATIC is used to define the resource id for static labels on forms. The tigress is here :-D

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

                      :confused: "STATIC" is the type (e.g., listbox, button, edit) of window that is to be created. It is one of many predefined system classes. In his call to CreateWindow(), 0 (the 9th parameter) was used as the control id.


                      "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

                      1 Reply Last reply
                      0
                      • L Lost User

                        It is to do with resource ID numbers, STATIC is used to define the resource id for static labels on forms. The tigress is here :-D

                        J Offline
                        J Offline
                        James Brown
                        wrote on last edited by
                        #11

                        I don't believe that resource-ids are the problem: The control/resource-id is specified as the 10th parameter to CreateWindowEx. The STATIC you are seeing is the name of the window-class to create a window from - in this case, a static-control - so no problem there. Changing the text to _STATIC_ results in an invalid class-name and CreateWindowEx fails (returns NULL) so no window is created. I think the problem with the program is that a console-program does not run a message-pump, so it cannot receive or process windows messages. So all messages destined for the STATIC control do not get processed and the program/Windows hangs indefinitely. Solution: create separate thread to handle the GUI and create a message-pump (GetMessage/DispatchMessage) to handle GUI messages. or better yet, use a GUI program that's what they're meant for. James
                        http://www.catch22.net

                        I 1 Reply Last reply
                        0
                        • J James Brown

                          I don't believe that resource-ids are the problem: The control/resource-id is specified as the 10th parameter to CreateWindowEx. The STATIC you are seeing is the name of the window-class to create a window from - in this case, a static-control - so no problem there. Changing the text to _STATIC_ results in an invalid class-name and CreateWindowEx fails (returns NULL) so no window is created. I think the problem with the program is that a console-program does not run a message-pump, so it cannot receive or process windows messages. So all messages destined for the STATIC control do not get processed and the program/Windows hangs indefinitely. Solution: create separate thread to handle the GUI and create a message-pump (GetMessage/DispatchMessage) to handle GUI messages. or better yet, use a GUI program that's what they're meant for. James
                          http://www.catch22.net

                          I Offline
                          I Offline
                          IGx89
                          wrote on last edited by
                          #12

                          Ok, thanks! That's exactly the detailed explanation I was looking for :). It's nice to know about things not to do, but it's even nicer to know exactly why not to do them.

                          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