Hottest Forum Q&A on CodeGuru

Tuesday Mar 16th 2004 by Sonu Kapoor

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.


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 CButton class. I
tried that, and overwrite OnPaint(); however, the check box
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.

Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved