Question

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

Était-ce utile?

La solution

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.

Autres conseils

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.

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top