|
|
Thanks for the tip... but this won't work because when you override the default behaviour you literally override the default behaviour. Something as simple as highlighting will stop working. I can go down this route but I really don't want to have to write all the basic functionality for a list control because MS somehow added a beep. I'll consider this as a method of last resort.
|
|
|
|
|
I have found the solution to the problem myself...
Under sounds in Vista, if the entry "Select" has ever been given a sound file to play and then set back to empty the control will bing. The only easy fix I can see at this point is to assign an empty sound file to that entry. That will elliminate the problem.
I'd suggest this is a bug in Vista.
Anthony
|
|
|
|
|
In my VC6++ source, I'm building a sql string and I run into a problem when a field or string contains an apostrophe or single quote. The single quote in the CString object causes an improper termination of the SQL string syntax. Is there a way around this?
For example:
int iVendorID = 1;<br />
<br />
CString csVendorName = _T("Matt's Hobby Shop");<br />
<br />
CString csSQL = _T("");<br />
<br />
csSQL.Format(_T("Update tblVendorList Set VendorDescription='%s' where VendorID=%d"), csVendorName, iVendorID);
During execution, the sql statement becomes
Update tblVendorList Set VendorDescription='Matt's Hobby Shop' where VendorID=1
And things get ugly because it wants to set VendorDescription to 'Matt' and it has no idea what s Hobby Shop means.
|
|
|
|
|
in SQL, you must type a double simple quote if within a string...
CString csVendorName = _T("Matt''s Hobby Shop");
but the best is ever to use Parametrized Queries...
|
|
|
|
|
littleGreenDude wrote: CString csVendorName = _T("Matt's Hobby Shop");
How about:
CString csVendorName = _T("Matt''s Hobby Shop");
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I have a barcode scanner which can emulate a Com Port (i.e. in the Device Manager it appears as a Com Port and I can communicate to it via HyperTerminal). How can I programmatically determine which Com Port (COM1, COM2, COM3, ..., etc) has been assigned to my scanner? If I look in the Device Manager there is some additional information available:
Metrologic USB Scanner (COM4)
Can I retrieve this additional descriptive information somehow from my C++ application? Thanks you in advance for any help.
|
|
|
|
|
The way to do this is to scan the available serial ports and then send a command to the deivce or something that will produce a known response. When you get the response, you have the device. Check if the Mfg. gives you a SDK to work with or they update the registry with useful information. Check the CP projects for a serial port scanner. I think Paul Discalia (sp?) did one a long time ago.
|
|
|
|
|
Thanks for your suggestion. I was unable to locate the serial port example by Paul, but I found another example that does exactly what I would like to do:
http://www.naughter.com/enumser.html[^]
The function CEnumerateSerial::UsingSetupAPI2 reads the entries in the Device Manager so I get the descriptive name of my barcode scanner and can thus locate the correct com port without having to actually communicate over it.
|
|
|
|
|
PJ Naughter is the guy I was thinking of, not Paul.
Sorry about that.
|
|
|
|
|
I have an application which allows users to create documents that could potentially contain a lot of fonts, brushes and pens. In order to keep GDI handle usage to a minimum I was planning to implement some form of shared GDI object pool (as many of the GDI objects used by these documents will be the same) but before I did I thought it worth asking if anyone here has come across anything similar before. I am using MFC FWIW.
Thanks in advance.
|
|
|
|
|
Rob Caldecott wrote: asking if anyone here has come across anything similar before
Yes I have implemented and seen libraries for object pools. I believe they are fairly common. In fact there is C++ template based article for one here on code project which one finds with a simple Google search[^].
|
|
|
|
|
I derived my class from CListBox called CMyListBox.
then I write the virtual function MeasureItem to change the height of items.
In my main dialog CMyDialog, construct a CMyListBox object.
CMyListBox m_ctlBox;
and in the CMyDialog::OnInitDialog
<br />
DDX_Control(pDX, BOXID, m_ctlBox);<br />
CMyDialog::OnInitDialog()<br />
{<br />
m_ctlBox.ModifyStyle(0, LBS_OWNERDRAWFIXED);<br />
}<br />
but it has no affect. The height doesn't change at all. But it executes fine.
Then I've tried comment the code m_ctlBox.ModifyStyle(0, LBS_OWNERDRAWFIXED);
And in the resource editor, I change the property of the ListBox with OwnerDraw to OwnerDrawFixed, then I got compilation assertion error.
What do I miss? And Why do I get the assertion error?But I don't want to create the CMyListBox on the fly at all, cause If I create it on the fly, I can't adjust its position and size.
And in the book «Programming with MFC 2nd», I program as the book shows, it works fine.
First, in the CMyListBox use the PreCreateWindowClass to add the style with LBS_OWNERDRAWFIXED OR LBS_OWNERDRAWVARIABLE.
Second, in the virtual MeasureItem function to change the height.
Third, But you should in the CMyDialog::OnInitDialog to create the CMyListBox on the fly, it should use CMyListBox.Create to create the ListBox, otherwise the CMyListBox::PreCreateWindowClass would not be called to initialize the style with LBS_OWNERDRAWFIXED.
|
|
|
|
|
The proper place to do all this is inside your override of the PreSubclassWindow() function.
This function is called regardless of whether the control is created dynamically with a call to Create(), or on-the-fly with a dialog resource template and subclassed with the DDX_Control functions.
See http://www.flounder.com/presubclasswindow.htm[^]
|
|
|
|
|
Hi all,
A simple question, although I do not know the answer, but how can I get the size of a char* array.
I have tried the following:
char* array[2] = {"!5","C2"};
sizeof(array)
sizeof(array) 8 (0x00000008)
Can anyone please help?
Thanks in advance
Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
you cannot. you have to maintain a counter variable to know the current number of elements in your array, if its size is not constant...
doing a sizeof(array) will do nothing but returning you the size of the variable array, which is of type char**; and as long as a pointer is 8 bytes long... sizeof(array) returns 8.
If you were using C++, you could have used std::vector<std::string> for instance, but AFAIK, you're using C only...
|
|
|
|
|
toxcct, thanks for the response, I don't want to be forward but how would one then do it using std::vector<std::string> (if I may be so bold ...)
Thanks again ...
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
those 2 classes are part of the Standard Template Library (better known as STL).
in your case, it would be very easy to use :
std::vector<std::string> array;
array.add("Hello");
array.add("World");
size_t n = array.size();
|
|
|
|
|
|
Programm3r wrote: (if I may be so bold ...)
Why is asking a legitimate question considered being bold?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I think he refers to the daunting design challenge of using STL .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
in general, you can't. C/C++ doesn't keep track of array dimensions. at best, you can get the size of a 1D array like this:
#define _ARRAYSIZE(__a) (sizeof(__a)/sizeof(__a[0]))
int array[5] = {0,1,2,3,4};
int s = _ARRAYSIZE(array);
... s = 5
but that only works if the array is declared in the same scope - it won't work if you just have a pointer to the array.
use the STL's collections.
|
|
|
|
|
Thanks for the response Chris, I'll give it a try.
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
Programm3r wrote: A simple question, although I do not know the answer, but how can I get the size of a char* array.
Do you really need the size of the array or the number of its elements?
The compiler is, of course, answering correctly to your request: it returns 8 because your array contains two char * and each pointer size is 4 (on a 32-bit system).
If you want to know how many elements the array has, then use, as suggested
by Chris Losinger [^]
sizeof(array)/sizeof(array[0]);
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
Thanks for the response CPallini.
CPallini wrote: Do you really need the size of the array or the number of its elements?
Yes, size of the array or the number of its elements.
CPallini wrote: If you want to know how many elements the array has, then use, as suggested
by Chris Losinger [^]
Thanks
Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|