|
How can I change the background color of my CComboBox , but only in the edit area , not dropdown list ?
I have something like :
class CStatusCombo : public CComboBox
and here :
HBRUSH CStatusCombo::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);
switch(nCtlColor)
{
case CTLCOLOR_LISTBOX:
pDC->SetTextColor(RGB(0, 255, 0));
pDC->SetBkColor(RGB(120,120,120));
return (HBRUSH)(m_pEditBkBrush->GetSafeHandle());
}
return hbr;
}
I change background of the list area , not the edit area of the combo ... I would like to change the color of edit area just like the statusbar color ... it could be soemthing like that ?
modified on Saturday, October 23, 2010 2:03 PM
|
|
|
|
|
Doesn't CTLCOLOR_EDIT work?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world.
Fry: But this is HDTV. It's got better resolution than the real world <
|
|
|
|
|
No , I try but didn't work ...
|
|
|
|
|
How about CTLCOLOR_STATIC?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world.
Fry: But this is HDTV. It's got better resolution than the real world <
|
|
|
|
|
It was go with CTLCOLOR_EDIT , but only when I type letters into combo control , when not the background color remain white ...
|
|
|
|
|
I just realized that you are hancling the control-color message in the combo box itself, not in its parent. Did you try with ON_WM_CTLCOLOR_REFELECT or ON_WM_CTLCOLOR?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world.
Fry: But this is HDTV. It's got better resolution than the real world <
|
|
|
|
|
You have to subclass the edit control of the combo box, since a combo box is a combined control. Here is an article[^] from Microsoft support describing how to do so.
|
|
|
|
|
I do what they said to , I put the change background code , but in vain ... still don't function ...
|
|
|
|
|
I've just tried it with an MFC dialog application. It's not perfect because the color change doesn't "stick" when the edit control has the focus but it comes back when you tab away from the combo box. You'd need to do some more work to make it work the way you want when the edit control has the focus, but this should give you a starting point.
The class that I derived from CComboBox is named CColorEditCombo . In the Visual Studio designer I added a CComboBox control to the dialog window. With the ClassWizard I added a CComboBox control variable named m_ctlComboColorEdit . Then in the header file for the dialog class I changed the declaration for this variable to the following:
CColorEditCombo m_ctlComboColorEdit;
This associates that control with the new CColorEditCombo class rather than the parent CComboBox class. In the class file for CColorEditCombo I added a handler for the WM_CTLCOLOR message as follows:
HBRUSH CColorEditCombo::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);
switch (nCtlColor)
{
case CTLCOLOR_EDIT:
case CTLCOLOR_MSGBOX:
if (m_edit.GetSafeHwnd() == NULL)
{
m_edit.SubclassWindow(pWnd->GetSafeHwnd());
}
pDC->SetBkColor(RGB(255, 255, 0));
m_brush.DeleteObject();
m_brush.CreateSolidBrush(RGB(255, 255, 0));
hbr = (HBRUSH) m_brush.GetSafeHandle();
return hbr;
case CTLCOLOR_LISTBOX:
if (m_listBox.GetSafeHwnd() == NULL)
{
m_listBox.SubclassWindow(pWnd->GetSafeHwnd());
}
}
return hbr;
}
Note the member variable named m_brush . This has to be declared in the header file for the CColorEditCombo class as a CBrush object. It should be deleted in the class destructor as well as just before the CreateSolidBrush statement shown above.
If you'd like, I can send you the solution for the very simple MFC dialog application I put together as a test to make sure this procedure works. You'll have to give me your email address and tell me which version of Visual Studio you are using.
modified on Wednesday, October 27, 2010 1:52 PM
|
|
|
|
|
I want to thank you for your solution , I will try it , and let you know if I did it ! I use VC6 .
|
|
|
|
|
Hi all,
I am having a CTreeView in Left Pane and in Right Pane i am Having a View.
My Requirement.
I can Open a Word Document,Node Pad,WordPad etc.
In the Tree i have Main Nodes as
1) Word Document
2) Note Pad
3) Word Pad. etc...
By Default this Main Nodes are been Populated.
When i Open any File i mean Word Document,NotePad and Word Pad in File Open Menu of my Application then I have to Add The Respective Name beneth this Nodes.
I.e) If i open Word Document from File Open Menu Then the Word Document Name must be Added in WordDocument Node.
If i open Node Pad from File Open Menu then the Node Pad must Then the Node Pad Name must be Added in Node Pad Node.
So which ever Category is been Opened then It should add The Name of Open File Name to Respective Node Only.
Please provide me a solution for this.
Thanks And Regards,
Uday.
|
|
|
|
|
So you are asking us to write you a program that meets your requirements?
If you are just asking for pointers, you should try asking a bit more specific questions, like "how do you add items to a treecontrol?" or "how do you know what type of file was opened?" or so, asking for a solution of such a "complex" task sounds like point 2 here[^].
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world.
Fry: But this is HDTV. It's got better resolution than the real world <
|
|
|
|
|
I need a solution which is very urgent.
Please donot feel in any other way.
As InsertItem(...) will Insert into Respective Node. But how to Find the specific Node is related to that Type. Pls provide me a solution if it is existing.
Regards,
Uday.
|
|
|
|
|
janaswamy uday wrote: Pls provide me a solution if it is existing.
nobody here is going to do your work for you.
|
|
|
|
|
janaswamy uday wrote: I need a solution which is very urgent.
Well I'm afraid it is not urgent to us.
janaswamy uday wrote: But how to Find the specific Node is related to that Type.
How can we offer a solution to this question when we do not know the structure of your Tree control? Take a look here[^] at the documentation for information on how to get to a specific child item of your control.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Hi,
Thank you very much. I got It. Thanks a Lot.
Regards,
Uday.
|
|
|
|
|
I have to cal this function to enable menu.. OnUpdateFileExit(?)--- what i have to pass in place of CCmdUI argument... confused
void BrowserManager::OnUpdateFileExit(CCmdUI *pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable ( TRUE );
}
|
|
|
|
|
The OnUpdateXXX handlers should be called auto-magically by the framework when the message ON_UPDATE_COMMAND_UI message is sent.
you need to add a message for that ...
add something like in the message map area of (I don't remember which one) either the application (CWinApp derived class) or the main frame class.:
ON_UPDATE_COMMAND_UI( ID_OF_YOUR_MENU_ITEM, OnUpdateFileExit)
IMO, the Exit menu (quit?) should always be enable.
Watched code never compiles.
|
|
|
|
|
What i want exactly i have a menu item disabled initially.. ? I have a function which check wheteher a Sotware present in System or not and retruns true/false... If it returns true i have to enable the menu item.. If it retuns false do nothing...
Can u explain me how to do this... 
|
|
|
|
|
The ON_UPDATE_COMMAND_UI is called for each menu item when the menu is displayed;
So, when that particular menu Item is displayed, the ON_UPDATE_COMMAND_UI handler is called.
In the function that you specified for the handler (usually called OnUpdateXXX where XXX is a descriptive name of the function based on the menu item) you will check to see if the software is present or not and enable disable the menu item accordingly.
for example (pseudo-coded):
ON_UPDATE_COMMAND_UI( IDM_YOUR_MENU_ITEM, OnUpdateYourMenuItem )
void YourClass::OnUpdateYourMenuItem( CCmdUI* pCmdUI )
{
pCmdUI->Enable( IsSoftwarePresentOnSystem() );
}
If the function IsSoftwarePresentOnSystem() takes a long time, then it would be a good thing to call it somewhere else and have a state variable.
Have fun.
M.
Watched code never compiles.
|
|
|
|
|
yes dude.. I did the same way u explained... but still the menu item remains disabled.. dont know where i went wrong... 
|
|
|
|
|
Can you debug your code ?
-If you put a breakpoint in the OnUpdateXXX method, is it triggered when the menu is displayed (when you open a menu) ?
-Does the function(s) that check you condition (if the software is there or not) works ? did you validate that before ?
M.
Watched code never compiles.
|
|
|
|
|
Hello buddies,
I'm working with openGL to draw line
Im using VC++ 2008 express
<br />
#include <glut.h><br />
#include <math.h><br />
<br />
GLfloat static x = 0.0;<br />
GLfloat static y = 0.0;<br />
<br />
<br />
typedef int BOOL;<br />
#define FALSE 0<br />
#define TRUE 1<br />
<br />
static BOOL button_down = FALSE;<br />
<br />
void draw_line(int x,int y) <br />
{<br />
<br />
glBegin(GL_LINE);<br />
glPointSize(3.5);
glColor3f(1.0,0.0,0.0);
glVertex2f(x,y);
glVertex2f(x,y);
<br />
glFlush();<br />
glEnd();<br />
}<br />
<br />
<br />
<br />
void mouse(int button,int state,int x,int y)<br />
{<br />
if<br />
<br />
( state == GLUT_DOWN) <br />
{<br />
button_down = TRUE;<br />
}<br />
<br />
<br />
if<br />
<br />
<br />
(state == GLUT_UP)<br />
{<br />
button_down = TURE;<br />
} <br />
}<br />
<br />
void init(void)<br />
{<br />
glClearColor(0.0, 1.0, 0.0, 1.0);
glMatrixMode(GL_PROJECTION); <br />
glLoadIdentity();<br />
<br />
}<br />
<br />
<br />
void motion(int x,int y)<br />
<br />
{ <br />
if(button_down)<br />
{<br />
<br />
<br />
<br />
}<br />
<br />
<br />
}<br />
void display(void)<br />
{<br />
glClear(GL_COLOR_BUFFER_BIT);
glFlush();<br />
glutSwapBuffers();<br />
}<br />
<br />
<br />
<br />
<br />
int main(int argc, char** argv)<br />
{<br />
glutInit(&argc,argv);<br />
glutInitWindowSize(ww,hh);
glEnable(GL_DEPTH);<br />
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);<br />
glutCreateWindow("draw_line");<br />
init();<br />
glutMotionFunc(motion);<br />
glutMouseFunc(mouse);
<br />
glutDisplayFunc(display);<br />
glutMainLoop();<br />
}
When the mouse press in location it would send the x and y values to draw the start point of the line then i have to release the button to point the end point of the line
So, What I suppose to change the value of x and y in motion function
|
|
|
|
|
Is it possible to change the startup location of a CFileDialog? I am working on a legacy application that makes use of multiple monitors, and I need to be able to position the location of the file load/save dialogs. I derived my own class based on CFileDialog and added what I thought was the appropriate SetWindowsPos call in the OnInitDialog method, but the things just will not move. If I change the windows size instead of the position, it correctly truncates the dialog, so I'm fairly sure I have the right window, yet no matter what values I pass in for the position, the location remains the same. Below is the important code from a test program.
BOOL CMyFileDialog::OnInitDialog()
{
CFileDialog::OnInitDialog();
CWnd *pW = GetParent();
RECT Rect;
pW->GetWindowRect(&Rect);
pW->SetWindowPos( NULL, 10, 10, Rect.right - Rect.left, Rect.bottom - Rect.top, 0);
return TRUE;
}
If it makes any difference this is using VS2005.
|
|
|
|
|
You can..
use CWnd::SetWindowPos[^] with the instance created for CMyFileDialog.
--
"Programming is an art that fights back!"
|
|
|
|