Background для диалогового окна
От: бонифаций  
Дата: 24.09.02 14:51
Оценка:
Господа,
похоже я заблудился в трех соснах! Помогите! Как поменять цвет фона немодального диалогового окна? Я делал так:
        WndClass.style         = CS_HREDRAW|CS_VREDRAW;
    WndClass.lpfnWndProc   = MTDialogWndProc;
    WndClass.cbClsExtra    = 0;
    WndClass.cbWndExtra    = DLGWINDOWEXTRA;
    WndClass.hInstance     = hInstance;
       WndClass.hIcon         = NULL;
       WndClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
       WndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);//черный фон
       WndClass.lpszMenuName  = NULL;
    WndClass.lpszClassName = "MyOwnDialogClass";
        
    RegisterClass(&WndClass);

    CreateDialogParam(hInstance, 
               lpszResName,hwndParent,
              (DLGPROC)MTDialogProc,
              (long)this);


RegisterClass сработала, т.е. вернула ненулевое значение, а CreateDialogParam вернула ручку окна. Окно появилось, но вместо черного фона я вижу стандартный серый!...

Re: Background для диалогового окна
От: old Dutchman Беларусь http://blogs.rsdn.org/ikemefula
Дата: 24.09.02 15:05
Оценка:
Здравствуйте бонифаций, Вы писали:

Б>Господа,

Б>похоже я заблудился в трех соснах! Помогите! Как поменять цвет фона немодального диалогового окна? Я

WM_ERASEBKGND перехватывай и обрабатывай в нем

WM_ERASEBKGND
The WM_ERASEBKGND message is sent when the window background must be erased (for example, when a window is resized). The message is sent to prepare an invalidated portion of a window for painting.

A window receives this message through its WindowProc function.

LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_ERASEBKGND
WPARAM wParam, // handle to device context (HDC)
LPARAM lParam // not used
);
Parameters
wParam
Handle to the device context.
lParam
This parameter is not used.
Return Values
An application should return nonzero if it erases the background; otherwise, it should return zero.

Remarks
The DefWindowProc function erases the background by using the class background brush specified by the hbrBackground member of the WNDCLASS structure. If hbrBackground is NULL, the application should process the WM_ERASEBKGND message and erase the background.

An application should return nonzero in response to WM_ERASEBKGND if it processes the message and erases the background; this indicates that no further erasing is required. If the application returns zero, the window will remain marked for erasing. (Typically, this indicates that the fErase member of the PAINTSTRUCT structure will be TRUE.)



wParam — это HDC — в него рисуешь хучь битмап, хучь просто закрашивай
Re: Background для диалогового окна
От: _Kostya_  
Дата: 24.09.02 15:18
Оценка:
Здравствуйте бонифаций, Вы писали:

Б>Господа,

Б>похоже я заблудился в трех соснах! Помогите! Как поменять цвет фона немодального диалогового окна? Я делал так:
Б>
Б>        WndClass.style         = CS_HREDRAW|CS_VREDRAW;
Б>    WndClass.lpfnWndProc   = MTDialogWndProc;
Б>    WndClass.cbClsExtra    = 0;
Б>    WndClass.cbWndExtra    = DLGWINDOWEXTRA;
Б>    WndClass.hInstance     = hInstance;
Б>       WndClass.hIcon         = NULL;
Б>       WndClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
Б>       WndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);//черный фон
Б>       WndClass.lpszMenuName  = NULL;
Б>    WndClass.lpszClassName = "MyOwnDialogClass";
Б>        
Б>    RegisterClass(&WndClass);

Б>    CreateDialogParam(hInstance, 
Б>               lpszResName,hwndParent,
Б>              (DLGPROC)MTDialogProc,
Б>              (long)this);
Б>



Так ты ведь и не задаешь никакой цвет! То окно, которое создается CreateDialogParam относится к общему классу диалоговых оког, а класс MyOwnDialogClass никак не используется.
Для изменения цвета нужно перехватывать WM_ERASEBACKGROUND в процедуре MTDialogProc
Re[2]: Background для диалогового окна
От: бонифаций  
Дата: 25.09.02 08:14
Оценка:
Здравствуйте old Dutchman, Вы писали:

OD>Здравствуйте бонифаций, Вы писали:


Б>>Господа,

Б>>похоже я заблудился в трех соснах! Помогите! Как поменять цвет фона немодального диалогового окна? Я

OD>WM_ERASEBKGND перехватывай и обрабатывай в нем


OD>WM_ERASEBKGND

OD>The WM_ERASEBKGND message is sent when the window background must be erased (for example, when a window is resized). The message is sent to prepare an invalidated portion of a window for painting.

OD>A window receives this message through its WindowProc function.


OD>LRESULT CALLBACK WindowProc(

OD> HWND hwnd, // handle to window
OD> UINT uMsg, // WM_ERASEBKGND
OD> WPARAM wParam, // handle to device context (HDC)
OD> LPARAM lParam // not used

OD>Parameters

OD>wParam
OD>Handle to the device context.
OD>lParam
OD>This parameter is not used.
OD>Return Values
OD>An application should return nonzero if it erases the background; otherwise, it should return zero.

OD>Remarks

OD>The DefWindowProc function erases the background by using the class background brush specified by the hbrBackground member of the WNDCLASS structure. If hbrBackground is NULL, the application should process the WM_ERASEBKGND message and erase the background.

OD>An application should return nonzero in response to WM_ERASEBKGND if it processes the message and erases the background; this indicates that no further erasing is required. If the application returns zero, the window will remain marked for erasing. (Typically, this indicates that the fErase member of the PAINTSTRUCT structure will be TRUE.)


OD>

OD>wParam — это HDC — в него рисуешь хучь битмап, хучь просто закрашивай


Спасибо за ответ, у меня получилось!
Re[2]: Background для диалогового окна
От: бонифаций  
Дата: 25.09.02 08:16
Оценка:
Здравствуйте _Kostya_, Вы писали:

K>Здравствуйте бонифаций, Вы писали:


Б>>Господа,

Б>>похоже я заблудился в трех соснах! Помогите! Как поменять цвет фона немодального диалогового окна? Я делал так:
Б>>
Б>>        WndClass.style         = CS_HREDRAW|CS_VREDRAW;
Б>>    WndClass.lpfnWndProc   = MTDialogWndProc;
Б>>    WndClass.cbClsExtra    = 0;
Б>>    WndClass.cbWndExtra    = DLGWINDOWEXTRA;
Б>>    WndClass.hInstance     = hInstance;
Б>>       WndClass.hIcon         = NULL;
Б>>       WndClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
Б>>       WndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);//черный фон
Б>>       WndClass.lpszMenuName  = NULL;
Б>>    WndClass.lpszClassName = "MyOwnDialogClass";
Б>>        
Б>>    RegisterClass(&WndClass);

Б>>    CreateDialogParam(hInstance, 
Б>>               lpszResName,hwndParent,
Б>>              (DLGPROC)MTDialogProc,
Б>>              (long)this);
Б>>


K>

K>Так ты ведь и не задаешь никакой цвет! То окно, которое создается CreateDialogParam относится к общему классу диалоговых оког, а класс MyOwnDialogClass никак не используется.
K>Для изменения цвета нужно перехватывать WM_ERASEBACKGROUND в процедуре MTDialogProc

Спасибо за ответ! У меня получилось!
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.