Thread: A couple of static control questions

  1. #1
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584

    A couple of static control questions

    I am writing this program that the user, one way or another, puts in a question and the question is then sent to the static to be viewed by the program. But, I don't know how long this question will be. How would I do something like this with an unknown length of string to put in the static? How "big" would I make it?

    And, when you SetWindowText for the static, how do you previously clear the static so it's not written over, but replaces the previous text of the static? I don't recall how to do this.

    Thanks!
    1978 Silver Anniversary Corvette

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Well, I'm pretty sure that if your call to SetWindowText() is writing OVER (and not erasing) the old text, then there may be a problem with your WM_PAINT handler....

    As far as the size of the control, unless the user will be typing a novel, you can safely assume it will be of a certain size...say 50-200-500, etc. It won't hurt to go a little large on that....
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    >> then there may be a problem with your WM_PAINT handler.... <<

    But, I don't handle the WM_PAINT for the static, do I? I didn't write the WndProc for it, it's with the API. Right?
    1978 Silver Anniversary Corvette

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You could dynamically size the static if need be but it might be a better idea to go with a read-only edit control; that way the user can scroll the info into view. It also sidesteps the possibility that the control may be too big to fit within its parent's client area.

    Generally for sizing text I might use:

    Code:
    HDC hdc=GetDC(hwnd); //parent wnd will do
    TCHAR chTxt[]=TEXT("The Text");
    SIZE sz;
    //get string dimensions
    GetTextExtentPoint32(hdc,chTxt,lstrlen(chTxt),&sz);
    //liberate dc
    ReleaseDC(hwnd,hdc);
    //resize static, where 'hwndStatic' is static cntrl wnd handle
    //and 'Left' is top-left x-coord and 'Top' is top-left y-coord
    MoveWindow(hwndStatic,Left,Top,sz.cx,sz.cy+4,1);
    Or something like that. Hope that is of some use, Garfield.

  5. #5
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    I'll see what I can do with that, Ken, thanks!

    So do I need to handle the WM_PAINT of the static? That's not possible, right?
    1978 Silver Anniversary Corvette

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    You could sublass any control and add a handler...but I agree with Ken that a read-only edit is mush easier to use .........

  7. #7
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Yeah, I mightaswell try that. But, I always thought that the WndProc of the static "erased" the window (static window) when you resend text to it. Oh well, I guess I was wrong ...
    1978 Silver Anniversary Corvette

  8. #8
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584

    Resizing the readonly edit

    I'm going to have to resize the readonly edit, right?
    1978 Silver Anniversary Corvette

  9. #9
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Create an edit control with the 'ES_AUTOHSCROLL' style ( and ES_READONLY) and set its width to something suitable for your main window. When you put some text that is too long to 'fit' completely within the length of the edit control the user only needs to set the focus ( or you, the programmer can do it) to that edit control and can use the arrow keys to scroll the hidden text into view. Alternatively, the user can left-click and 'copy' the contents using the pop-up menu option. Both of these features are fairly standard with this type of control.

    Hope that helps some. Good luck

  10. #10
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    I didn't want to make the control single line. Then to read the whole question, the user has to click and then frequently type the "->" key. That's not really convenient, don't you agree?
    1978 Silver Anniversary Corvette

  11. #11
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    then set the multiline style. simple.

    experiment with things by yourself rather than constantly posting questions that are really simple.. you'll be amazed at what you can learn!

    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  12. #12
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    I just got the multiline thing fine. But, now I tried to set the background mode of it TRANSPARENT, but it doesn't seem to be working. Don't I hand the WM_CTLCOLOREDIT message? I couldn't find how to do an edit in Petzold or Ground Up.
    1978 Silver Anniversary Corvette

  13. #13
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    For read-only edits handle the WM_CTLCOLORSTATIC instead.

    ( And welcome to the internal consistency of the win32 api. )

    nb: you could always try the WS_EX_TRANSPARENT extended style for the edit to make it transparent.

  14. #14
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    >> nb: you could always try the WS_EX_TRANSPARENT extended style for the edit to make it transparent. <<

    Ah! I believe I will just take this alternative...

    >> For read-only edits handle the WM_CTLCOLORSTATIC instead.<<

    I tried this, but when I highlighted the text, the bk turned blue
    1978 Silver Anniversary Corvette

  15. #15
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Okay, I used the WS_EX_TRANSPARENT style for CreateWindowEx, but it's still not working!!! Here is a screen shot that has the code in the background and the program that I wrote is in focus for you to see that it isn't transparent!!! Please help me! Thanks!
    1978 Silver Anniversary Corvette

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  2. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  3. Static Control Bitmap Style
    By Nurfina in forum Windows Programming
    Replies: 2
    Last Post: 04-14-2007, 05:51 AM
  4. Couple of Questions
    By toonlover in forum Windows Programming
    Replies: 10
    Last Post: 07-14-2006, 01:04 AM
  5. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM