|
...I could however close the socket and open it again, but what are the drawbacks of this? this means that i need to close and open like 20 sockets per second in the future...
hehe, anyways your saying that your server wont suffer to hard when creating AND DESTROYING lets say 2 sockets per second?
|
|
|
|
|
No. As long as that's really what your app needs to do.
Think about how many TCP sockets a busy web (HTTP) server must open and close per second.
20 per second is nothing
Mark
|
|
|
|
|
ok now i know enough. thanks for everything mark, you've helped me alot
|
|
|
|
|
*EDIT* Having a pool of sockets could improve performance - that way only ConnectEx/DisconnectEx
needs to be called on a socket instead of recreating/destoying the entire socket every time.
Mark
|
|
|
|
|
src=msdn:The Windows Sockets ConnectEx function establishes a connection to a specified socket, and optionally sends data (called connect data) once the connection is established. The ConnectEx function is only supported on connection-oriented sockets.
remember, i'm forced to use connectionless protocols thanks anyway
|
|
|
|
|
Gotcha man I was just extending my comment about TCP sockets on an HTTP server
|
|
|
|
|
Hi!
In a dialog I have a number of customized check boxes, displaying a red check when leftclicked and a blue check when rightclicked. The red and blue determines if an associated variable shall be associated to the left or right axis in a chart. This works fine except that if the dialog is covered by a window and then redisplayed, the checkboxes that have been clicked disapper.
I have tried all the obvious calls, Invalidate(), RedrawWindow(), UpdateWindow(), Show(), OnPaint() etc. to redisplay the dialog, but the checkboxes wont reappear.
Can anybody give me a hint on how should I do this?
Thanks!
maladuk
|
|
|
|
|
If you are doing much of the drawing of the controls yourself, you need to make sure that areas that have been marked as invalidated are also marked as validated (see functions like ValidateRect(...) ) when drawing is done, otherwise Windows may not think that you have drawn an invalidated area yet.
Usually, not having a validated area causes excessive paint messages, but I have seen strange things happen...
Incorrect handling of the WM_ERASEBKGND message can also cause similar things to happen.
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
|
|
|
|
|
Hi! Thanks for trying to help. Your answer is however a bit too general for me to be sure I am checking out exactly what you mean. I have tried to put calls like
m_checkbox.Invalidate()
m_checkbox.ValidateRectangle()
m_checkbox.RedrawWindow()
....
in the OnPaint() message handler function of the dialog class. It did'nt help a bit. I also tried to put a OnPaint() message handler function in the chekcbox class itself. Then none of the checkboxes were shown even at dialog creation. I have posted the relevant code for the dialog and the checkbox classes in an answer below. One of the suggestions so far is that the error is in the CheckBox's class DrawItem() function. If you have any suggestions it will be highly appreciated.
thanks
maladuk
|
|
|
|
|
Where are you drawing the check boxes. It seems like you are probably doing the drawing in the WM_LBUTTONDOWN and WM_RBUTTONDOWN message handler functions. You should be drawing the checkboxes in the WM_PAINT message handler.
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
Thanks for trying to help! They are drawn in the InitDialog() of the parent dialog and then in the WM_LBUTTONDOWN message handler function of the CheckBox-class itself. The WM_RBUTTONDOWN message handler function is just used to toggles between red and blue color (see code in my answer further down).
Can you say more specifically how you mean I should draw the Checkboxes in the WM_PAINT message handler function. If I put such a function in the CheckBox-class itself, the boxes are not shown at all. Should I draw them from OnPaint() in dialog class ? (as you understand I am not an expert in this)
Thanks!
maladuk
|
|
|
|
|
As said earlier, invalidation may be problem. Can you post some code, what you are trying ?
|
|
|
|
|
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
|
|
|
|
|