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; How to get the sub menu handle? Here is the tips for getting the Sub menu handle... CMenu *m_lMenu; // A ...


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
  #11  
Old 03-27-2007, 11:04 PM
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

How to get the sub menu handle?

Here is the tips for getting the Sub menu handle...


CMenu *m_lMenu; // A pointer to the menu
CPoint m_pPoint; // A copy of the mouse position
// Copy the mouse position to a local variable
m_pPoint = point;
// Convert the position to a screen position
ClientToScreen(&m_pPoint);
// Get a pointer to the window menu
m_lMenu - GetMenu();
// Get a pointer to the first submenu
m_lMenu = m_lMenu->GetSubMenu(0);
// Show the Popup Menu
m_lMenu->TrackPopupMenu(TPM_CENTERALIGN + TPM_LEFTBUTTON,
m_pPoint.x, m_pPoint.y, this, NULL);

thanks
__________________
Karpagarajan. R
Necessity is the mother of invention
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12  
Old 03-28-2007, 05:01 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

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.

The actual reason for the above problem is...

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

Inorder to create a DLL file u have to some manipulation in the project properties.
i.e open 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"

After setting this in the project properties, the program was compiled successfully.

thanks
__________________
Karpagarajan. R
Necessity is the mother of invention

Last edited by Booom : 08-09-2007 at 05:39 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13  
Old 03-28-2007, 05:05 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, Do you know How to change the cursor in a form?

Here is the simple tips for changing the cursor.

Add the WM_SETCURSOR message handler .
LRESULT OnSetCursor(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{

//HICON hIconBang = LoadCursor(0,MAKEINTRESOURCE(IDC_LEFTC)); // pApp->LoadCursor( IDC_BANG );
HCURSOR h=::AfxGetApp()->LoadCursor(IDC_LEFTC);
::SetCursor( h );
return 0;
}
thanks
__________________
Karpagarajan. R
Necessity is the mother of invention
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14  
Old 03-28-2007, 05:13 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 code is used to convert the mouse pos to the client pos. Useful one.

POINT point;
GetCursorPos(&point);
ScreenToClient(&point);

If you find any tips and tricks, please post your idea here.
__________________
Karpagarajan. R
Necessity is the mother of invention
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15  
Old 03-28-2007, 05:34 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

Compiler Problem

My compiler(VC++ 6) never accepts cin >> str1 if str1 is declared as a string .
the following program gives error.
#include <iostream.h>
#include <string>

using namespace std;

int main() {
string testStr;
cout << "enter string";
cin >> testStr;

return 0;
}


C:\Program Files\Microsoft Visual Studio\MyProjects\Learning\test2\test_loop.cpp(9) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allo
cator<char> >' (or there is no acceptable conversion)
Solutions :

Change "#include <iostream.h>" to "#include <iostream>". Use the newer standard headers such as iostream, string and fstream instead of iostream.h, string.h and fstream.h. Mixing older and new style headers causes compilation problems such as I experienced.


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

Here is one tip:

You can view whitespace (tabs and spaces) in your source files by clicking advanced on the Edit menu and then clicking view Whitespace

thanks
__________________
Karpagarajan. R
Necessity is the mother of invention
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #17  
Old 03-29-2007, 02:01 PM
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,

You can use Visual C++ debugger window in different situation. It is very useful one to trace your code errors.

The Debugger windows support intelligent drag & Drop where the result depends on the drop location. For example, you can add a variable to the Watch Window by dragging it from the variables window or view the memory contents by dragging a variable to the memory window.

thanks
__________________
Karpagarajan. R
Necessity is the mother of invention

Last edited by Booom : 08-09-2007 at 05:40 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #18  
Old 03-29-2007, 02:11 PM
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

About Macros
When creating objects that derive directly or indirectly from CObject, such as CFrameWnd, you should let the compiler know that you want your objects to be dynamically created. To do this, use the DECLARE_DYNCREATE and the IMPLEMENT_DYNCREATE macros. The DECLARE_DYNCREATE macro is provided in the class' header file and takes as argument the name of your class. An example would be DECLARE_DYNCREATE(CTheFrame). Before implementing the class or in its source file, use the IMPLEMENT_DYNCREATE macro, passing it two arguments: the name of your class and the name of the class you derived it from.

We mentioned that, to access the frame, a class derived from CFrameWnd, from the application class, you must use a pointer to the frame's class. On the other hand, if you want to access the application, created using the CWinApp class, from the windows frame, you use the AfxGetApp() global function.

1.How to use the dynamic macros, I have given the sample code here.
#include <afxwin.h>

class CSimpleFrame : public CFrameWnd
{
public:
CSimpleFrame();
DECLARE_DYNCREATE(CSimpleFrame)
};

class CSimpleApplication : public CWinApp
{
public:
BOOL InitInstance();
};

IMPLEMENT_DYNCREATE(CSimpleFrame, CFrameWnd)

CSimpleFrame::CSimpleFrame()
{
// Create the window's frame
Create(NULL, "Windows Application");
}

BOOL CSimpleApplication::InitInstance()
{
// Use a pointer to the window's frame for the application
// to use the window
m_pMainWnd = new CSimpleFrame ();

// Show the window
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();

return TRUE;
}

CSimpleApplication theApp;
thanks
__________________
Karpagarajan. R
Necessity is the mother of invention

Last edited by Karpagarajan : 03-29-2007 at 02:16 PM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #19  
Old 03-29-2007, 02:21 PM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 301
Karpagarajan is on a distinguished road
Default Re: VC++ Tips & Tricks

Marshalling Library and Vista Development with Visual C++

The latest Channel 9 video by the Visual C++ team has just been released. This video features Sarita Bafna, a PM on the libraries team, talking about a few of latest features which are previewed in the March CTP:

MFC support for Vista
IDE support for Vista
Native-Managed Marshalling Library

“MFC support for Vista” includes support for new Vista file dialogs, support for the new controls specifically for Vista and support for additional Windows messages (including some for XP) that had not previously been supported by MFC etc. The IDE Support for Vista includes support for the new controls and high quality graphics in the Resource Editor, support for enabling UAC for VC++ apps etc. The Native-Managed Marshalling Library supports marshalling strings between native-managed code and includes an extensibility model so you add support for your own types. This video includes a demonstration of the VC++ features to support Vista development.

thanks
__________________
Karpagarajan. R
Necessity is the mother of invention

Last edited by Booom : 08-09-2007 at 05:40 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #20  
Old 04-06-2007, 05:02 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

Tips1:
The Compiler options /Yc and /Yu (Create and Use specific procompiled header) provide the most efficient precompiled header management.

Tips2:
By pressing F2 and Shift F2 to go to Next and previous source file Bookmark

thanks
__________________
Karpagarajan. R
Necessity is the mother of invention

Last edited by Karpagarajan : 04-06-2007 at 05:05 AM.
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 01:25 AM
SAP Tips & Tricks leoraja8 Operating Systems 0 03-29-2008 01:11 AM
Visual Studio Tips & Tricks SaravananJ C# Programming 197 12-20-2007 04:25 AM
PHP Tips and Tricks Sabari PHP Programming 20 12-18-2007 06:26 AM
.NET tricks & Tips Karpagarajan VB.NET Programming 1 04-23-2007 09:17 AM


All times are GMT -7. The time now is 10:01 AM.


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