Visual C++
How to set Font for Static Text Controls?
1![]()
By default, static text is displayed in normal fonts. And you don’t have any option to make it bold or italic or underline. Is there any way to enable these styles and change the font of the static text control?

![]()
Yes! you can do it. First you’ve to get the current font of the text control and then enable the styles you need then set it back. Setting font is done in OnInitDialog() and new font is kept as member variable. See the code snippet below.
BOOL CStaticFontDlg::OnInitDialog()
{
...
// Get current font.
CFont* pFont = GetDlgItem( IDC_STATIC_ITALIC )->GetFont();
LOGFONT LogFont = { 0 };
pFont->GetLogFont( &LogFont );
// Create new font with underline style.
LogFont.lfUnderline = TRUE;
m_StaticFont.CreateFontIndirect( &LogFont );
// Sets the new font back to static text.
GetDlgItem( IDC_STATIC_ITALIC )->SetFont( &m_StaticFont );
return TRUE;
}
Now the static text will look like this.

![]()
Don’t forget to change the Id of static text control from IDC_STATIC to something else. Or else GetDlgItem() will return invalid handle.
![]()
Targeted Audiance – Intermediate.
gotoxy() function in Visual C++?
5![]()
I often feel nostalgic about the gotoxy() function in old Turbo C++. The gotoxy() is used to “jump” to any point of the console screen. I used that function to create nice menu effects. But unfortunately in visual C++, gotoxy() is not available. But is there any other api which can be used instead of gotoxy()?

![]()
You can use SetConsoleCursorPosition(). Check out the following sample program. It reads an integer in loop and prints the time in the right hand corner of console. Just a demonstration of Visual C++’s gotoxy().

#include "iostream"
#include "time.h"
#include "windows.h"
using namespace std;
// Set current cursor position.
void GotoXY( HANDLE StdOut, SHORT x, SHORT y )
{
// Set the cursor position.
COORD Cord;
Cord.X = x;
Cord.Y = y;
SetConsoleCursorPosition( StdOut, Cord );
}
// Print time at the upper right corner of console.
void PrintTime()
{
// Get handle to console output buffer.
HANDLE hStdout = GetStdHandle( STD_OUTPUT_HANDLE );
// Get current screen information.
CONSOLE_SCREEN_BUFFER_INFO ScreenBufferInfo = { 0 };
GetConsoleScreenBufferInfo( hStdout, &ScreenBufferInfo );
// Set the cursor position to upper-right of console.
GotoXY( hStdout, 50, 0 );
// Get time and display it.
time_t tim=time(NULL);
char *s=ctime(&tim);
cout << s;
// Reset cursor back to position.
GotoXY( hStdout,
ScreenBufferInfo.dwCursorPosition.X,
ScreenBufferInfo.dwCursorPosition.Y );
}
void main(int argc, char* argv[])
{
// Just to provide enough space.
cout << endl << endl;
while( true )
{
// Print the time.
PrintTime();
// Read a value.
int a;
cout << "Enter number: ";
cin >> a;
}
}
![]()
Yes! After a short break, I’m back.
You’ll soon have a happy news from me, within a week.
Keep watching.
![]()
Targeted Audience – Beginners.
How to Enable XP/Vista themes in your Dialog?
8![]()
From Windows XP onwards, the basic control look and feel have improved drastically. Previously, they were merely flat style controls without any effects- the maximum you can do is to change the control color and mouse cursor icon( I hope you do remember the Jungle Theme of those old win98 days). In Vista its even more stylish. But is it possible to give the same look & feel effects to our applications as well?

![]()
Yes. You can. You just have to add a manifest file to your application. Well follow the detailed steps about how to do it. Well, we are going to apply Vista look and feel to the following dialog.

1) The manifest format is specified below. Copy it to notepad and change the “ExeName” to the name of your application. For instance if your exename is Rabbit.exe, then “ExeName” is “Rabbit”.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="X86"
name="ExeName"
type="win32"
/>
<description>Application Description</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
2) Now insert a new resource.

3) Now add a new Custom Resource with Resource ID as 24.

4) Now copy-paste the manifest contents to new resource and save it. Make sure you’ve changed the “ExeName” to your application name.

5) Now take the properties of our new resource – “IDR_DEFAULT1″.

6) Now change the Resource ID to “1“.

7) That’s it. Now compile and run the application. And now see the command buttons in Vista Style. Cool! isn’t it?

![]()
I searched a lot for the screenshot of the old “Jungle Theme” of Windows 98. Its a pity that I couldn’t find it.
If you find one such, please do notify. I’m getting nostalgic.
![]()
Targeted Audience – Intermediate.