|
how to bind a edit control in a ADO to a combo box control ?
which class in MFC will help,
|
|
|
|
|
What do you mean by binding an edit control to a combobox control?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
it means a current Record set called as a ADO Data bound dialog , where i have all static and edit boxs as default ,i need to place a new combobox to call the data of a field from second record set of database
|
|
|
|
|
So are you wanting to populate a combobox with the results of a recordset query?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Yes,i want to place a combobox on a ADO data dialog with a result of a recordset query to get only a selected field from the table in this combobox as a dropdown, Please help me this
|
|
|
|
|
Asha Rams wrote:
...a ADO data dialog...
I've never heard of one of these. What is it?
In any case, perhaps this article will help.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I am having problems trying to capture the HDN_ITEMDBLCLICK message of a HeaderCtrl of a ListCtrl. MSDN docs refer to seting HDS_BUTTONS style for the HeaderCtrl. I have tried doing this during the ListCtrl:OnCreate procedure. It appears to be changing the style and when you left click on a header column, it depresses like a button control would.
Any help would be appreciated.
Thank you.
|
|
|
|
|
Hi,
I have been using a wrapper class around IXMLDOMDocument to save to an XML file. (Available here on CP)
How can i save the type of encoding in that XML file?
Best regards,
Jens
|
|
|
|
|
I am using a list control, where i am displaying around 5 columns and 25 rows. I want to update only the 2nd and 3rd column items values for every second. This is working by updating it in OnTimer function. To reflect the changes Invalidate(TRUE) is used. But the problem is, the control is FLICKERING every second when it is updated.
Is there any way to update/refresh the control without flickering?
Please let me know ASAP.
vidya
|
|
|
|
|
InvalidateRect() can be used to identify the area of the window/control that requires repainting. The entire window is always repainted. BUT, using InvalidateRect allows you to specify which parts of the window are erased before repaint. The flickering is caused by the erasing/repainting method. If the unchanged areas of the window/control are not erased before a repaint, they will not flicker, but will remain the same.
A plain english example: Take a paper and a pen. Draw a line on the paper. Now, if you used Invalidate , you'd first erase the line, then draw it again. If you used InvalidateRect and specified an empty section of the paper, you'd draw the same line again over the previous one without erasing it first, thus avoiding the flicker effect.
This is a valid approach as long as the other columns do not change. If they do, the entire window must be erased before repainting, otherwise it will paint over the previous display, resulting in incorrectly drawn text or other cell contents.
To get the rectangles, you can either test different kinds of values which suits the situation best, or you can get each cell in the 2nd and 3rd column independently and use GetClientRect to fetch their rectangles. Easier way is, of course, to fit a rectangle to cover the two columns just by testing different values. It takes time, and patience, though.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Hi nnvidya,
Try this: http://www.codeproject.com/vcpp/gdiplus/what_is_a_basename_.asp
In my experience, this works. Also check out the article by Keith Rule that the author mentions.
Good luck,
Mick
|
|
|
|
|
hi ! thru : bool CreateMsgService(LPTSTR lpszService, LPTSTR lpszDisplayName)
we can create a service , but that pops up a property sheet page thru which user has to enter data to create the service.How can we fill in the information programatically ? I have seen a lot of applications automatically add services.I thought of two possible ways.One is that they might be an option using some other API or modified version of this one, or else use Inter process communication to send a WM_MINIMIZe to the property sheet page , and then using SetWindowText( ) after retrieveing the windows handle and detecting the fields.This is theoritically possible but sounds a bit clumsy isn't it ? I am sure it is possible somehow...you have any idea ?
Can you also explain to me the usage of ConfigureMsgService ? I could not find the proper docs in MSDN..
Thanks in advance
Regards
Kane
"Some guys hack just to get themselves a girlfriend.What a pathetic reason ,huh ?"
|
|
|
|
|
HI ,
Can any one tell me how can i send data to paralle port . n how can i recive from it
i think there is also a difference to send and recive on windows 98 and on NT n XP
is it
plz send me any sample
thanx
|
|
|
|
|
Hi,
You can use platform SDKs File Storage operations also for writing and reading data from communication resources (such as parallel and serial ports).
Check out CreateFile() , WriteFile() and ReadFile() from MSDN.
Cohen
|
|
|
|
|
Why do MS prefer to provide a new function, CWnd::CreateEx, rather than override CWnd::Create()?
|
|
|
|
|
The first one calls CreateWindowEx and allows access to the extended window flags, and the latter calls CreateWindowEx , but specifies the extended window flags as zero. Or, at least this is the way it does in MFC v7.0..
The biggest reason is backwards compatibility. The first function offers a superseded set of options related to window creation. However, the MFC library MUST support older versions also. Like, if a client has MFC version 7.0 libraries installed, this library must also support programs designed for MFC 6.0 or earlier. Thus, if a program used to call CWnd::Create , and the behaviour of this function was altered when the version changed, the results would become unpredictable, and the program might not work correctly. Thus, Microsoft preferred to provide a new function.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
I am attempting to write a CListCtrl with CustomDraw for PocketPC 2002 in Embedded C++ 3.0. I hoped to have the list control handle custom draw messages (to display red text for negative numbers) so three dialogs could benefit. Have found that ON_NOTIFY_REFLECT messages never arrive in the control. Brad Spencer at Group1 Software verified that list controls don't receive custom draw events. I began catching NOTIFY messages in the dialog and directly handing them off to a custom draw message handler in the control. The handler code follows below:
The PosDialog transfers control to a public function of the control which hands the call to a (protected) custom draw message handler.
ON_NOTIFY( NM_CUSTOMDRAW, IDC_PosList, OnCustDrwPosLst )
void CPosDialog::OnCustDrwPosLst( NMHDR* pNMHDR, LRESULT* pResult )
{ CRBListCtrl* pLC = (CRBListCtrl*)this->GetDlgItem( IDC_PosList );
pLC->ReflectCustomDraw( pNMHDR, pResult );
}
The control passes control to a handler written to respond to ON_NOTIFY_REFLECT messages (which never arrive). In the control's .h file:
public:
void ReflectCustomDraw( NMHDR* pNMHDR, LRESULT* pResult )
{ OnCustomDraw( pNMHDR, pResult); };
and its .cpp file:
ON_NOTIFY_REFLECT( NM_CUSTOMDRAW, OnCustomDraw )
void CRBListCtrl::OnCustomDraw( NMHDR* pNMHDR, LRESULT* pResult )
{ NMLVCUSTOMDRAW* pCustomDraw = (NMLVCUSTOMDRAW*)pNMHDR;
NMCUSTOMDRAW nmcd = pCustomDraw->nmcd;
int rr = nmcd.dwItemSpec;
DWORD drawStage = nmcd.dwDrawStage;
switch ( drawStage )
{ case CDDS_PREPAINT:
*pResult = CDRF_NOTIFYITEMDRAW;
break;
case CDDS_ITEMPREPAINT:
*pResult = CDRF_NOTIFYSUBITEMDRAW;
break;
case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
{ // which subitem?
int si = pCustomDraw->iSubItem;
CString cst = GetItemText( rr, si );
bool red = (cst[0] == '-'); //access violation
CDC* dc = CDC::FromHandle( nmcd.hdc );
dc->SetTextColor( red ? RGB(255,0,0) : RGB(0,0,0) );
*pResult = CDRF_NOTIFYPOSTPAINT;
break;
}
case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
{ CDC* dc = CDC::FromHandle( nmcd.hdc );
dc->SetTextColor( RGB(0,0,0) );
*pResult = CDRF_DODEFAULT;
break;
}
default:
break;
}
}
GetItemText() above returns a CString which (if accessed) will produce a memory access violation.
The other possibly relevant code is functionally identical to Mike Blazczak's AddPool() on p. 443 of "MFC with Visual C++ 6", excerpted here:
LPTSTR CPosDialog::AddPool( CString* cst )
{ CString& nxCStr = cstPool[ nextFreeSlot ];
nxCStr = *cst;
// an access violation occurs below when AddPool() is a
// member of the list control, but it works as part of
// the dialog (here)
LPTSTR retVal = nxCStr.LockBuffer();
pBufPool[ nextFreeSlot ] = retVal;
nxCStr.ReleaseBuffer();
if ( ++nextFreeSlot > 2 ) nextFreeSlot = 0;
return retVal;
}
The control displays everything just fine (in black) if you comment out the offending GetItemText() call. When you replace the ?: color selector in SetTextColor(), so the line reads dc->SetTextColor( RGB(255,0,0) ), you'd think all of the text would be red, but its still black.
This patch of code is driving me nuts. I'd be particularly grateful (will send $50) to the first responder with a working solution to an issue mentioned above: 1) How to get a CString from GetItemText() that won't produce an access violation. 2) Explain how to get the text color to change to red (basically, explain what I'm doing wrong).
Thanks, Mike Landis
|
|
|
|
|
Try to check control HWND/id before calling ReflectCustomDraw in CPosDialog::OnCustDrwPosLst. I guess there are some other controls and you're just calling ReflectCustomDraw too often. In other words, ReflectCustomDraw tries to handle message targeted to other window.
BTW: I have eVC 3.0 app here, and reflected NM_CUSTOMDRAW works perfectly for CListCtrl without hacks like OnCustDrwPosLst. But then, I host them in CPropertyPage-derived class.
Tomasz Sowinski -- http://www.shooltz.com
Alika masiaka!
|
|
|
|
|
Tom,
I appreciate the fast reply, but I'm fairly certain the dialog's
ON_NOTIFY( NM_CUSTOMDRAW, IDC_PosList, OnCustDrwPosLst )
effectively filters out messages meant for controls other than PosList. When I get PosList messages in the debugger, the other controls seem to have finished painting, though the list control is the only one listening for CustomDraw messages.
View derived classes apparently get their CustomDraw messages and (from what I can tell) CtrlList derived classes get REFLECTed CustomDraw messages on other targets, but CtrlLists on PocletPC 2002 don't get notified without the hack. Possibly comctl32 builds are customized per target.
I'd love not to have the hack, but at this point, I just want GetItemText to stop crashing and subitem text to paint red when I tell it to.
-Mike Landis
|
|
|
|
|
Mike Landis wrote:
appreciate the fast reply, but I'm fairly certain the dialog's
ON_NOTIFY( NM_CUSTOMDRAW, IDC_PosList, OnCustDrwPosLst )
effectively filters out messages meant for controls other than PosList
Yes, I realized this right after posting the reply. Just to be 102% sure, check if you don't have duplicate control IDs in your dialog. This would screw notification routing.
At this point, I'd resort to basic debugging tricks. What are the contents of pCustomDraw structure - are members looking 'normally' or rather it's random data?
Also, according to comments in the code your program crashes when you're accessing the 0th element of the string. Maybe GetItemText returns empty one?
Tomasz Sowinski -- http://www.shooltz.com
Alika masiaka!
|
|
|
|
|
I don't think eVC 3.0 will load the resource file if you have conflicting IDs in the same dialog (I've had to fix this after hand editing the resource files before). I have hundreds of calls where I cast from CWnd* to a *Ctrl of some sort - the eVC3 documentation for CWnd::GetDlgItem says:
This method retrieves a pointer to the specified control or child window in a dialog box or other window. The pointer returned is usually cast to the type of control identified by nID.
The struct pointed to by pCustomDraw looks normal as does the nmcd struct.
You're absolutely right that GetItemTxt() could be returning an empty string. Its returning an empty string for every subitem in the list control. Why would that happen? The following:
if ( cst.GetLength() > 0 )
{ bool red = ( cst[0] == '-' );
CDC* dc = CDC::FromHandle( nmcd.hdc );
dc->SetTextColor( red ? RGB(255,0,0) : RGB(0,0,0) );
}
prevents access violations, but doesn't explain why cst comes back "" for every subitem.
In watching the code that responds to the LVN_GETDISPINFO messages to the PosListCtrl just before the CustomDraw messages come in, I can see normal looking CString values coming out of the LVN_GETDISPINFO handler:
void CSPosDialog::OnGetDispInfoPosList( NMHDR* pNMHDR, LRESULT* pResult )
{ LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
if ( pDispInfo->item.mask & LVIF_TEXT )
{ SPosListItemInfo* pItem =
(SPosListItemInfo*) pDispInfo->item.lParam;
CString cst = this->GetPosItemText( pDispInfo->item.iItem, pDispInfo->item.iSubItem );
LPTSTR pBuf = this->AddPool( &cst );
pDispInfo->item.pszText = pBuf;
}
*pResult = 0;
}
CString CSPosDialog::GetPosItemText( int rr, int si )
{ // get the sortCol for this subitem
CBOSListCtrl* pLC = (CBOSListCtrl*)this->GetDlgItem( IDC_PosList );
short msi = pLC->MapSubitem( si ); // column reordering
CHeaderCtrl* pHdr = pLC->GetHeaderCtrl();
short nItems = pHdr->GetItemCount();
if ( msi < 0 || msi >= nItems-1 ) return _T("");
SPosListItemInfo* pItem = (SPosListItemInfo*)pLC->GetItemData( rr );
if ( !pItem ) return _T(""); // impossible
CPos* pos = pItem->thePos;
bool itsTheTotalRow = ( pos == 0 );
double res;
if ( msi == 8 )
return itsTheTotalRow ? _T("") : pos->note;
unsigned short buf[20];
switch ( msi )
{ case 0:
swprintf( buf, "first col ..." );
// ...
case 7:
swprintf( buf, "other ..." );
}
CString cst( buf );
return cst;
}
CStrings coming out of OnGetDispInfoPosList(), feed AddPool(), and both look normal. Just after, in GetItemText(), all I get is "". That's the mystery.
Note, if I take all the conditions out of setting the text color in OnCustomDraw(), so it should paint subitem text in red no matter what, I still get black. That's the other mystery.
-Mike
|
|
|
|
|
Mike Landis wrote:
I have hundreds of calls where I cast from CWnd* to a *Ctrl of some sort - the eVC3 documentation for CWnd::GetDlgItem says:
This method retrieves a pointer to the specified control or child window in a dialog box or other window. The pointer returned is usually cast to the type of control identified by nID.
Well, this allows you to call wrapper methods which basically use SendMessage to expose Win32 control functionality. I'm assuming there's no associated MFC object and GetDlgItem returns temporary CWnd *. In such case you can't also use message reflection - this could contribute to your problems with NM_CUSTOMDRAW not passing through.
Anyway, the problem obviously lies in AddPool and/or related functions. I can't really comment on this, because parts of the code implementing pool are missing. I guess you should put the breakpoint in OnGetDispInfoList, in the line where pszText is actually set. You may also use TRACE to check if LVN_GETDISPINFO is handled correctly.
Wrt to changed text color - you should change the clrText member instead of using SetTextColor.
Tomasz Sowinski -- http://www.shooltz.com
Alika masiaka!
|
|
|
|
|
There are real MFC objects behind the GetDlgItem call, so I think the CWnd*s are real. I use the (cast)ptrs to call CCtrlList, CEdit, etc. functions. I'm not wrapping anything, just subclassing, so I hope I haven't killed NM_CUSTOMDRAW passthrough. The reason I don't suspect OnGetDispInfoList() is because the control behaves quite rationally in all other cases. I can scroll the view generating update events and it handily fetches the right stuff from OnGetDispInfoList() and displays it in the control.
The only other code I know is:
const unsigned short StringPoolSize = 3;
unsigned short nextFreeSlot;
CString cstPool[StringPoolSize ];
LPTSTR pBufPool[StringPoolSize ];
from the PosDialog's .h file and GetItemText in the ListCtrl itself, excerpted here:
CString CListCtrl::GetItemText(int nItem, int nSubItem) const
{
ASSERT(::IsWindow(m_hWnd));
LVITEM lvi;
memset(&lvi, 0, sizeof(LVITEM));
lvi.iSubItem = nSubItem;
CString str;
int nLen = 128;
int nRes;
do
{
nLen *= 2;
lvi.cchTextMax = nLen;
lvi.pszText = str.GetBufferSetLength(nLen);
nRes = (int)::SendMessage(m_hWnd, LVM_GETITEMTEXT, (WPARAM)nItem,
(LPARAM)&lvi);
} while (nRes == nLen-1);
str.ReleaseBuffer();
return str;
}
The chain of events is: the CustomDraw handler calls GetItemText which sends a LVM_GETITEMTEXT message, received by GetDispInfoPosList which puts the CString in the pool (calls AddPool). AddPool plays with the reference count so the CString can't be released and sends back its pool copy. The LPTSTR retVal also looks good every time and its still okay when pDispInfo->item.pszText is assigned in OnGetDispInfoPosList(). Then you're back in _AfxDispatchCmdMsg (which can hardly be screwed up). str still shows the correct value after ReleaseBuffer in GetItemText and is good when you are at the final brace. The next thing you know, you're in OnCustomDraw and the string is gone. Apparently ReleaseBuffer decrements the reference count to 0 and the string goes away when the stack unrolls.
Thinking that Blazczak's pooling didn't anticipate CustomDraw calling GetItemText(), ultimately leading to one ReleaseBuffer() call he hadn't anticipated, I tried setting:
const unsigned short StringPoolSize = 4;
in the PosDialog's .h file and modifying the circular indexing in AddPool to use StringPoolSize (instead of 3), so it now reads:
if ( ++nextFreeSlot > StringPoolSize-1 )
nextFreeSlot = 0;
No change was evident. As soon as you return from GetItemText(), where the reference count on the string was decremented by ReleaseBuffer, its gone.
There's no other code. The answer (I think) is getting the reference count to be > 1 when GetItemText releases the buffer, because str is still okay when GetItemText is about to return (still at the top of the stack).
On the color, the evc3 help doesn't show you the structure under the m_hAttribDC. In the debugger, I can see inside dc to the m_hAttribDC, but only see 'unused' within. Not sure what to do with that.
-Mike
|
|
|
|
|
Mike Landis wrote:
There are real MFC objects behind the GetDlgItem call, so I think the CWnd*s are real. I use the (cast)ptrs to call CCtrlList, CEdit, etc. functions. I'm not wrapping anything, just subclassing, so I hope I haven't killed NM_CUSTOMDRAW passthrough
If you have associated MFC objects, why do you call GetDlgItem? You should have some CListCtrl-derived objects as dialog members, and you should be able to access them easily. The fact you resorted to GetDlgItem suggests they are not there. This would explain missing NM_CUSTOMDRAWs.
On the color, the evc3 help doesn't show you the structure under the m_hAttribDC. In the debugger, I can see inside dc to the m_hAttribDC, but only see 'unused' within. Not sure what to do with that.
I'm not referring to CDC. To set the color of list item text, you don't call CDC::SetItemText. You just set the clrText member of NMLVCUSTOMDRAW to RGB you need.
Pool - is there real reason for pooling? Or you just have a feeling this would be good from perf viewpoint?
Tomasz Sowinski -- http://www.shooltz.com
*** Purgamentum init, exit purgamentum ***
|
|
|
|
|
pCustomDraw->clrText = RGB(255,0,0); works like a charm. Saw it in the structure and forgot about it until you reminded me.
I am not sure what you're referring to regarding the controls. I build up dialogs by adding controls in the resource editor. I've been finding them by calling GetDlgItem(). It's been working for responding to other messages. I didn't think NM_CUSTOMDRAW worked differently.
On Pooling - all I know is that there is a data longevity requirement which Blazczak's AddPool solves. If you don't do it absolutely nothing displays in the list control. This is behaving exactly the same way that it did before I put the pooling in. Blazczak says that you have to cache strings through two LBN_GETDISPINFO notifications after the one where you set the value.
- Mike Landis
|
|
|
|
|