Visual C++6: how to change font for list box & TCP/IP(Help!)

  • 13 years ago

    Q1)

    How can I change the font for a list box? I am learning Visual C++ 6.  I have tried

       m_cltList.SetFont((CFont *)"Courier New") ;

    but obviously it does not work!! Please help me!!

     

    Q2)

    I am trying to develop a client application in Visual C++ 6 (the server in C and it runs well!). Receive() in the program incurs an error WSAEWOULDBLOCK!! 

     

        i.e. if ((iRcvd=m_sConnectSocket.Receive(..))==SOCKET_ERROR) {

                 switch(iError=GetLastError()){

                       case WSAEWOULDBLOCK:

                                        :

              } // if

    To get around this problem, I introduced a loop which contains the Receive() statement, ignores WSAEWOULDBLOCK and breaks only when some data is received.  With this, the program runs but I feel that I have not addressed the problem correctly.  Please tell me how you would solve this problem!  Do I have to use SetSockOpt() or IOCtl() to address this problem!!  The server is in the blocking mode!!

    Many thanks

    Chong

  • 13 years ago

    From CodeGuru.com (by Andreas Masur) :

    (http://www.codeguru.com/forum/showthread.php?t=322238&goto=nextoldest)

    The following is an example how to change the font for a static control...the example is a dialog-based application which does not matter regarding the setting of the font itself...

    // Dialog.hpp
    class CYourDlg : public CDialog
    {
    public:
      ~CYourDlg() { m_Font.DeleteObject(); }
      ...

    private:
      CFont m_Font;
    };

    // Dialog.cpp
    BOOL CYourDlg::OnInitDialog()
    {
      CDialog::OnInitDialog();

      // Creates a 12-point-Courier-font
      m_Font.CreatePointFont(120, _T("Courier"));

      // With a member variable associated to the static control
      m_MyStatic.SetFont(&m_Font);

      // Without a member variable
      GetDlgItem(IDC_MY_STATIC)->SetFont(&m_Font);
    }

    The font itself can be created in many ways...the only important thing is that the font object itself exists as long as the control...in other words....keep it as a member of the control or surrounding dialog....

    // First way
    CFont Font;

    Font.CreateFont(12,                            // Height
                    0,                             // Width
                    0,                             // Escapement
                    0,                             // Orientation
                    FW_BOLD,                       // Weight
                    FALSE,                         // Italic
                    TRUE,                          // Underline
                    0,                             // StrikeOut
                    ANSI_CHARSET,                  // CharSet
                    OUT_DEFAULT_PRECIS,            // OutPrecision
                    CLIP_DEFAULT_PRECIS,           // ClipPrecision
                    DEFAULT_QUALITY,               // Quality
                    DEFAULT_PITCH | FF_SWISS,      // PitchAndFamily
                    "Arial"));                     // Facename



    // Second way
    CFont   Font;
    LOGFONT lfLogFont;

    memset(&lfLogFont, 0, sizeof(lfLogFont));

    lfLogFont.lfHeight    = 12;                    // 12-pixel-height
    lfLogFont.lfWeight    = FW_BOLD;               // Bold
    lfLogFont.lfUnderline = TRUE;                  // Underlined

    strcpy(lfLogFont.lfFaceName, "Arial");         // Arial

    Font.CreateFontIndirect(&lfLogFont);



    // Third way
    CFont   Font;
    LOGFONT lfLogFont;

    memset(&lfLogFont, 0, sizeof(lfLogFont));

    lfLogFont.lfHeight    = 120;                   // 12-pixel-height
    lfLogFont.lfWeight    = FW_BOLD;               // Bold
    lfLogFont.lfUnderline = TRUE;                  // Underlined

    strcpy(lfLogFont.lfFaceName, "Arial");         // Arial

    Font.CreatePointFontIndirect(&lfLogFont);

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“If Java had true garbage collection, most programs would delete themselves upon execution.” - Robert Sewell