|
Below is the essential code of the dialog and the checkbox class. Hope it helps. Thanks a lot for your assistance so far.
maladuk
dialog class header:
class ShowResultDlg : public CDialog{
//{{AFX_DATA(ShowResultDlg)
CColorCheck m_chk_tmax;
//}}AFX_DATA
protected:
//{{AFX_MSG(ShowResultDlg)
afx_msg void OnChkTmax();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
dialog class source:
void ShowResultDlg::DoDataExchange(CDataExchange* pDX){
//{{AFX_DATA_MAP(ShowResultDlg)
DDX_Control(pDX, IDC_CHK_TMAX,m_chk_tmax);
//}}AFX_DATA_MAP
}
void ShowResultDlg::OnChkTmax(){
if(m_chk.GetCheck()) m_chk_tmax.SetCheck(FALSE);
else m_chk_tmax.SetCheck(TRUE);
}
BOOL ShowResultDlg::OnInitDialog() {
CDialog::OnInitDialog();
m_chk_tmax.SetArrowColor(RGB(255,0,0);
return TRUE; // return TRUE unless you set the focus to a control
}
void ShowResultDlg::OnPaint(){
CPaintDC dc(this); // device context for painting
}
ColorCheckBox class header
(from: www.codeguru.com/Cpp/controls/controls/checkboxcontrols/article.php/c5319/)
class CColorCheck : public CButton{
DECLARE_DYNAMIC(CColorCheck)
int rightstatus;
public:
CColorCheck();
virtual ~CColorCheck(){;}
virtual void SetCheck(int nCheck);
virtual int GetCheck();
COLORREF SetArrowColor(COLORREF newColor);
int RightStatus() {return rightstatus;}
void RightStatus(int status) {rightstatus=status;}
public:
BOOL checkFlag,drawFocus;
UINT oldAction,oldState;
COLORREF newColor, newArrowColor, newTextColor;
protected:
void DrawCheckCaption(CDC *pDC, CRect R, const char *Buf, COLORREF TextColor);
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItem);//overrides WM_DRAWITEM !!!
COLORREF GetDisabledColor() { return disabled; }
//{{AFX_MSG(CColorCheck)
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
//}}AFX_MSG
private:
DECLARE_MESSAGE_MAP()
};
ColorCheckBox class source:
IMPLEMENT_DYNAMIC(CColorCheck, CButton)
CColorCheck::CColorCheck(){
....
rightstatus = 0;
}
BEGIN_MESSAGE_MAP(CColorCheck, CButton)
//{{AFX_MSG_MAP(CColorCheck)
ON_WM_RBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CColorCheck::OnRButtonDown(UINT nFlags, CPoint point) {
if(rightstatus) rightstatus = 0;
else rightstatus = 1;
SetArrowColor(RGB((1-rightstatus)*255,0,rightstatus*255)); //red if leftclicked, blue if rightclicked
}
void CColorCheck::SetCheck(int nCheck){
if (nCheck == 1) checkFlag = 1;
else checkFlag = 0;
}
BOOL CColorCheck::GetCheck(){
if (checkFlag == 1) return 1;
else return 0;
}
COLORREF CColorCheck::SetArrowColor(COLORREF arrowColor){
newArrowColor = arrowColor;
return newArrowColor;
}
void CColorCheck::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct){
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
CRect rc;
CRect rect(13,1,11,11);
CRect focusRect, btnRect;
focusRect.CopyRect(&lpDrawItemStruct->rcItem);
disabled = RGB(100,100,100); // dark gray disabled text
CSize captionSize;
// Retrieve the button's caption
//
const int bufSize = 512;
TCHAR buffer[bufSize];
GetWindowText(buffer, bufSize);
//
// Set the Text Position more to the left
//
captionSize = pDC->GetTextExtent(buffer, strlen(buffer));
btnRect.SetRect(16,1,16 + captionSize.cx + 4,15);
//
// Set the focus rectangle to just past the border decoration
//
focusRect.SetRect(18,1,16 + captionSize.cx +8, 15);
//Get control's ID
int id = GetDlgCtrlID();
UINT state = lpDrawItemStruct->itemState;
UINT action = lpDrawItemStruct->itemAction;
// Don't redraw whole control if only focus has changed
if (action == ODA_FOCUS)
drawFocus = TRUE;
if (!drawFocus)
{
//Start drawing the check box
CPen normRect(PS_SOLID, 1,NULL_PEN);
CPen* m_normRect = pDC->SelectObject(&normRect);
pDC->SelectStockObject(NULL_BRUSH);
//draw the caption
pDC->DrawText(buffer, strlen(buffer), btnRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
DrawCheckCaption(pDC, btnRect, buffer, newTextColor);
//draw the check rectangle
pDC->FillSolidRect(2,2,11,11,newColor);
normRect.DeleteObject();
//draw the borders
CPen normRect1(PS_SOLID, 1,RGB(80,80,80));
CPen* m_normRect1 = pDC->SelectObject(&normRect1);
CPoint startPt = pDC->MoveTo(1,13);
pDC->LineTo(1,1);
pDC->LineTo(13,1);
normRect1.DeleteObject(); //release
CPen normRect2(PS_SOLID, 1,RGB(100,100,100));
CPen* m_normRect2 = pDC->SelectObject(&normRect2);
CPoint startPt1 = pDC->MoveTo(0,14);
pDC->LineTo(0,0);
pDC->LineTo(14,0);
normRect2.DeleteObject(); //release
CPen normRect3(PS_SOLID, 1,RGB(255,255,255));
CPen* m_normRect3 = pDC->SelectObject(&normRect3);
CPoint startPt2 = pDC->MoveTo(14,0);
pDC->LineTo(14,14);
pDC->LineTo(0,14);
normRect3.DeleteObject(); //release
CPen normRect4(PS_SOLID, 1,RGB(180,180,180));
CPen* m_normRect4 = pDC->SelectObject(&normRect4);
CPoint startPt3 = pDC->MoveTo(13,1);
pDC->LineTo(13,13);
pDC->LineTo(13,1);
normRect4.DeleteObject(); //release
if (checkFlag == 1)
{
pDC->FillSolidRect(2,2,11,11,newColor);
// draw the arrow
CPen normRect5(PS_SOLID, 1, newArrowColor);//BLACK_PEN);
CPen* m_normRect5 = pDC->SelectObject(&normRect5);
CPoint startPt2 = pDC->MoveTo(4,7);
pDC->LineTo(7,11);
pDC->LineTo(10,3);
CPoint startPt3 = pDC->MoveTo(4,8);
pDC->LineTo(7,9);
pDC->LineTo(9,4);
normRect5.DeleteObject(); //release
}
}
//draw "checked" - arrow depending on state
if (action & ODA_SELECT && checkFlag == 1)
pDC->FillSolidRect(2,2,11,11,newColor);
else if (action & ODA_SELECT && checkFlag == 0)
{
pDC->FillSolidRect(2,2,11,11,newColor);
// draw the arrow
CPen normRect5(PS_SOLID, 1, newArrowColor);//BLACK_PEN);
CPen* m_normRect5 = pDC->SelectObject(&normRect5);
CPoint startPt2 = pDC->MoveTo(4,7);
pDC->LineTo(7,11);
pDC->LineTo(10,3);
CPoint startPt3 = pDC->MoveTo(4,8);
pDC->LineTo(7,9);
pDC->LineTo(9,4);
normRect5.DeleteObject(); //release
}
if( ( state & ODS_FOCUS ) ^ ( oldState & ODS_FOCUS ) ||( !drawFocus && ( state & ODS_FOCUS ) ) )
DrawFocusRect(lpDrawItemStruct->hDC, (LPRECT)&focusRect);
else if (state & ODS_DISABLED)
{
pDC->FillSolidRect(2,2,11,12,RGB(192,192,192)); //grayed
DrawCheckCaption(pDC, btnRect, buffer, GetDisabledColor());
}
oldState = state;
oldAction = action;
}
void CColorCheck::DrawCheckCaption(CDC *pDC, CRect R, const char *Buf, COLORREF TextColor)
{
COLORREF prevColor = pDC->SetTextColor(TextColor);
pDC->SetBkMode(TRANSPARENT);
pDC->DrawText(Buf, strlen(Buf), R, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
pDC->SetTextColor(prevColor);
}
maladuk
|
|
|
|
|
maladuk wrote: void ShowResultDlg::OnPaint(){
CPaintDC dc(this); // device context for painting
}
Are you some operations in this function ?
|
|
|
|
|
No, I have not. What should go in there?
Thanks!
maladuk
|
|
|
|
|
Implemenation of DrawItem seems to be problem there.
|
|
|
|
|
OK. I will start looking into it. If you think of something particular, please let me know.
Thanks a lot !
maladuk
|
|
|
|
|
Here it is, It was logical error, For time being I've removed a if case to modify code.
void CColorCheck::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
CRect rc;
CRect rect(13,1,11,11);
CRect focusRect, btnRect;
focusRect.CopyRect(&lpDrawItemStruct->rcItem);
disabled = RGB(100,100,100);
CSize captionSize;
const int bufSize = 512;
TCHAR buffer[bufSize];
GetWindowText(buffer, bufSize);
captionSize = pDC->GetTextExtent(buffer, strlen(buffer));
btnRect.SetRect(16,1,16 + captionSize.cx + 9,15);
focusRect.SetRect(18,0,16 + captionSize.cx +6, 15);
int id = GetDlgCtrlID();
UINT state = lpDrawItemStruct->itemState;
UINT action = lpDrawItemStruct->itemAction;
if (action == ODA_FOCUS)
drawFocus = TRUE;
CPen normRect(PS_SOLID, 1,NULL_PEN);
CPen* m_normRect = pDC->SelectObject(&normRect);
pDC->SelectStockObject(NULL_BRUSH);
pDC->DrawText(buffer, strlen(buffer), btnRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
DrawCheckCaption(pDC, btnRect, buffer, newTextColor);
pDC->FillSolidRect(2,2,11,11,newColor);
normRect.DeleteObject();
CPen normRect1(PS_SOLID, 1,RGB(80,80,80));
CPen* m_normRect1 = pDC->SelectObject(&normRect1);
CPoint startPt = pDC->MoveTo(1,13);
pDC->LineTo(1,1);
pDC->LineTo(13,1);
normRect1.DeleteObject();
CPen normRect2(PS_SOLID, 1,RGB(100,100,100));
CPen* m_normRect2 = pDC->SelectObject(&normRect2);
CPoint startPt1 = pDC->MoveTo(0,14);
pDC->LineTo(0,0);
pDC->LineTo(14,0);
normRect2.DeleteObject();
CPen normRect3(PS_SOLID, 1,RGB(255,255,255));
CPen* m_normRect3 = pDC->SelectObject(&normRect3);
CPoint startPt2 = pDC->MoveTo(14,0);
pDC->LineTo(14,14);
pDC->LineTo(0,14);
normRect3.DeleteObject();
CPen normRect4(PS_SOLID, 1,RGB(180,180,180));
CPen* m_normRect4 = pDC->SelectObject(&normRect4);
CPoint startPt3 = pDC->MoveTo(13,1);
pDC->LineTo(13,13);
pDC->LineTo(13,1);
normRect4.DeleteObject();
if (checkFlag == 1)
{
pDC->FillSolidRect(2,2,11,11,newColor);
CPen normRect5(PS_SOLID, 1, newArrowColor);
CPen* m_normRect5 = pDC->SelectObject(&normRect5);
CPoint startPt2 = pDC->MoveTo(4,7);
pDC->LineTo(7,11);
pDC->LineTo(10,3);
CPoint startPt3 = pDC->MoveTo(4,8);
pDC->LineTo(7,9);
pDC->LineTo(9,4);
normRect5.DeleteObject();
}
if (action & ODA_SELECT && checkFlag == 1)
pDC->FillSolidRect(2,2,11,11,newColor);
else if (action & ODA_SELECT && checkFlag == 0)
{
pDC->FillSolidRect(2,2,11,11,newColor);
CPen normRect5(PS_SOLID, 1, newArrowColor);
CPen* m_normRect5 = pDC->SelectObject(&normRect5);
CPoint startPt2 = pDC->MoveTo(4,7);
pDC->LineTo(7,11);
pDC->LineTo(10,3);
CPoint startPt3 = pDC->MoveTo(4,8);
pDC->LineTo(7,9);
pDC->LineTo(9,4);
normRect5.DeleteObject();
}
if( ( state & ODS_FOCUS ) ^ ( oldState & ODS_FOCUS ) ||( !drawFocus && ( state & ODS_FOCUS ) ) )
DrawFocusRect(lpDrawItemStruct->hDC, (LPRECT)&focusRect);
else if (state & ODS_DISABLED)
{
pDC->FillSolidRect(2,2,11,12,RGB(192,192,192));
DrawCheckCaption(pDC, btnRect, buffer, GetDisabledColor());
}
oldState = state;
oldAction = action;
}
|
|
|
|
|
Fantastic!
It works!
Thanks a lot.
malduk
|
|
|
|
|
You certainly deserve a 5. I am sorry I did'nt give it right away.
maladuk
|
|
|
|
|
Do you have any paint on your dialog?
|
|
|
|
|
Theres a OnPaint function in the dialog class (see code in answer above). But putting calls like m_chekbox.RedrawWindow(),
m_chekbox.UpdateWindow(),
m_chekbox.Invalidate()
etc. does not solve the problem.
maladuk
|
|
|
|
|
Hello everyone,
I was just wondering if it is possible to build a Window Application which can monitor a Third-Party software's activities?
What I mean by that is to be able to know which Button is clicked in a certain 3rd-party application. Let's say you have your "MS words" open and you are working on a document. Once you click on buttons like, Bolld, Italic, Save As, Save, Print etc..., your window application can tell you specificly what action was requested?
These are Learing question and please feel free to share with me your suggestions.
Thank you very much for your time.
Khoramdin
|
|
|
|
|
Yes - look into Windows Hooks. Specifically, I think a CBT hook can help you with things like this.
Trivia: MFC (in VC++ 6.0 at least) uses CBT hooks internally for certain functionality.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
If you've got visual studio installed, try launching Spy++ (in VS's tools menu) - that'll show you all the windows messages an application is receiving, which can tell you which buttons, menus, etc are being clicked
|
|
|
|
|
I am writing a program where I want a sound file to play while I update the main window. I have everything implemented with the sndPlaySound() function, but when the program runs, it becomes unresponsive as long as the sound clip is running. That is, if the user tries to move the window, the whole thing goes white until the function that is updating the window is finished as well as the sound has stopped playing.
I implemented a second thread to try to do nothing but call the sndPlaySound function, but that did not work either. It played the sound, but the window still goes unresponsive if anything interrupts in my functions.
Does anyone have ideas on how to do this properly?
I have searched through the multi-threaded posts, but haven't found anything so far.
Please help, if possible. Or point me in another direction on how to implement this properly.
Thanks.
|
|
|
|
|
You can use the SND_ASYNC flag... Look up the documentation for the PlaySound(...) function.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
I am already using the SND_ASYNC flag on sndPlaySound function.
It seems that the drawing of the window doesn't happen once the user clicks anything in the window.
|
|
|
|
|
Are you using any other flags? You might not be combining them correctly. I have used the SND_ASYNC flag lots of time and never had it stall anything like you are describing.
You do not have any code that is waiting for the sound to finish, do you?
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
No, I am not using any other flags in the sndPlaySound function. That seems to be working. What i am having a problem with (now that I look at it further), is in my ability to update the window as I need to. I am using a simple 'wait until X amount of time has passed', then I update some values, call Invalidate(); followed by a UpdateWindow().
This all works unless, in the middle of my function where I am drawing the window, the user clicks my window. Then, it doesn't update until the very end of the function and I am not sure why.
I originally thought that maybe having the sound play on another thread would help, but it isn't.
|
|
|
|
|
If your "wait until X amount of time has passed" implementation is a blocking one, like calling Sleep(...) or going into a spin, you will not be able to pump any messages, so you will not get the Paint message to update the screen.
For example, if you are trying to do some cheap animation using old-school-style techniques in a loop, it will not work the same under Windows.
If you are doing the above, you can change your wait to use a Timer message, and then when the timer message fires, you can do your updates.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Thank you for the help. Can you point me in the direction of Timer message info? I have never heard of this before.
Thanks again.
Josh
|
|
|
|
|
Look up the WM_TIMER message and the SetTimer(...) function. If you need high-accuracy timers, look up multimedia timers.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
That was it, thank you. I appreciate the help.
|
|
|
|
|
How can i access the exact hardware configuration details using Registry in VC++?Can u please give me with a piece of code?
|
|
|
|
|
V.Natarajan wrote: How can i access the exact hardware configuration details...
Of what?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
For all Hardware devices namely USB ports,D-I/O Ports & COM Ports respectively,which are currently connected to the system.Please explain with code using VC++.
|
|
|
|
|