4

I am trying to get my dialog box to match. I have been all through google, random testing, etc, even read some places it cant be done.

What I have been able to do is to use one of the messages to set font and colors, but nowhere about drawing itself.

I would think it has to be able to do...

Does anyone have any ideas? Or know anything about this?

http://imageshack.com/a/img832/5955/91m.png

Evan Carslake
  • 2,267
  • 15
  • 38
  • 56
  • Does your control by any chance have the `WS_EX_CLIENTEDGE` style applied to it? Also, are you creating this with the Visual Studio resource editor or by hand? – Joel Jul 31 '13 at 04:56
  • I am doing the resource files by hand, and used the BS_OWNERDRAW on the buttons, even has up/ down state drawn. I am using wxDev-CPP. EDITTEXT IDC_TIMEINPUT, 5, 135, 160, 12, ES_CENTER//| EMS_OWNERDRAW CONTROL "Status", IDC_STATUSBAR, STATUSCLASSNAME, 0, 0, 0, 0, SBT_OWNERDRAW Is the lines as they are in the resource file. I was trying to custom draw the status bar as well, but it as the same trouble with the "raised edges." Also, I did not have WS_EX_CLIENTEDGE specified anywhere. Thanks for the reply. – Evan Carslake Jul 31 '13 at 05:11
  • 1
    It looks like edit controls in resource scripts have some styles set by default. If I create a dialog in Visual Studio and turn off the border, the code is `EDITTEXT IDC_EDIT1,17,51,136,14,ES_AUTOHSCROLL | NOT WS_BORDER`, rather than including `WS_BORDER` when the border is set to on. – Joel Jul 31 '13 at 05:21
  • This link confirms that: http://msdn.microsoft.com/en-us/library/windows/desktop/aa381009%28v=vs.85%29.aspx – Joel Jul 31 '13 at 05:22
  • Independently of how resource files work, if all you need is simple text display you could try using static text controls instead of edit controls and status bar. They definitely support flat appearance and color customization. It also wouldn't be all that difficult to roll your own. If you need full text editing capabilities, then it gets harder, but not really all that hard. – Joel Jul 31 '13 at 05:36
  • ^ Thank you. That is exactly what I needed, solved. Now, just one other side issue, I can't figure out how to get rid of the edges around the status bar. – Evan Carslake Jul 31 '13 at 05:40
  • Cool. Adding as an answer, then. – Joel Jul 31 '13 at 05:45
  • True. Really for this application I need the edit (for custom time(s).) The status bar I could easily go without, but I am really wanting to figure this stuff out for future reference. From the screenshot, I was able to color the area, and change the font, but I couldn't figure out how to remove the border. – Evan Carslake Jul 31 '13 at 06:22
  • Updated my answer with an owner-drawn status bar. I wasn't able to get rid of the size grip when I tried it, but yours doesn't appear to have one, anyway. – Joel Jul 31 '13 at 13:44

3 Answers3

2

It looks like edit controls don't support owner draw, but you can still solve your direct problem. According to the MSDN page for EDITTEXT, by default edit controls in a resource file have the WS_BORDER style set. Looks like you can get rid of it with something like this:

EDITTEXT IDC_EDIT1,17,51,136,14,ES_AUTOHSCROLL | NOT WS_BORDER

For the status bar, you might try using a static control with customized colors instead of a real status bar. Or you could roll your own, specify the window class name in the resource file, and make sure you register the class before displaying the dialog.

UPDATED: Wow, the documentation for status bar is terrible. You can owner draw one, though. Follow these steps:

// where hStatus is the HWND of a status bar...

// You must set simple mode to false, because simple mode doesn't
// support owner draw.

SendMessage(hStatus, SB_SIMPLE, FALSE, 0);

// I'm assuming 1 status bar part for demonstration. Setting the right edge
// for the 1 part to -1 make it take up the whole status bar.

int partWidths[] = { -1 };

SendMessage(hStatus, SB_PARTS, 1, reinterpret_cast<LPARAM>(partWidths));

// There is background stuff that stays behind even with owner draw,
// so you have to set the background color to black, too, to get rid of
// any appearance of borders.

SendMessage(hStatus, SB_SETBKCOLOR, 0, RGB(0, 0, 0));

// There is still a slim border that stays behind, so you need to set
// SBT_NOBORDERS in addition to SBT_OWNERDRAW. The 0 is the index of the
// status bar part. It could be anything between 0 and 255.

SendMessage(
    hStatus,
    SB_SETTEXT,
    SBT_NOBORDERS | SBT_OWNERDRAW | 0,
    reinterpret_cast<LPARAM>(_T("Status")));

From there, you must also handle the WM_DRAWITEM for the status bar. Now, as to why I say the documentation for status bar is terrible...

Docs for SB_SETTEXT say the high byte of the low order word of the WPARAM can be one of the values that follows. There are two problems with this:

  1. You can combine them, and you must for this to work. MFC does it, too. I checked.

  2. You might be tempted to write MAKEWPARAM(MAKEWORD(0, SBT_OWNERDRAW), 0). This will not work. By appearances, the SBT_ styles are defined so that they will automatically appear in the high byte of the low word if you just OR them with your index value.

That I had to look at the MFC source code to figure out how to use SB_SETTEXT correctly is telling.

Joel
  • 1,135
  • 6
  • 9
  • Thanks! That made some progress with the status bar looking how I want it to. Still working with it. Back to the edit, I am finding it all but possible to vertical align the text. I have googled everything, and closest thing I could find was TextAlign(), which would change the alignment to fixed positions and none vertically centered. I've spent a couple of hours on this, everything being done through WM_CTLCOLOREDIT, no progress. Any ideas on this? – Evan Carslake Jul 31 '13 at 19:56
  • You might be able to play around with some combination of `EM_SETRECT` and `EM_SETLIMITTEXT`, but since `EM_SETRECT` apparently only works on multiline edit controls that seems pretty hacky to me (although it is part of the API). I haven't actually tried it, so I can't guarantee it will work. – Joel Aug 01 '13 at 02:01
1

Edit controls do not have an owner-draw mode, however you can subclass an Edit control and process messages like WM_ERASEBKGND, WM_NCPAINT, WM_PAINT, etc, as well as the WM_CTLCOLOREDIT message sent to the edit's parent window.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 1
    That doesn't work either, the Edit control partially repaints without using WM_PAINT. Very, very naughty but a necessary hack back when it had to run on a 386SUX machine. – Hans Passant Jul 31 '13 at 07:01
0

The answer for part 2, vertical aligning text in an edit:

        RECT rect;
        GetClientRect(GetDlgItem(hwnd, IDC_TIMEINPUT),&rect);          
        Rectangle(hdcEdit, rect.left, rect.top, rect.right, rect.bottom);            
        rect.left+=5; rect.top+=5; rect.right+=5; //rect.bottom+=5;
        SendMessage(GetDlgItem(hwnd, IDC_TIMEINPUT), EM_SETRECTNP, 0, (LPARAM)&rect);

Has to be multi-line, and you really do have to play around with different numbers to keep it single lined, and maintain the vertical align. The EMS_SETRECTNP allows you to specify where you want the text to be, allowing the Edit to have a larger height.

Evan Carslake
  • 2,267
  • 15
  • 38
  • 56