Thread: multicolor dialog & multicolor text

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    380

    multicolor dialog & multicolor text

    Hey how would i create a multicolor dialog? For example I want the top half to be black that contains a edit text box and a list box. While the bottom is purple and has another text box, a combo box, and a pushbutton.

    Attached is what I would like to have.
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    One solution is to derive your own relevant controls and the dialog class. Do custume-draw.

    Kuphryn

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Another option is to handle the WM_ERASEBKGND and draw the dialog's background, eg:
    Code:
    case WM_ERASEBKGND:
      {
      RECT rcDlg,rcTop,rcBottom;
      HBRUSH hbrTop,hbrBottom;
      HDC hdc;
      
      hdc=(HDC)wParam;
      GetClientRect(hDlg,&rcDlg);
      SetRect(&rcTop,0,0,rcDlg.right,rcDlg.bottom-60);
      SetRect(&rcBottom,0,rcDlg.bottom-60,rcDlg.right,rcDlg.bottom);
      //create a black and a purple brush...
      hbrTop=CreateSolidBrush(RGB(0,0,0));
      hbrBottom=CreateSolidBrush(RGB(200,0,200));
      //...and use them to paint designated areas
      FillRect(hdc,&rcTop,hbrTop);
      FillRect(hdc,&rcBottom,hbrBottom);
      //free gdi resources
      DeleteObject(hbrTop);
      DeleteObject(hbrBottom);
      return TRUE;
      }
    Where hDlg is the handle of your dialog box. If you intend resizing your dialog you should handle the WM_SIZE and InvalidateRect(hDlg,0,1); to ensure proper drawing of the background. Adjust proportions to suit and it's probably better to initialise the background brushes when your app starts and delete them when your app finishes.

    Hope that helps.

    edit: typos
    Last edited by Ken Fitlike; 12-10-2002 at 07:10 PM.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    Thank you for your help. Your solution helped me achieve what I wanted.

    I have more one question. Do you know how to give the controls a 2-D border instead of the 3-D look?
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  5. #5
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>Do you know how to give the controls a 2-D border instead of the 3-D look?<<

    Depends on the control. For flat buttons, give them the BS_FLAT style, for other controls you'll have to experiment but make sure that they don't have the WS_EX_CLIENTEDGE as this style is responsible for making them appear 'sunken'.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    I have checked the recourse script and there is WS_EX_CLIENTEDGE style.
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  7. #7
    Registered User
    Join Date
    Aug 2001
    Posts
    380

    multicolor text

    I'm trying make my program output different colors for different type of messages.
    For regular messages I want them to be white.
    For Private Messages I want them to be cyan.
    For Actions I want them to be yellow.
    For Arrive and Leave messages I want them to be Green.

    I have tried using if statements while handling the WM_CTLCOLORSTATIC message, but they all stay one color.
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  8. #8
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    If you want that degree of colour formatting with a single control then you should probably either use a rich edit control or design your own owner drawn control.

  9. #9
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    How do I write a rich edit control using a resource script?

    Is this it?
    Code:
    RICHEDIT IDC_EDIT2, 4, 3, 149, 120, ES_AUTOVSCROLL | ES_READONLY
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  10. #10
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You are probably better using CreateWindowEx in your WM_INITDIALOG handler (for dialogs) because there are different versions of richedit control with different wnd class names depending on the system dll available (richedit20.dll or richedit32.dll).

    However, if you are certain that your target system will only use one or the other then you may be able use the CONTROL resource definition statement in your resource script giving the specific class name eg for richedit v2.0+:
    Code:
    CONTROL "some text", IDC_EDIT2, RICHEDIT_CLASS, WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE, 0, 0, 400, 400, WS_EX_CLIENTEDGE
    You will still have to use LoadLibrary (your WM_INITDIALOG handler is a good place) to map the necessary richedit dll into the address space of your app, eg for richedit v2.0+:
    Code:
    HINSTANCE hLib=LoadLibrary(TEXT("riched20.dll"));
    Don't forget to use FreeLibrary when you are done with the HINSTANCE returned from your use of LoadLibrary.

    Hope that helps.
    Last edited by Ken Fitlike; 12-15-2002 at 01:44 AM.

  11. #11
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    I have change the resource to your method but the borland resource compiler says "Expecting class name or ID." I also tried using CreateWindowEx and it always failed.

    Code:
    hEdit = CreateWindowEx(0,"RICHEDIT_CLASS", "", 
    WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL |  ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL, 0, 0, 100, 100, 
    hwnd, (HMENU)IDC_MAIN_EDIT, 
    GetModuleHandle(NULL), NULL);
    if(hEdit == NULL)
       MessageBox(hwnd, "Could not create edit box", "Error!", MB_OK | MB_ICONERROR);
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  12. #12
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    ...and #include <richedit.h>

    RICHEDIT_CLASS is defined as follows:
    Code:
    #if defined UNICODE
    #define RICHEDIT_CLASS L"RichEdit20W"
    #else
    #define RICHEDIT_CLASS "RichEdit20A"     
    #endif
    so if you still get errors with the resource script then just use the explicit UNICODE or ANSI string class name.

    Assuming you have #included richedit.h, have you remembered to load the correct richedit dll prior to attempting to create the richedit wnd? If you have not, then creation will fail in either case.

  13. #13
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    That appears to make it compile. The code you have posted defines RichEdit v2.0 and not v1.0?
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  14. #14
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>The code you have posted defines RichEdit v2.0 and not v1.0?<<

    Yes. I suggested that for ease of use. If you would like a more complete example that ensures the loading of the most recent richedit dll available then see the one on [shameless plug]my wee, humble website[/shameless plug]; but it's only good when using CreateWindowEx/CreateWindow.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  15. #15
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    Thank you for your help. All my questions have been answered. I have look at your website and will be spending some time there.
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

Popular pages Recent additions subscribe to a feed