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

Introduction:

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)

Thread:

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?

or

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)

Thread:

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?

Hi,

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?

BR
Shoma

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)

Thread:

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)
    {
        pDC->SetTextColor(RGB(255,0,0));
    }
    return hbr;
}


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

Thread:

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 http://dotnetslackers.com. DotNetSlackers publishs the latest .net news and articles - it contains forums and blogs as well. His blog can be seen at: http://dotnetslackers.com/community/blogs/sonukapoor/

Comments

  • 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.

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

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Live Event Date: October 29, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this eSeminar, Gene Kim will discuss these survey findings and will share woeful tales of artifact management gone wrong! Gene will also share examples of how …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds