View Full Version: Changing font in Edit Control

C++ Learning Community > C++ Help > Changing font in Edit Control


Title: Changing font in Edit Control
Description: Question regarding win32 application


Dragon - June 25, 2003 11:17 PM (GMT)
I have the code below so far. It doesn't do anything yet and just displays an edit control. Can someone please tell me how to change the font of the text inside the control?

QUOTE
#if ! defined EditControlsH
#define EditControlsH

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

LRESULT CALLBACK WndProc(HWND hwnd,UINT Message,WPARAM wParam,LPARAM lParam);
HINSTANCE g_hInst;

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
  HWND hwnd;
  MSG Msg;
  HICON hIcon;
  HCURSOR hCursor;
  TCHAR chClassName[] = TEXT("SIMPLEWND");
  WNDCLASSEX wcx;
  g_hInst = hInstance;
 
  hIcon = (HICON)LoadImage(0,IDI_APPLICATION,IMAGE_ICON,0,0,LR_SHARED);
  hCursor = (HCURSOR)LoadImage(0,IDC_ARROW,IMAGE_CURSOR,0,0,LR_SHARED);
  wcx.cbSize = sizeof(WNDCLASSEX);
  wcx.style = CS_HREDRAW|CS_VREDRAW;
  wcx.lpfnWndProc = (WNDPROC)WndProc;
  wcx.cbClsExtra = 0;
  wcx.cbWndExtra = 0;
  wcx.hInstance = hInstance;
  wcx.hIcon = hIcon;
  wcx.hCursor = hCursor;
  wcx.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
  wcx.lpszMenuName = NULL;
  wcx.lpszClassName = chClassName;
  wcx.hIconSm = NULL;
 
  if ( ! RegisterClassEx(&wcx))
  {
    MessageBox(NULL,
              TEXT("Failed to register wnd class"),
              TEXT("Error"),
              MB_ICONERROR|MB_OK);
    return FALSE;
  }
 
  hwnd = CreateWindowEx(0,
                        chClassName,
                        TEXT("Edit Controls"),
                        WS_OVERLAPPEDWINDOW,
                        GetSystemMetrics(SM_CXSCREEN) / 4,
                        GetSystemMetrics(SM_CYSCREEN) / 4,
                        GetSystemMetrics(SM_CXSCREEN) / 2,
                        GetSystemMetrics(SM_CYSCREEN) / 2,
                        NULL,
                        NULL,
                        hInstance,
                        NULL);
 
  if ( ! hwnd)
  {
    MessageBox(NULL,
              TEXT("Failed to create wnd"),
              TEXT("Error"),
              MB_ICONERROR|MB_OK);
    return FALSE;
  }
 
  ShowWindow(hwnd, nCmdShow);
  UpdateWindow(hwnd);
 
  while (GetMessage(&Msg,NULL,0,0) > 0)
  {
    TranslateMessage(&Msg);
    DispatchMessage(&Msg);
  }
return Msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd,UINT Message,WPARAM wParam,LPARAM lParam)
{
  switch (Message)
  {
    case WM_CREATE:
      CreateWindowEx(WS_EX_CLIENTEDGE,
                    TEXT("EDIT"),
                    TEXT("Single Line Edit Control"),
                    WS_CHILD|WS_VISIBLE|WS_BORDER|
                    ES_MULTILINE,
                    10,
                    10,
                    200,
                    30,
                    hwnd,
                    NULL,
                    g_hInst,
                    NULL);
      return 0;
    case WM_DESTROY:
      PostQuitMessage(0);
      return 0;
    default:
      return DefWindowProc(hwnd,Message,wParam,lParam);
  }
}
#endif




* Hosted for free by InvisionFree