IT Community - Software Programming, Web Development and Technical Support

Visual C++ Tips & Tricks

This is a discussion on Visual C++ Tips & Tricks within the C and C++ Programming forums, part of the Software Development category; The following macros make it easy to add reminders which are displayed when code is compiled. You can double click ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C and C++ Programming

Register FAQ Members List Calendar Mark Forums Read

Reply
 
Thread Tools Display Modes
  #21  
Old 04-06-2007, 04:08 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 301
Karpagarajan is on a distinguished road
Thumbs up Re: VC++ Tips & Tricks

The following macros make it easy to add reminders which are displayed when code is compiled. You can double click on a reminder in the Output Window and jump to the line. Useful for marking TODOs.

// Statements like:
// #pragma message(Reminder "Fix this problem!")
// Which will cause messages like:
// C:\Source\Project\main.cpp(47): Reminder: Fix this problem!
// to show up during compiles. Note that you can NOT use the
// words "error" or "warning" in your reminders, since it will
// make the IDE think it should abort execution. You can double
// click on these messages and jump to the line in question.
#define Stringize( L ) #L
#define MakeString( M, L ) M(L)
#define $Line \
MakeString( Stringize, __LINE__ )
#define Reminder \
__FILE__ "(" $Line ") : Reminder: "
Once defined, use like so:

#pragma message(Reminder "Fix this problem!")
This will create output like:

C:\Source\Project\main.cpp(47): Reminder: Fix this problem!


thanks
__________________
Karpagarajan. R
Necessity is the mother of invention
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #22  
Old 04-06-2007, 04:14 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 301
Karpagarajan is on a distinguished road
Thumbs up Re: VC++ Tips & Tricks

A bug with namespaces causes Visual C++ 6.0 to move a namespace to root in cases where it should only be in another namespace. Here is a small

example:
#include <string>

namespace ipl{ // use namespace ipl
using namespace std;
}

namespace ipl{ // use namespace ipl
}

int main()
{
string str;
return 0;
}

The code above should not compile since string in the main function is unknown, i.e. it should still be in the std namespace. This bug caused me to redo some code in IPL98, instead of writing using namespace std inside the ipl namespace, I am forced to explecitely write what functions/classes I need from the std library, for instance using std::string. This works.

thanks
__________________
Karpagarajan. R
Necessity is the mother of invention
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #23  
Old 04-13-2007, 03:58 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 301
Karpagarajan is on a distinguished road
Thumbs up Re: VC++ Tips & Tricks

Dealing with Palettes
I have written about palettes , I will say only that the application has a single palette that is created as a simple color cube to give a rough variety of colors. The application needs to handle two palette messages, and these are taken care of by these two functions:

void CPaintWnd::OnPaletteChanged(CWnd* pFocusWnd)
{
// See if the change was caused by us and ignore it if not.
if (pFocusWnd != this) {
OnQueryNewPalette();
}
}

BOOL CPaintWnd::OnQueryNewPalette()
{
// We are going active, so realize our palette.
if (m_pPal) {
CDC* pdc = GetDC();
CPalette *poldpal = pdc->SelectPalette(m_pPal, FALSE);
UINT u = pdc->RealizePalette();
ReleaseDC(pdc);
if (u != 0) {
// Some colors changed, so we need to repaint.
InvalidateRect(NULL, TRUE); // Repaint the lot.
return TRUE; // Say we did something.
}
}
return FALSE; // Say we did nothing.
}


That's more or less all there is to it, except to know that each time a new CDIB or CSprite object image is loaded, it must be mapped to this common palette by calling its MapColorsToPalette function. The CCrayon and CEraser classes are both derived from CDrawingTool, which does this for you in its Load function:

void CDrawingTool::Load(UINT uiID, CPalette* pPal)
{
ASSERT(uiID);
ASSERT(pPal);
BOOL b = CSprite::Load(uiID);
ASSERT(b);
MapColorsToPalette(pPal);
}


thanks
__________________
Karpagarajan. R
Necessity is the mother of invention

Last edited by Karpagarajan : 04-13-2007 at 04:01 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #24  
Old 07-16-2007, 05:46 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 301
Karpagarajan is on a distinguished road
Smile Re: VC++ Tips & Tricks

Hi

Here is the tips for avoiding the build errors in Visual C++.

To avoid build errors, when upgrading from one version of the compiler to another, make sure you have deleted your old PDB, PCH files.

thanks
__________________
Karpagarajan. R
Necessity is the mother of invention

Last edited by Booom : 08-09-2007 at 04:41 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #25  
Old 07-30-2007, 01:12 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 301
Karpagarajan is on a distinguished road
Post Re: VC++ Tips & Tricks

Here is the simple way to call URL...
________________________________________

Hi.. All
Here i give a simple way to call the URL using visual c++ code "ShellExecute"

ShellExecute(NULL,"open", "www.google.com", "", "c:\\", SW_SHOW);

thanks
__________________
Karpagarajan. R
Necessity is the mother of invention

Last edited by Booom : 08-09-2007 at 04:41 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #26  
Old 07-30-2007, 01:16 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 301
Karpagarajan is on a distinguished road
Default Re: VC++ Tips & Tricks

