|
Hi,
After reading your posting 3 times, i think that you wanted to a dll reference to another project, right?. If so, when you create a dll project with some export functions the IDE adds the exporting function as like
extern "C" __declspec(dllexport) void myFunc()
{
}
This tells the C++ complier not to use name mangling. So you can use LoadLbrary to get a pointer to this function in this dll like
HMODULE hMod = LoadLibrary("MyDlLL.dll");
GetProcAddress(hMod, "MyFunc");
this works well you specify extern "C"(Please see MSDN to know more about this).
For a dll that doesn't exports any functions/class don't allow accessing the its functions or classes.
If you don't wish to use the loadLibrary u can do the following steps to add a reference to a dll.
1. Mark the class as exported (__declspec(dllexport) class classA)
1. add the header file of the dll you want to refer.
2. Add the lib file of the dll to the linker options(Additional dependencies) of your project.
3. Make sure that you specify the path to lib correctly.
3. compile.
Hopes this helps.
Nitheesh George
http://www.simpletools.co.in
|
|
|
|
|
|
i'm surprised you read it that many times! ...i give up on the first try...if i can't read it, i won't try to answer it...lol
...you're a lot kinder...
|
|
|
|
|
Thank you Albert
Nitheesh George
http://www.simpletools.co.in
|
|
|
|
|
you get my 5 just for trying that hard to help someone!
|
|
|
|
|
How can I change background / text color of an CComboBox , but that have CBS_DROPDOWNLIST style ?
Thank you .
|
|
|
|
|
You need to handle OnCtlColor()[^] in your parent window to check (nCtlColor == CTLCOLOR_EDIT) condition for normal state.
You need to subclass CComboBox and handle OnCtlColor() to check (nCtlColor == CTLCOLOR_LISTBOX) condition for dropped down state, that is, while the list box is visible. In this case a child LB is created on the fly.
In OnCtlColor() members:
pDC->SetTextColor(clrTextColor));
pDC->SetBkColor(clrBkColor);
if(NULL == m_pBrush)
m_pBrush = new CBrush(clrBkColor);
return (HBRUSH)*m_pBrush;
Don't forget to return HBRUSHes in both cases.
|
|
|
|
|
posted your solution as a question... this isn't jeopardy!
...i was about to give you a 5 when i noticed all i could choose was "good question/bad question"...
|
|
|
|
|
|
Something I didn't do well , because at me is still white bkg/text color ...
|
|
|
|
|
Hi, which background you are talking about whether drop down list or in combo box itself.
|
|
|
|
|
I mean drop down list , not edit box where I succeded :
HBRUSH CComboBoxExt::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if(nCtlColor == CTLCOLOR_EDIT)
{
if(! m_bAlertText)pDC->SetTextColor(COLOR_BLACK);
else pDC->SetTextColor(COLOR_RED);
if(! m_bAlertBkg)pDC->SetBkColor(COLOR_WHITE);
else pDC->SetBkColor(COLOR_ALERT);
}
pDC->SetBkMode(TRANSPARENT);
if(m_bAlertBkg)return m_hBrushAlert;
return m_hBrushWhite;
}
well , I change CTLCOLOR_EDIT with CTLCOLOR_LISTBOX but with no effect ... I don't know why ...
|
|
|
|
|
In above code, that is, subclassed combo box's OnCtlColor() member, you should handle CTLCOLOR_LISTBOX for dropped-down list box.
May be, subclassing fails.
To ensure that above code is called, put the following line on top of function.
TRACE(_T("CComboBoxExt::OnCtlColor() was called with nCtlColor: %d\n"), nCtlColor);
And watch output window to see above phrase.
|
|
|
|
|
I think I am in dead point ... I use already OnCtlColorListBox but for other reason , and with other signature :
ON_MESSAGE(WM_CTLCOLORLISTBOX, OnCtlColorListBox)
...
...
LRESULT CComboBoxExt::OnCtlColorListBox(WPARAM wParam, LPARAM lParam)
{
if(m_hListBox == NULL)
{
HWND hWnd = reinterpret_cast<HWND>(lParam);
if(hWnd != 0 && hWnd != m_hWnd)
{
m_hListBox = hWnd;
m_pWndProc = reinterpret_cast<WNDPROC>(GetWindowLong(m_hListBox, GWL_WNDPROC));
SetWindowLong(m_hListBox, GWL_WNDPROC, reinterpret_cast<long>(ComboBoxListBoxProc));
}
}
return 1;
}
to get a handle to list box window ...
|
|
|
|
|
Yes. This blocks OnCtlColor(CTLCOLOR_LISTBOX). OnCtlColor() (WM_CTLCOLOR) is retained from 16Bit Windows and should be managed by MFC using newer messages like WM_CTLCOLORLISTBOX.
You can also use this handler to do your work, the HDC is wParam and you need to return a valid HBRUSH.
But, above return value is invalid (as brush). Probably, that listbox should paint itself if this doesn't produce a problem. In this case, how could you paint again?
|
|
|
|
|
To make a review :
ON_MESSAGE(WM_CTLCOLORLISTBOX, OnCtlColorListBox)
ON_WM_CTLCOLOR()
LRESULT CComboBoxExt::OnCtlColorListBox(WPARAM wParam, LPARAM lParam)
{
if(m_hListBox == NULL)
{
HWND hWnd = reinterpret_cast<HWND>(lParam);
if(hWnd != 0 && hWnd != m_hWnd)
{
m_hListBox = hWnd;
m_pWndProc = reinterpret_cast<WNDPROC>(GetWindowLong(m_hListBox, GWL_WNDPROC));
SetWindowLong(m_hListBox, GWL_WNDPROC, reinterpret_cast<long>(ComboBoxListBoxProc));
}
}
return 1;
}
HBRUSH CComboBoxExt::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor == CTLCOLOR_EDIT)
{
if(! m_bAlertText)pDC->SetTextColor(COLOR_BLACK);
else pDC->SetTextColor(COLOR_RED);
if(! m_bAlertBkg)pDC->SetBkColor(COLOR_WHITE);
else
{
pDC->SetBkColor(COLOR_ALERT);
hbr = m_hBrushAlert;
}
}
pDC->SetBkMode(TRANSPARENT);
return hbr;
}
|
|
|
|
|
Don't use both. Use 1st one.
LRESULT CComboBoxExt::OnCtlColorListBox(WPARAM wParam, LPARAM lParam)
{
...
CDC* pDC = CDC::FromHandle((HDC)wParam);
...
return hbr;
}
|
|
|
|
|
BTW, beware that list box is already subclassed by other reason. If it paints itself without using windows behaviour, that is, without sending WM_CTLCOLOR notifications to its parent, your attempt can be failed again.
|
|
|
|
|
I did not tried the subclassed combobox, but according to msdn,
http://msdn.microsoft.com/en-us/library/0wwk06hc(v=vs.80).aspx[^]
In subclassed combobox you have to handle CTLCOLOR_LISTBOX to change the color.
I tried handling OnCtlColor in dialog box,with nCtrClr == (IDOFCOMBOBOX),it is working
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (pWnd->GetDlgCtrlID() == IDC_COMBO1)
{
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(128,128, 128));
hbr = m_brush;
}
return hbr;
}
|
|
|
|
|
I solve the problem in the follow matter :
CListBox m_ListBox;
ON_WM_CTLCOLOR()
HBRUSH CComboBoxExt::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor == CTLCOLOR_EDIT)
{
if(m_Edit.GetSafeHwnd() == NULL)
{
m_Edit.SubclassWindow(pWnd->GetSafeHwnd());
}
if(! m_bAlertText)pDC->SetTextColor(COLOR_BLACK);
else pDC->SetTextColor(COLOR_RED);
if(! m_bAlertBkg)pDC->SetBkColor(COLOR_WHITE);
else
{
pDC->SetBkColor(COLOR_ALERT);
hbr = m_hBrushAlert;
}
}
if(nCtlColor == CTLCOLOR_LISTBOX)
{
if(m_ListBox.GetSafeHwnd() == NULL)
{
m_ListBox.SubclassWindow(pWnd->GetSafeHwnd());
m_pWndProc = reinterpret_cast<WNDPROC>(GetWindowLong(m_ListBox, GWL_WNDPROC));
SetWindowLong(m_ListBox, GWL_WNDPROC, reinterpret_cast<long>(ComboBoxListBoxProc));
}
if(! m_bAlertBkg)pDC->SetBkColor(COLOR_WHITE);
else
{
pDC->SetBkColor(COLOR_ALERT);
hbr = m_hBrushAlert;
}
}
pDC->SetBkMode(TRANSPARENT);
return hbr;
}
I get handle of drop down list box in OnCtlColor
but I still have an question :
How can I change text / background color of edit while combo box have CBS_DROPDOWNLIST style ?
|
|
|
|
|
Finllay I solve my problem , and for that I thank you very much , for you kindness and for your patient . ! Best wishes !
|
|
|
|
|
I solve the problem in follow way :
class CMyComboBox : public CComboBox
{
afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
};
and
ON_WM_CTLCOLOR_REFLECT()
END_MESSAGE_MAP()
HBRUSH CMyComboBox::CtlColor(CDC* pDC, UINT nCtlColor)
{
HBRUSH hBrush = NULL;
switch(nCtlColor)
{
case CTLCOLOR_EDIT:
{
pDC->SetBkColor(RGB(255, 0, 0));
pDC->SetTextColor(RGB(255, 255, 255));
hBrush = m_brush;
}
break;
}
return hBrush;
}
|
|
|
|
|
Hi,
I have drived a class from CView and create class instance using new.
I am confused in deleting view.
Shell I use delete view;
Or view->DestroyWindow();
|
|
|
|
|
Call DestroyWindow() , then delete ...
|
|
|
|
|
If I do call this, I got exception.
|
|
|
|