|
OK... You don't need to handle the any paint messages to change the color of a static text control. You just handle OnCtrlColor().
mfranco_neto wrote: I feel very lost right now...
Don't think like that... Now you know the method that do not lead to static text color handling... Next time you won't waste time in this way.
I am not sure about the results caused by calling BeginPaint inside OnPaint of another window. It is not desirable, because BeginPaint is for optimized painting.
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) <br />
{<br />
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);<br />
<br />
if (pWnd->GetDlgCtrlID() == IDC_MYSTATIC)<br />
{<br />
pDC->SetTextColor(RGB(255, 0, 0));<br />
pDC->SetBkMode(TRANSPARENT);<br />
hbr = GetStockObject( NULL_BRUSH );<br />
}<br />
<br />
return hbr;<br />
}
The above code may help you.
- NS -
|
|
|
|
|
Thanks a lot NS!!! I hope that it helps me!!
Although your answer is very complete, as I am just beginning to understand everything related to C++ and Windows, could you please extend your assistance to a few more questions?
NS17 wrote: HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
-> CMyDlg == "MyToolbar" class?
-> I assume it is called inside the message map of the toolbar (...HANDLER(WM_CTLCOLOR...,OnCtrlColor)). if so, where do I pass the parameters?
NS17 wrote: HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
-> CDialog... wasn't it CMyDlg?? -> I know this may seem a silly question and you may wonder what is a person who does not know the difference trying to build a toolbar??
NS17 wrote: return hbr;
-> Where does this brush return to, if the function is called from inside a message map (if it is the case)?
Thank you once again, for I have spent the last few week nights trying to understand everythng...
|
|
|
|
|
NS17 wrote: HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
Compiling...
MFToolbar.cpp
C:\Murphy\Temp\MFToolbar.cpp(150) : error C2653: 'CDialog' : is not a class or namespace name
C:\Murphy\Temp\MFToolbar.cpp(150) : error C2065: 'OnCtlColor' : undeclared identifier
????????????????????
|
|
|
|
|
I am sorry for the delay... I was not here for some days.
mfranco_neto wrote: C:\Murphy\Temp\MFToolbar.cpp(150) : error C2653: 'CDialog' : is not a class or namespace name
In your case the CDialog should be replaced with your class' base class.
As far as I know i will be CToolBarCtrl.
OK... You have to do the following steps...
In .h file add
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
between //{{AFX_MSG(CMyToolBar) and //}}AFX_MSG
like:
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
OK?
Now in .cpp add
ON_WM_CTLCOLOR()
between //{{AFX_MSG_MAP(CMyToolBar) and //}}AFX_MSG_MAP
like
ON_WM_CTLCOLOR()
OK?
Now place the code that I sent you before...
HBRUSH CMyToolBar::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CToolBarCtrl::OnCtlColor(pDC, pWnd, nCtlColor);
if (pWnd->GetDlgCtrlID() == IDC_MYSTATIC)
{
pDC->SetTextColor(RGB(255, 0, 0));
pDC->SetBkMode(TRANSPARENT);
hbr = GetStockObject( NULL_BRUSH );
}
Note: The CMyToolBar should be replaced with your class name. And your base class name should be placed in the place of CToolBarCtrl if it not the same.
IDC_MYSTATIC is the ID of your static text.
The return brush will be used for the painting the background of the static text control. Here we are returning NULL brush, so the background will be transparent. And the text color is changed to RGB(255,0,0) (RED).
Please know that this method is used in dialogs. And I did not tested this in such a toolbar (means a Toolbar for IE).
Any way GOOD LUCK...
- NS -
|
|
|
|
|
Hi NS,
Thank you for this "step-by-step tutorial"... . It's just amazing...
I started reading the book "Programming Windows API - 5th ed", by Petzold, to understand a little bit more about WinAPI, and stop asking very silly questions
I will try your solution and see what happens...
Once again, thank you very much. I know that it will help a lot other programmers which go through this FAQ.
|
|
|
|
|
I am not able to see my control list (by mistake i have press the del button) so that i can add control in my dialog box,What option should i use to display it again.
Thanks
|
|
|
|
|
am not sure what u mean.
Open any dialog in resources. Right click on any existing menu bar or tool bar in the msdev. a popup menu will appear. In it click controls.
nave
|
|
|
|
|
Does a function have to be a member of a class? Can it stand alone "classless?" If so, is it available to be used in any other class or function?
Likewise, does a data variable have to be a member of a class? If not, is it available to be used in any other class or function?
|
|
|
|
|
|
Hi, Oliver.
You can declare functions outside of your class just as you did in C, and they'll be globally available.
Additionally, there are times when you might want the function to be a member of your class, but you wish to avoid the implicit "this" param, such as when you're creating a callback function. In this case, you can declare the function static, and call it with explcit scope resolution, i.e. CMyClass::GlobalFunction(param1, param1).
The same applies to variables. You can declare them outside of a class (I typically use the g_ with the Hungarian to know that it's global, i.e. CString g_strText). You can also make them static members of your class, which for instance is the method employed in CFile for the open and create mode flages (CFile::modeRead, etc.).
Hope this helps.
|
|
|
|
|
When using CHttpConnection in my MFC program, is there a way to make the connection to Proxy server persistent instead of closing after every request? Or can I have to manually put the field into the header. For example I have:
------------------------- SAMPLE CODE ------------------------
CInternetSession session;
CHttpConnection* pConnection = NULL;
CHttpFile* pFile1 = NULL;
CString strHeaders = _T("Content-Type: image/jpeg\r\nProxy-Connection: Keep-Alive\r\nUser-Agent: MyProgram/1.0\r\n");
char buffer[BUFSIZZ];
UINT nBytesRead;
pConnection = session.GetHttpConnection("www.test.com", (INTERNET_PORT)80 );
for (i = 0; i < 30; i++) {
pFile1 = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET, "/", NULL, 1, NULL, NULL, INTERNET_FLAG_DONT_CACHE);
pFile1->SendRequest(strHeaders);
nBytesRead = 0;
nBytesRead = pFile1->Read(buffer, BUFSIZZ - 1);
buffer[nBytesRead] = '\0';
pFile1->Close();
delete pFile1;
}
------------------------------------------------------------------
However, when I run the code and do "netstat" I couldn't see any TCP connection with the proxy, even though the number of bytes read was non zero.
Btw, I noticed that the header produced using CHttpConnection/CHttpFile (captured using ethereal) says it's HTTP 1.0 instead of 1.1, will this create any problems with proxy server?
|
|
|
|
|
Using Windows 2000, Excel 2000, VC++ 6 sp 6,I'm having trouble with an Excel automation function (SetValue()) that throws an exception whenever I use the VT_UI2 type. Size of array doesn't matter. Always works fine for VT_R4.
CXLRange range;
VARIANT v;
VariantInit(&v);
LPDISPATCH pDisp = worksheet.Range(v1, v2);
range.AttachDispatch(pDisp);
SAFEARRAYBOUND rgsabound[2];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = nXLRows;
rgsabound[1].lLbound = 0;
rgsabound[1].cElements = nXLCols;
VARTYPE vType = pTable->GetVariantType(0);
SAFEARRAY FAR* psa = SafeArrayCreate(vType, 2, rgsabound);
if( psa )
{
V_VT(&v) = vType|VT_ARRAY;
V_ARRAY(&v) = psa;
LPSTR pData;
HRESULT hr = SafeArrayAccessData( psa, (void**)&pData );
if( SUCCEEDED(hr) )
{
VARIANT vData;
VariantInit(&vData);
int nSize = CFldPath::GetVariantSize(vType);
for( int nCol=0; nCol<nXLCols; nCol++ )
{
for( int nRow=0; nRow < nXLRows; nRow++ )
{
vData = pTable->GetElementValue( nCol, nRow );
if (2 == nSize)
memmove(pData, &vData.uiVal, nSize);
else
memmove( pData, &vData.lVal, nSize );
pData += nSize;
}
}
SafeArrayUnaccessData(psa);
range.SetValue(v);
VariantClear(&v);
}
}
}
Any help appreciated.
|
|
|
|
|
What exception is thrown? Where in the code?
Steve
|
|
|
|
|
Thanks for your reply.
It happens when SetValue() is called. The code jumps to the function
// invoke standard method given IDispatch parameters/return value, etc.
SCODE CCmdTarget::CallMemberFunc(const AFX_DISPMAP_ENTRY* pEntry, WORD wFlags,
VARIANT* pvarResult, DISPPARAMS* pDispParams, UINT* puArgErr)
in the MFC file oledisp1.cpp. There is a TRY on line 987. This would indicate that there's something wrong with the VARIANT v going into SetValue(v). However, I don't know what that would be. v.vt = 0x2012, which just indicates an array of VT_UI2. There's no problem when I use floating numbers and v.vt = 0x2004.
|
|
|
|
|
Hi All
Does anyone know how i can set the focus of another application from within my application ?
for example, from within my application if the user selected a certain option it would (providing it was open)
maximise say Ms Word and bring that to the forefront of the screen
I hope that makes sense
thanks
Simon
|
|
|
|
|
use
FindWindow();// get the handle to the word application
SetwindowPos() ;// bring the word aplication to the front
nave
|
|
|
|
|
You need to know application name and use FindWindow for get CWnd or HWND to window then you can set focus on it.
|
|
|
|
|
I'm trying to develop a class that takes a query and exports the result in a certain way.
I can use CRecordset::GetODBCFieldInfo() to find out what kind of data i have for a certain field and then format it like i need (mm.dd.yyyy for date fields for example) but how can i find if the curent field is null? Is there another way than casting it to a string and seeing if the value is ""?
I can't figure out how isFieldNull works..can anyone help?
|
|
|
|
|
|
I did that before posting the question...
|
|
|
|
|
I search a way to determine the memory which is on the graphic card installed.
Thanks for help.
|
|
|
|
|
Check out the Win32_VideoController class.
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
See here[^] maybe it is some helpful to you
|
|
|
|
|
I think the Alt-Tab window only shows the stuff on the taskbar. Windows only appear on the taskbar if they have the WS_EX_APPWINDOW extended style set. So that might be the place to start.
|
|
|
|
|
Hey guys, I was wondering when we use these parameters (int argc, char *argv[]) in a main function? I have no clue why they use it....
Thanks in advance
void main (int argc, char *argv[]) {<br />
<br />
..........<br />
.........<br />
<br />
}
|
|
|
|
|