Results 1 to 3 of 3

Thread: Setting A TextBox's font

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516

    Red face

    I know this is probably not how you should do it, nut why won't this work:

    Code:
       HWND hWnd;
    
       hInst = hInstance;
    
       hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
          CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
    
       Text1 = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", "1", WS_CHILD | ES_NUMBER, 20,20, 80, 25, hWnd,0, hInst, NULL);
       
       HFONT hFont;
       HDC hDC;
       SIZE TxtSize;
       CHAR* Tahoma = "Tahoma";
    
       ShowWindow(Text1, nCmdShow);
    
       hDC = GetDC(Text1);
    
       GetTextExtentPoint32(hDC, "T", 1, &TxtSize);
       
       hFont = (HFONT) CreateFont( TxtSize.cx , 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, 0, Tahoma);
    
       SelectObject(hDC, hFont);
       
       ReleaseDC(Text1, hDC);
       
       if ((!hWnd) && (!Text1))
       {
          return FALSE;
       }
    
       ShowWindow(hWnd, nCmdShow);
       UpdateWindow(hWnd);
    
       return TRUE;
    Unless you didn't get it, I'm trying to set the TextBox's font to Tahoma. It doesn't raise any errors, but the font is always that boldish systemy font.

    Any help?
    Courgettes.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You have to send it a WM_SETFONT message:
    Code:
    SendMessage(Text1, WM_SETFONT, (WPARAM)Tahoma, TRUE);
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516

    <ahem>

    I knew that all along.

    Thanks,

    Moi.
    Courgettes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width