|
I hope following code snippet will help you. I've not included the details in depth. Just try it out.
class CMeiTengDlg: public CDialog
{
...
protected:
CBrush m_objMyBrush;
...
};
BOOL CMyDlg::OnInitDialog()
{
...
m_objMyBrush.CreateSolidBrush(RGB(255, 255, 255));
...
}
BOOL CMyDlg::DistroyWindow()
{
m_objMyBrush.DeleteObject();
}
HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
return m_objMyBrush;
}
void CMeiTengDlg::OnBnClickedChangebkcolor()
{
CColorDialog dlg;
if (dlg.DoModal() == IDOK)
COLORREF color=dlg.GetColor();
changbackground(color);
}
void CMeiTengDlg::changbackground(COLORREF color)
{
m_objMyBrush.DeleteObject();
m_objMyBrush.CreateSolidBrush( color );
Invalidate(TRUE);
}
|
|
|
|
|
thanks Malli
i want to confirm i just wanna change my CMeiTengDlg background color, what mentioned above is CMyDlg, CAboutDlg, so i no need to add one class, right? so i followed your idea, but after compiled, one error is
c:\documents and settings\zhiyuan li\desktop\meiteng\meiteng\meitengdlg.cpp(163) : error C4716: 'CMeiTengDlg::DistroyWindow' : must return a value<br />
Build log was saved at "file://c:\Documents and Settings\ZhiYuan Li\Desktop\MeiTeng\MeiTeng\Debug\BuildLog.htm"<br />
MeiTeng - 1 error(s), 0 warning(s)
by the way,could i get your email, and keep in touch. thanks.
|
|
|
|
|
Sorry Zhiyuan16,
I forgot to replace the CMyDls with your dialog class name. And you should return value from DestroyWindow function. I had deleted rest of the code (and put ....) considering you'd put the required one. For details have a look at here[^]
|
|
|
|
|
thanks Malli
comiling had no problem, but still no color change of background after i chose different color.
where is problem, Malli? thanks
|
|
|
|
|
dear Malli
could you help me to check is it right below: thanks a lot
BOOL CMeiTengDlg::OnDestroyWindow()<br />
{<br />
m_objMyBrush.DeleteObject();<br />
return TRUE;<br />
}<br />
<br />
<br />
HBRUSH CMeiTengDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)<br />
{<br />
<br />
return m_objMyBrush;<br />
}<br />
<br />
void CMeiTengDlg::SetBackgroundColor(COLORREF color)<br />
{<br />
m_objMyBrush.DeleteObject(); <br />
m_objMyBrush.CreateSolidBrush( color ); <br />
<br />
Invalidate(TRUE);<br />
}<br />
<br />
void CMeiTengDlg::OnBnClickedChangebkcolor()<br />
{<br />
CColorDialog dlg;<br />
if (dlg.DoModal() == IDOK) <br />
color=dlg.GetColor(); <br />
SetBackgroundColor(color);<br />
}<br />
|
|
|
|
|
The above code worked for me (only 'color' variable I found missing). Do you have any overlapping control on your dialog ? And I think you should call
return CDialog::DestroyWindow();
in your dialog's DistroyWindow();
|
|
|
|
|
no other control..
Malli
could you check for me the following my dialog .h and .cpp files thanks.
CMeiTengDlg.h file
#pragma once
#include "afxwin.h"
class CMeiTengDlg : public CDialog
{
public:
CMeiTengDlg(CWnd* pParent = NULL);
void SetBackgroundColor(COLORREF color);
enum { IDD = IDD_MEITENG_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX);
protected:
HICON m_hIcon;
CBrush m_objMyBrush;
COLORREF color;
virtual BOOL OnInitDialog();
virtual BOOL OnDistroyWindow();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
DECLARE_MESSAGE_MAP()
public:
CComboBox m_pComboBox;
afx_msg void OnBnClickedChangebkcolor();
};
CMeiTengDlg.cpp file
#include "stdafx.h"
#include "MeiTeng.h"
#include "MeiTengDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX);
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
CMeiTengDlg::CMeiTengDlg(CWnd* pParent )
: CDialog(CMeiTengDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMeiTengDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_BITMAP, m_pComboBox);
}
BEGIN_MESSAGE_MAP(CMeiTengDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_ChangeBKColor, &CMeiTengDlg::OnBnClickedChangebkcolor)
END_MESSAGE_MAP()
BOOL CMeiTengDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_objMyBrush.CreateSolidBrush(RGB(255, 255, 255));
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
return TRUE;
}
void CMeiTengDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
void CMeiTengDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this);
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
HCURSOR CMeiTengDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
BOOL CMeiTengDlg::OnDistroyWindow()
{
m_objMyBrush.DeleteObject();
return CDialog::DestroyWindow();
}
HBRUSH CMeiTengDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
return m_objMyBrush;
}
void CMeiTengDlg::SetBackgroundColor(COLORREF color)
{
m_objMyBrush.DeleteObject();
m_objMyBrush.CreateSolidBrush( color );
Invalidate(TRUE);
}
void CMeiTengDlg::OnBnClickedChangebkcolor()
{
CColorDialog dlg;
if (dlg.DoModal() == IDOK)
color=dlg.GetColor();
SetBackgroundColor(color);
}
|
|
|
|
|
ON_WM_CTLCOLOR() is missing in your message map. I hope you've added OnCtlColor handler manually.
|
|
|
|
|
thanks malli
now is ok. i have one more question here: in my dialog, i have several buttons, when i changed the background color, but dun chanaged the buttons' color, how can i can change the buttons' color after i choose different color. thanks
|
|
|
|
|
I think this[^] would help you.
|
|
|
|
|
thanks, malli
i have 3 radio buttons and one common button now, for 3 radio buttons, one is change background color, one is play music, last one is browse photoes, so when i check anyone radio button, and my that common button will show correspoding content what the radio button contains. thanks a lot.i searched online, but my pc and connection are slow, counldn't find. thanks.
|
|
|
|
|
Check this[^] one too.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Hi..
I'm supposed to get the information(when a event is trigered) from a application(service)running in a windows machine.. can some one please temme how to fetch it..
thanks in advance!!!
|
|
|
|
|
What exactly do you mean by "get the information" ? You looking for any "Data" communication between the processes or just an event notification ?
|
|
|
|
|
Thnks for the reply..
i ll tell u the exact scenario..
i have an application(i.e. an access control system).. im asked to use tcp/ip to collect the data(i.e.. address of the card reader, time and violation code) from the application when there is access violation... and after getting the instance of access violation, im supposed to pass the information to another application(written in c++) to take an action(record the event from a cctv where it is happening)..
|
|
|
|
|
I'm again confused ! Anyway, if you wanna to pass data across the process [i'm supposed to pass the information to another application(written in c++)] you can choose any of the Inter Process Communication mechanism[^]. And if you just wanna to sent an event notification (like a signaling kind of thing) you can use synchronization [^] object like Event.
|
|
|
|
|
What do you need exactly? user name? computer name? hardware profile? processes? folders? hardware?....
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Thankq Hamid!!!
i have an application(i.e. an access control system).. im asked to use tcp/ip socket communication to interface. have to collect the information(device address where access violation takes place ,alarm id) from the application when there is access violation... and after getting the instance of access violation, im supposed to pass the information to another application(written in c++) to take an action(record the event from a cctv where it is happening)..
|
|
|
|
|
is there any written way to communicate or you have to create mechanism for this. could you please clear it
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/xml>
|
|
|
|
|
For the receiving side there is a code , which accepts the information.. i have to simply pass the value from the access control system service to the to the code...
can i use client side programming to get the info from service ?
|
|
|
|
|
it there is any documented way to retrieve code from service or you have to device your own for it...
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
yea there is a documented way.. if i give a command like this to the service"" <username password="******/>" i.e.="" mode="hold">
when a event occurs, then it ll send a command in the above said format.. i have to send the data from those command to another application .
i used client socket programming to send n receive the message., is there any way to get the data
wsprintf(Buffer, ""<username password="******/">", loopcount++);
iretval = send(c_socket, zBuffer, sizeof(zBuffer), 0);
if (retval == SOCKET_ERROR)
{
fprintf(stderr," send() failed: error %d.\n", WSAGetLastError());
WSACleanup();
return -1;
}
else
printf("send() is OK.\n");
printf(" Sent data \"%s\"\n", zBuffer);
modified on Tuesday, December 30, 2008 7:25 AM
|
|
|
|
|
Hi I have an application which protects and unprotects .doc file. If I protect file first it works fine but when I am unprotecting it with following code it unprotects properly but again if I am trying to protect it it gives error (File not in format i.e not structure storage file). Please let me know is anything wrong with following code.
COleVariant vFilename(csFile);
VARIANT vOptional;
vOptional.vt = VT_ERROR;
vOptional.scode = DISP_E_PARAMNOTFOUND;
int iStat = FILE_NOT_EXIST ;
// Now ole object specific processing
switch (iType)
{
case WINWORD:
{
pFile -> Dispatch -> AddRef();
_Document Doc;
Doc.AttachDispatch(pFile -> Dispatch);
// The actual save
Doc.SaveAs( vFilename,
&vOptional, // Format
&Optional, // LockComments
&Optional, // Password
&vOptional, // AddToRecentFiles
&vOptional, // WritePassword
&vOptional, // ReadOnlyRecommended
&vOptional, // EmbedTrueTypeFonts
&vOptional, // SaveNativePictureFormat
&vOptional, // SaveFormsData
&vOptional); // SaveAsAOCELetter
}
break;
}
Do I need to add / set some more variant variable in order to protect it in second time.
Thanks
SNI
SNI
|
|
|
|
|
<br />
...<br />
&vOptional,
&Optional,
&Optional,
&vOptional,
...<br />
Do you have two different variables vOptional and Optional?
|
|
|
|
|
no that is copy paste mistake. it it vOptional at each place.
SNI
|
|
|
|