Dynamic GUI

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • compman9902
    New Member
    • Mar 2007
    • 105

    Dynamic GUI

    People, first of all thank you for reading my post.
    I would like to start off by saying that I have read Prorgramming Windows and I have found no information that contributes to what I need to do.
    Here is what I need help with. I need to make a windown with text in the middle of it that displays "Percent: %X" X being a intiger that I submit to the function that makes thew window.
    Basicaly, a funtion that when I send a intiger to it, it opens up and then displays what is above. Then, it just dosn't close after it initially opens.
    I really need help on this.
    Thank you.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    And you can't build a string containing your display and just use TextOut() ??

    Comment

    • Studlyami
      Recognized Expert Contributor
      • Sep 2007
      • 464

      #3
      I'm not quite sure i fully understand the question. You need help closing the winodw? or creating the window? or centering the text?

      Comment

      • compman9902
        New Member
        • Mar 2007
        • 105

        #4
        Originally posted by Studlyami
        I'm not quite sure i fully understand the question. You need help closing the winodw? or creating the window? or centering the text?
        All of the above
        And then some

        Comment

        • kreagan
          New Member
          • Aug 2007
          • 153

          #5
          Originally posted by compman9902
          All of the above
          And then some
          Would message pop up work for you?
          MessageBox

          Comment

          • Studlyami
            Recognized Expert Contributor
            • Sep 2007
            • 464

            #6
            Message box is nice and it provides and OK which will close it when clicked.

            As for centering text here are the basic steps needed.


            Get total window width and height (windowrect.rig ht - windowrect.left ; windowrect.bott om - windowrect.top)

            divided total height and width by 2 (you want the center of the window).

            Now we have the center of the window we need to subtract half the size of the string width and half of the string height.

            Use GetTextExtentPo int32 and divide that number by 2 that will be your x,y value for drawing the font. You'll need to look up the parameters for GetTextExtentPo int32 i can never remember exactly how it works

            Comment

            • compman9902
              New Member
              • Mar 2007
              • 105

              #7
              Originally posted by Studlyami
              Message box is nice and it provides and OK which will close it when clicked.

              As for centering text here are the basic steps needed.


              Get total window width and height (windowrect.rig ht - windowrect.left ; windowrect.bott om - windowrect.top)

              divided total height and width by 2 (you want the center of the window).

              Now we have the center of the window we need to subtract half the size of the string width and half of the string height.

              Use GetTextExtentPo int32 and divide that number by 2 that will be your x,y value for drawing the font. You'll need to look up the parameters for GetTextExtentPo int32 i can never remember exactly how it works
              It would only work if the window would close automatically when a new number was submitted to the function and then opened up another with the submitted number.
              Actually.
              The above sounds perfect.
              If you can, please post code.

              Comment

              • Studlyami
                Recognized Expert Contributor
                • Sep 2007
                • 464

                #8
                Here is the basic way of centering the text on a given window. I was unable to get the dynamic window to work, but im sure a couple of the other people can help you out with that.

                Code:
                RECT TempRect;
                GetWindowRect(hWnd, &TempRect);
                LPCSTR myString = "This is the string to output";
                SIZE StringSize;
                GetTextExtentPoint32(GetDC(hWnd), (LPCTSTR) myString, 28, &StringSize);
                int Textx = (TempRect.right - TempRect.left)/2 - (StringSize.cx/2);
                int Texty =	(TempRect.bottom - TempRect.top)/2 - (StringSize.cy/2);
                TextOut(GetDC(hWnd),Textx,Texty,myString,28);
                That 28 is the number of chars in the string. I'm sure there is a way to get that dynamically, but im tired.

                Comment

                • compman9902
                  New Member
                  • Mar 2007
                  • 105

                  #9
                  Originally posted by Studlyami
                  Here is the basic way of centering the text on a given window. I was unable to get the dynamic window to work, but im sure a couple of the other people can help you out with that.

                  Code:
                  RECT TempRect;
                  GetWindowRect(hWnd, &TempRect);
                  LPCSTR myString = "This is the string to output";
                  SIZE StringSize;
                  GetTextExtentPoint32(GetDC(hWnd), (LPCTSTR) myString, 28, &StringSize);
                  int Textx = (TempRect.right - TempRect.left)/2 - (StringSize.cx/2);
                  int Texty =	(TempRect.bottom - TempRect.top)/2 - (StringSize.cy/2);
                  TextOut(GetDC(hWnd),Textx,Texty,myString,28);
                  That 28 is the number of chars in the string. I'm sure there is a way to get that dynamically, but im tired.
                  Thank yoyu very much..But, where do I put this to make the code work?

                  Comment

                  • Studlyami
                    Recognized Expert Contributor
                    • Sep 2007
                    • 464

                    #10
                    That would go after the new window is created. Instead of grabbing the rect for hWnd you would use the new window handle. If someone could help out with the dynamic window creation applying that code would make a lot more sense.

                    Comment

                    • compman9902
                      New Member
                      • Mar 2007
                      • 105

                      #11
                      Originally posted by Studlyami
                      That would go after the new window is created. Instead of grabbing the rect for hWnd you would use the new window handle. If someone could help out with the dynamic window creation applying that code would make a lot more sense.
                      Then it is agreed, I need help.
                      Anyone?

                      Comment

                      • compman9902
                        New Member
                        • Mar 2007
                        • 105

                        #12
                        Originally posted by weaknessforcats
                        And you can't build a string containing your display and just use TextOut() ??
                        Could you maybe write an example of how to use it? Becasue I have next to no experience with GUI in C++, so that would be great.

                        Comment

                        • compman9902
                          New Member
                          • Mar 2007
                          • 105

                          #13
                          Actually, I just thought of something. All I need is what goes under the "WM_PAINT" case and then I'll be golden.

                          Comment

                          • Studlyami
                            Recognized Expert Contributor
                            • Sep 2007
                            • 464

                            #14
                            So, you don't want a new window to be created then? If so, you don't want that code under the WM_PAINT.

                            Comment

                            • compman9902
                              New Member
                              • Mar 2007
                              • 105

                              #15
                              Originally posted by Studlyami
                              So, you don't want a new window to be created then? If so, you don't want that code under the WM_PAINT.
                              Oh, then I'm stuck. Any Tips? Anybody?
                              Also, just for future refrence, I was wondering what include to put in to the textout() function works. I'm using Dev-C++. Thanks.

                              Comment

                              Working...