Hottest Forum Q&A on CodeGuru for the week of March 7, 2004


Lots of hot topics are covered in the Discussion Forums on CodeGuru. If you missed the forums this week, you missed some interesting ways to solve a problem. Some of the hot topics this week include:

How can I shorten a String? (top)


stoneyrh is working with with strings. Unfortunately, his string is too long—49 chars. Now, he needs to shorten the string to 10-20 chars. How can he achieve this? It's not actually a big deal, right? So, what is the purpose behind that? First, take a look at the original question.

I have a serial of strings that each one of them is different
from each another.But each one has a length of 49 characters. I want
to shorten them to about 10-20 characters and each one of them after
shortened should be different from each another too. But I don't know
how to do it. Can anyone help me with it?


Maybe what I really want is to automatically generate a serial of
strings with about 10-20 characters that each one of them is
different from each another. But I can't do that either.I got them
with 49 characters.

So why does he need that? After reading some further messages, stoneyrh explained that he has combined a CPUID-string and the current date-time string as a long string to identify one special user in his database. He hopes to use the string as a barcode and the barcode will be printed to a card that is kept by the user. This clarifies the problem.

This is a very large string for a barcode. Besides that, it contains several "0"s in the string. You should find out whether there is any chance to have numbers in their place. If there is no chance, you can delete them. Is it possible to delete or reduce the timestamp? Are seconds really needed? This and some other questions are open before somebody can help. Marc from D suggests some very nice techniques to solve the problem. Take a look at the thread and maybe you also will find it helpful.

How do I hide a shortcut from a desktop window? (top)


shoma1508 wants to hide the shortcuts from the desktop Window without using the hide attribute of a file. Do you know how to do that?


I want to hide a shortcut from a Desktop window. But I do not want
to use the hide attribute of the file. I am using VC++. Can anyone
help on this topic?


Unfortunately, this is not possible. The only way to this is via the HIDE attribute. But, one question that comes into my mind is why do you want to have a shortcut on the desktop and at the same time keep it hidden? Take a look at the thread and you will know.

How can I subclass a CButton class for a Checkbox? (top)


jiac wants to subclass a CButton class. Can you help him?

Hi Friends,

I need to subclass a checkbox, and that is of the CButton class.
I tried that, and overwrote OnPaint(); however, the checkbox
disappears. I guess that is because I would need to paint the
checkbox as well. Well, that is beyond my knowledge, so I tried to
overwrite OnCtlColor; however, that doesn't get called.

One post said that I would need to set the ownerdraw flag. I tried
that, but it doesn't work with the following:
m_chk.SubclassDlgItem(IDC_CHK1, this);

DWORD style = m_chk.GetStyle();
style |= BS_OWNERDRAW;
::SetWindowLong(m_chk, GWL_STYLE, style);
I placed this in OnInitDlg.

Please help. Am I understanding this correctly and how to fix this?

Basically, I need to change the font size/color of the checkbox text
but still retain the checkbox bitmap itself because I don't know
how to draw that.

You don't need to sublass your CButton class to change the font size and color. All you have to do is to create an OnCtlColor() handler and check whether the window pointer passed in is your CheckBox; then set the text color to whatever using pDC->SetTextColor(...);. This looks like this:

HBRUSH CDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    if(pWnd == &m_Check)
    return hbr;

Why is VC++ confused by The Registry and drives? (top)


Dinker, a junior member, asked a very interesting question.

I had an extra hard drive present in my PC that had a drive
allocation of D:. I installed MS Visual Studio to drive E:. I
then had to remove Drive D:, which meant that the drive that was E:
is now D:. Consequently, all the Registry entries for MS Visual
Studio are now pointing to the wrong drive. There are too many
entries for me to correct easily and I've now lost the facility to
correct it myself by writing a program! Can somebody help me out?
Given that all Registry entries of "E:\" should be "D:\"... Is
there another way? Please help! It's very frustrating....

Thanks in advance.

If you are running Windows NT and above, you can use Diskmanager to assign any drive letter you want to the drive; thus, you can make the drive letter E again. If not, there are some freeware tools that do the same. But, the best solution to that problem is to reinstall Visual Studio.

About the Author

Sonu Kapoor

Sonu Kapoor is an ASP.NET MVP and MCAD. He is the owner of the popular .net website DotNetSlackers publishs the latest .net news and articles - it contains forums and blogs as well. His blog can be seen at:


  • COA2

    Posted by gjr on 03/16/2004 06:59pm

    Try the PCMag free utility "Change of Address". It handles just this sort of problem very well.

    • Thanks

      Posted by Sonu Kapoor on 03/18/2004 03:27pm

      Thanks gjir for the suggestion.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Protect Your Business against Today's Rapidly Growing Threats Your business, employees, partners, and customers are depending more and more on network connectivity, and protecting data and infrastructure has moved to the top of the IT agenda. You can't arm yourself against today's rapidly increasing threats unless you understand how they work. Read this ebook to learn more about the top 10 DNS attacks that can target your external and internal DNS infrastructure, the impact they can have on the DNS server …

  • Essential Insights for Successful Cloud Migration and Management Whether you're planning your cloud migration strategy or already in the cloud, making accurate cloud decisions requires a deep analytical approach. This paper discusses the main objectives to achieve, top questions to ask, and the analytics you need at each stage of your cloud journey. You'll learn: How to identify which cloud provider will provide the best cost and performance benefits for your organization How to determine which applications …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date