Hi.
Here is another tips.

When i tried to create a dll in c using visual c++ compiler i received these errors.

LNK2001: unresolved external symbol _main
Debug/windll.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.


Can you people tell why this error was occured?
....

Yeah..
The problem is I am creating a executable file
hence the compiler is looking for main method..

Inorder to create a DLL file we have to some manipulation in the project properties. i.e open the project properties window and select the link tab.
change the output file from exe to DLL and the "Project Options" text box change the "subsytem console" to "dll"

Thanks
__________________
Karpagarajan. R
Necessity is the mother of invention

Last edited by Booom : 08-09-2007 at 04:42 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #27  
Old 07-30-2007, 01:20 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 301
Karpagarajan is on a distinguished road
Default Re: VC++ Tips & Tricks

Hi All...

I developed one application which contains the listviews. In that
I gave the backgournd image for the listview.
In Some situations I need that listview should be blank(e.i without the background).

I dont know how to do this. I spent lot time to search in that.
Its simple. But that time i didnt know the code.
After some R&D i found it.

Do u know whats that?
Yeah this is what i had written in my code.

m_cListCtrl.SetBkImage( HBITMAP(0));

(HBITMAP(0) will return the NULL HBITMAP.)

bye
..........
thanks
__________________
Karpagarajan. R
Necessity is the mother of invention
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #28  
Old 07-30-2007, 01:22 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 301
Karpagarajan is on a distinguished road
Post Re: VC++ Tips & Tricks

Hi friends...

Today I am going to give the tips and tricks for the GDI+.

When I was new to the GDI+, I was not able to include the GDI+ library files into my project.

Here We will see how to link the GDI+ into our project.

1.) Go to Project setting by pressing Alt+F7.
2.) Go to Link tab in the Project Property, In that select Input from the category
combo list.
3.) Include the GDIplus.dll file path
4.) Then go to Application class header file(e.g App.h). In that Add the following code to link the GDI+ library class and functions.

#include <vector>
#include "myGdiPlus.h"
using namespace Gdiplus;

//Image Thread Handle
ULONG_PTR gdiplusToken;

//And Start the GDIplus in Application InitInstance()
//begin: initialize GDI+
GdiplusStartupInput gdiplusStartupInput;
VERIFY(GdiplusStartup( &gdiplusToken, &gdiplusStartupInput, NULL ) == Ok );
//end: initialize GDI+

//And Shutdown the GDIplus in Application ExitInstance()
//begin: shutdown GDI+
GdiplusShutdown(gdiplusToken);
//end: shutdown GDI+

Now your application will support the GDI+ class and functions

...........
bye
Thanks
__________________
Karpagarajan. R
Necessity is the mother of invention
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #29  
Old 07-30-2007, 01:25 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 301
Karpagarajan is on a distinguished road
Post Re: VC++ Tips & Tricks

Hi friends...
Here another tips.

Using GDI+, You can get the image from HBITMAP.
This is why i gave as a tips, some time we will need to load a picture in Static control or listview item. For that we need HBITMAP.
//The following code will help for this.
HBITMAP hBmp;
CString pszPath=_T("C:\\test.jpg");
WCHAR wpath[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, pszPath, -1, wpath, MAX_PATH);

Bitmap image(wpath);
bmPhoto = new Bitmap( IMGWIDTH, IMGHEIGHT, PixelFormat24bppRGB );
bmPhoto->SetResolution( image.GetHorizontalResolution(), image.GetVerticalResolution() );

Graphics *grPhoto = Graphics::FromImage( bmPhoto );
Color colorW(255, 255, 255, 255);
grPhoto->Clear( colorW );
grPhoto->SetInterpolationMode( InterpolationModeHighQualityBicubic );
grPhoto->DrawImage( &image, Rect(destX, destY, destWidth, destHeight) );

bmPhoto->GetHBITMAP( colorW, &hBmp );
//End of the code
Hope this will help you
..............
bye
Thanks
__________________
Karpagarajan. R
Necessity is the mother of invention
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #30  
Old 07-30-2007, 02:20 AM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 301
Karpagarajan is on a distinguished road
Default Re: VC++ Tips & Tricks

Hi...

Today's tips

1. You must initialize references and non-static const members in the member-initialization list of constructor

2. To get some new powerful and useful source editor commands, click Macros on the Tools menu and load the sample macrofile

bye
......
thanks
__________________
Karpagarajan. R
Necessity is the mother of invention
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
C# .Net Tips & Tricks oxygen C# Programming 85 01-08-2009 12:25 AM
SAP Tips & Tricks leoraja8 Operating Systems 0 03-29-2008 12:11 AM
Visual Studio Tips & Tricks SaravananJ C# Programming 197 12-20-2007 03:25 AM
PHP Tips and Tricks Sabari PHP Programming 20 12-18-2007 05:26 AM
.NET tricks & Tips Karpagarajan VB.NET Programming 1 04-23-2007 08:17 AM


All times are GMT -7. The time now is 06:51 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0