|
Good night friends. Sorry if I sound a bit rushed, but that is for me (especially) is very important to know does. And since someone there on the other side has the answer to my doubts, Please me of this force, since I am also not starting there, and yes seeing the two modes in parallel. Already Thank you and God Bless ...
|
|
|
|
|
Hi all,
I have spend already many hours to find the reason of my current problem.
I have a CDockablePane, in which I am placing a lot of CStatic controls. The CStatic controls I am using to display bitmaps. A dockable pane is designed for resizing at any time. Therefore I try to recalculate the positions of each CStatic after OnSize is called.
With some CStatic controls it is running well. But when I am adding an additional control, I am getting strange problems: The pane is not repainted properly and OnPaint is recalled cyclically.
My code (partially):
Header:
class CPaneCtrlPLC : public CDockablePane
{
DECLARE_DYNAMIC(CPaneCtrlPLC)
public:
CPaneCtrlPLC();
virtual ~CPaneCtrlPLC();
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSize(UINT nType, int cx, int cy);
private:
CStatic m_Ctrl_PLCLED[6];
CStatic m_SwitchCtrl;
CStatic m_Ctrl_test;
C-File:
int CPaneCtrlPLC::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDockablePane::OnCreate(lpCreateStruct) == -1)
return -1;
m_ColorSieGreen = RGB(0, 153, 153);
m_ColorSieWhite = RGB(251, 253, 253);
m_ColorText = RGB(230, 228, 193);
m_ColorBgnd = RGB(119, 117, 127);
m_BrushSieGreen.CreateSolidBrush(m_ColorSieGreen);
m_BrushBgnd.CreateSolidBrush(m_ColorBgnd);
m_BitmapSWITCHSTOP.LoadBitmapW(IDB_SWITCH_STOP);
m_bitmapLEDOFF.LoadBitmapW(IDB_LEDOFF);
m_bitmapLEDRED.LoadBitmapW(IDB_LEDRED);
m_bitmapLEDGREEN.LoadBitmapW(IDB_LEDGREEN);
m_bitmapTest.LoadBitmapW(IDB_LEDGREEN);
DWORD dwStyle = WS_CHILD | WS_VISIBLE | TVS_SHOWSELALWAYS | SS_BITMAP;
m_SwitchCtrl.Create(NULL, dwStyle, CRect(0, 0,0,0),this);
m_SwitchCtrl.SetBitmap(m_BitmapSWITCHSTOP);
int iLed;
for (iLed = 0; iLed < MaxNumPLCLeds; ++iLed)
{
DWORD dwStyle = WS_CHILD | WS_VISIBLE | TVS_SHOWSELALWAYS | SS_BITMAP;
m_Ctrl_PLCLED[iLed].Create(NULL, dwStyle, CRect(xPosPLCLEDS,(yPosPLCLEDS + (26* iLed)), 0, 0), this);
m_Ctrl_PLCLED[iLed].SetBitmap(m_bitmapLEDOFF);
}
{
DWORD dwStyle = WS_CHILD | WS_VISIBLE | TVS_SHOWSELALWAYS | SS_BITMAP;
m_Ctrl_test.Create(NULL, dwStyle, CRect(xPosPLCLEDS + (17 * iLed), yPosPAELEDS + 20, 0, 0), this);
m_Ctrl_test.SetBitmap(m_bitmapTest);
}
...
I was able to strip the OnPaint(0) function to a minumum to reprocude the problem.
If I comment out the re-positioning of the m_Ctrl_test, everything works fine, but with this statement I have the problems.
void CPaneCtrlPLC::OnPaint()
{
LOGMSG(LOG_TEST, _T("Repaint"));
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
dc.FillRect(&rect, &m_BrushBgnd);
m_SwitchCtrl.SetWindowPos(NULL, 10,10, 0, 0,
SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOCOPYBITS);
m_Ctrl_test.SetWindowPos(NULL, 10, 100, 0, 0,
SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOCOPYBITS);
return;
}
Any ideas, what could be wrong?
|
|
|
|
|
Solved by myself!
In OnPaint() I changed the positions of the CStaticControls.
Of course this is causing "recursive" WM_PAINT calls.
I moved this code to other functions (OnSize, OnTimer,...), now it works!
|
|
|
|
|
I have a CListCtrl in my MFC dialog application.
I enabled the HDS_FILTERBAR for List control the by the following code.
CHeaderCtrl* pHeaderCtrl = m_myListCtrl.GetHeaderCtrl();
pHeaderCtrl->SetDlgCtrlID( IDC_LIST1 );
HDITEM hdItem;
ZeroMemory( &hdItem, sizeof( HDITEM ));
hdItem.mask = ( HDI_FILTER );
pHeaderCtrl->ModifyStyle( 0, HDS_FILTERBAR );
hdItem.type = HDFT_ISSTRING;
The filter is displayed.
However I would like to change the background color and font of the Edit control and button in the filter section.
How can I achieve it.
aks
|
|
|
|
|
The CEdit class inherits from CWnd so you can use SetFont to change the font. You can probably set the background colour by subclassing the window. Changing the colour and image in a button can be done in similar ways. Google should find you some samples.
|
|
|
|
|
Thank you for the comment.
I tried by subclassing the Header control.
But I could not find any options to get the edit control and button from the CHeaderCtrl.
aks
|
|
|
|
|
aks. wrote: I could not find any options to get the edit control and button So who put them in the header in the first place?
|
|
|
|
|
Ok. I got it, I used FindWindoEx to find the WC_EDIT in the header.
I think the filter button is not exactly a button. Its a bitmap.
aks
|
|
|
|
|
I don't think that is the best way. You put the items in the header so you should be able to get their handles quite easily using the methods of the CHeaderCtl object.
|
|
|
|
|
I could only find it by using FindWondow API in class derived from CHeaderCtrl.
Ans I customized the edit control from OnCustomDraw().
aks
|
|
|
|
|
I have a dialog of radio buttons, 100 of them
I use this to select type of material product is made from so I can select correct ink for printing. Selections are everything from alumininum, plastics to wood.
I would like to select 1 radio button and have it return
the int of that selection without having to add an event handler for each and everyone of the radio buttons
Is there a routine that can handle any check on any button?
If(any button is checked) return(int # of the button)
Using visual studio c++ 2008
Peter Boyko
modified 8-Sep-15 10:23am.
|
|
|
|
|
You can hook up the same event for each button. The sender can be identified by the sender parameter of the event. It contains a reference to the button, and thus, its name.
--sorry, thought this was the C# forum. Doesn't MFC have something similar?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
if it does, I'm not able to find it. Could be I'm looking at the wrong pages.
Peter Boyko
|
|
|
|
|
golfbird wrote: I have a dialog of radio buttons, 100 of them That is a really bad idea. Use a ListBox, or preferably more than 1 to allow simple selection of items.
|
|
|
|
|
thanks
you have busted my bubble.
To me, it seemed easier to look at a dialog page
with radio buttons rather than search a listing
especially for my printers who may not have to learn how
to use drop down list boxes
Seems to me that the program knows when a radio button
is selected and then marks is as such and turns off all others in the group..
I was hoping I could intercept the routine and just
add my own function to it.
Peter Boyko
|
|
|
|
|
golfbird wrote: I was hoping I could intercept the routine and justadd my own function to
it. You can, see Davids reply. You'll need an ON_BN_CLICKED() entry for every radio button, but the function that gets called can be the same. Though for a 100 buttons I imagine it gets unwieldy.
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
ON_BN_CLICKED(IDC_RADIO_1, OnRadioClick)
ON_BN_CLICKED(IDC_RADIO_2, OnRadioClick)
ON_BN_CLICKED(IDC_RADIO_3, OnRadioClick)
END_MESSAGE_MAP()
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
This looks like what I was looking for.
Appreciate it, will give it a test
thank you
Peter Boyko
|
|
|
|
|
|
golfbird wrote: I have a dialog of radio buttons, 100 of them Very unfriendly UI.
The second parameter to the ON_BN_CLICKED() macro can point to the same handler function.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Thanks.. I have to believe the objective I'm trying to reach
is beyond me. Thank You all again.
Peter Boyko
|
|
|
|
|
Which are the way to copy a CBitmap to another CBitmap, but have both of them ? In fact, I want to create a CBitmap from another CBitmap ... could you help me ? Thank you.
|
|
|
|
|
|
Thank you, I have succeeded ! 
|
|
|
|
|
I have 3 functions that do sorting on a CArray.
CArrays are declared in header file:
CArray<int*, int*>m_Integer;
CArray<string*, string*>m_String;
CArray<double*, double*>m_Double;
void sortIntegers()
{
// Do sorting for m_Integer here
}
void sortStrings()
{
// DO sorting for m_String
}
void sortDouble()
{
// Do sorting for m_Double
}
Now what i want to do is, have one generic function and then pass the CArray to that.
So far what i did is,
in Header file:
void sortAll(CArray<void*, void*> m_Array);
in CPP file:
void sortAll(CArray<void*, void*> m_Array)
{
int size = m_Array.GetSize();
............
............
............
m_Array.GetAt(0); // Error here
................
................
}
The error is that, it needs a class type and not a void type.
I am not sure how to proceed with writing a generic function to handle all different data types in one.
Any help is welcome!
|
|
|
|
|