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; Aligning Text... The following example draws text in a rectangle. Each line of text is centered (side to side), and ...


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
  #41  
Old 07-30-2007, 06:49 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

Aligning Text...

The following example draws text in a rectangle. Each line of text is centered (side to side), and the entire block of text is centered (top to bottom) in the rectangle.
WCHAR string[] = L"Use StringFormat and RectF objects to center text in a rectangle.";

FontFamily fontFamily(L"Arial");
Font font(&fontFamily, 12, FontStyleBold, UnitPoint);
RectF rectF(30.0f, 10.0f, 120.0f, 140.0f);
StringFormat stringFormat;
SolidBrush solidBrush(Color(255, 0, 0, 255));

// Center-justify each line of text.
stringFormat.SetAlignment(StringAlignmentCenter);

// Center the block of text (top to bottom) in the rectangle.
stringFormat.SetLineAlignment(StringAlignmentCente r);

graphics.DrawString(string, -1, &font, rectF, &stringFormat, &solidBrush);

Pen pen(Color(255, 0, 0, 0));
graphics.DrawRectangle(&pen, rectF);
bye
thanks...
__________________
Karpagarajan. R
Necessity is the mother of invention
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #42  
Old 07-30-2007, 06:55 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

creating directory with user access persmission

Hi friends,

here I have given the code for creating directory with user access persmission. Very useful one. This code I got from Platform SDK -> Security section.
#define _WIN32_WINNT 0x0500

#include <windows.h>
#include <sddl.h>
#include <stdio.h>

BOOL CreateMyDACL(SECURITY_ATTRIBUTES *);

void main()
{
SECURITY_ATTRIBUTES sa;

sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = FALSE;

// Call function to set the DACL. The DACL
// is set in the SECURITY_ATTRIBUTES
// lpSecurityDescriptor member.
if (!CreateMyDACL(&sa))
{
// Error encountered; generate message and exit.
printf("Failed CreateMyDACL\n");
exit(1);
}

// Use the updated SECURITY_ATTRIBUTES to specify
// security attributes for securable objects.
// This example uses security attributes during
// creation of a new directory.
if (0 == CreateDirectory(TEXT("D:\\Karpagarajan"), &sa))
{
// Error encountered; generate message and exit.
printf("Failed CreateDirectory\n");
exit(1);
}

// Free the memory allocated for the SECURITY_DESCRIPTOR.
if (NULL != LocalFree(sa.lpSecurityDescriptor))
{
// Error encountered; generate message and exit.
printf("Failed LocalFree\n");
exit(1);
}
}


// CreateMyDACL.
// Create a security descriptor that contains the DACL you want.
// This function uses SDDL to make Deny and Allow ACEs.
//
// Parameter:
// SECURITY_ATTRIBUTES * pSA
// Pointer to a SECURITY_ATTRIBUTES structure. It is the caller's
// responsibility to properly initialize the structure and to free
// the structure's lpSecurityDescriptor member when the caller has
// finished using it. To free the structure's lpSecurityDescriptor
// member, call the LocalFree function.
//
// Return value:
// FALSE if the address to the structure is NULL.
// Otherwise, this function returns the value from the
// ConvertStringSecurityDescriptorToSecurityDescripto r function.
BOOL CreateMyDACL(SECURITY_ATTRIBUTES * pSA)
{
// Define the SDDL for the DACL. This example sets
// the following access:
// Built-in guests are denied all access.
// Anonymous logon is denied all access.
// Authenticated users are allowed read/write/execute access.
// Administrators are allowed full control.
// Modify these values as needed to generate the proper
// DACL for your application.
TCHAR * szSD = TEXT("D:") // Discretionary ACL
TEXT("(D;OICI;GA;;;BG)") // Deny access to built-in guests
TEXT("(D;OICI;GA;;;AN)") // Deny access to anonymous logon
TEXT("(D;OICI;GRGWGX;;;BG)") // Allow read/write/execute to authenticated users
TEXT("(A;OICI;GRGWGX;;;BA)") // Allow read/write/execute to authenticated users
TEXT("(A;OICI;GA;;;BA)"); // Allow full control to administrators

if (NULL == pSA)
return FALSE;

return ConvertStringSecurityDescriptorToSecurityDescripto r(
szSD,
SDDL_REVISION_1,
&(pSA->lpSecurityDescriptor),
NULL);
}
bye
thanks
__________________
Karpagarajan. R
Necessity is the mother of invention
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #43  
Old 07-30-2007, 07:39 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

WM_MESSAGE => KILL_FOCUS

Hi Buddies,

here I am giving the solution for ActiveX control illegal closing of Internet explorer.

I had found this problem in my activex which was used in web development.
The IE was closed with the Illegal error closing message. When I try to find out the problem in debug mode, I had found that there was stack point in my variable assignment statement in VC++.

The error happens because of the memory variable not been destroyed after the control was destroyed. The memory was not flushed after the activex control unloaded. I just check the flag in activex WM_MESSAGE => KILL_FOCUS.

Hope it may help you in activex coding part.

...........
bye
thanks
__________________
Karpagarajan. R
Necessity is the mother of invention
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #44  
Old 07-30-2007, 07:47 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 buddies,

You can use the following steps to maintain the version in ATL activeX control.
1. Open your Visual C++ ATL project workspace in VC++ IDE
2. Go to resource view
3. In that select version folder
4. In that one node "VS_VERSION_INFO", open it.
5. A grid window will be displayed. In that change the "FILEVERSION" key and "PRODUCTVERSION" key.
by changing these two keys you can maintain your activex control versioning.
..............
bye
thanks
__________________
Karpagarajan. R
Necessity is the mother of invention

Last edited by Booom : 08-09-2007 at 05:44 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #45  
Old 07-30-2007, 09:31 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

ASSERTION

An assertion statement specifies a condition that you expect to hold true at some particular point in your program. If that condition does not hold true, the assertion fails, execution of your program is interrupted, and the Assertion Failed dialog box appears.

MFC and C Run-Time Library Assertions
When the debugger halts because of an MFC or C run-time library assertion, it navigates to the point in the source file where the assertion occurred (if the source is available). The assertion message appears in the Output window as well as the Assertion Failed dialog box. You can copy the assertion message from the Output window to a text window if you want to save it for future reference. The Output window may contain other error messages as well. Examine these messages carefully, because they provide clues to the cause of the assertion failure.

_DEBUG
Assertion statements compile only when _DEBUG is defined. When _DEBUG is not defined, the compiler treats assertions as null statements. Therefore, assertion statements have zero overhead in your final release program; you can use them liberally in your code without affecting the performance of your Release version and without having to use #ifdefs.

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

To enable debugging of a release build, change the following release build options in VC++

1. On the Project menu, choose Settings.
2. Next to Settings for, select the configuration.
3. In the project tree, under Settings for, select a project.
4. Choose the C/C++ tab.
5. In the Category drop-down box, choose General.
6. In the Debug info drop-down box, choose Program Database.
7. In the Optimizations drop-down box, choose Disable (Debug).
8. On the Link tab, select the Generate Debug Info checkbox.

These selections correspond to the /Od and /Zi options, which turn off optimizations and place debug information in the build.

After doing this, rebuild and test your program. If the program works fine, it is still possible that you have a memory overwrite, but it is also possible that the optimizations are causing problems on a particular piece of code.

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

__uuidof Operator

The __uuidof keyword retrieves the GUID attached to the expression.

__uuidof ( expression )
The expression can be a type name, pointer, reference, or array of that type, a template specialized on these types, or a variable of these types. The argument is valid as long as the compiler can use it to find the attached GUID.

A special case of this intrinsic is when either 0 or NULL is supplied as the argument. In this case, __uuidof will return a GUID made up of zeros.

Use this keyword to extract the GUID attached to:

An object by the uuid extended attribute.
A library block created with the module attribute.
The following code (compiled with ole32.lib) will display the uuid of a library block created with the module attribute:
// expre_uuidof.cpp
// compile with: ole32.lib
#include "stdio.h"
#include "windows.h"

[emitidl];
[module(name="joe")];
[export]
struct stuff {
int i;
};

int main() {
LPOLESTR lpolestr;
StringFromCLSID(__uuidof(joe), &lpolestr);
wprintf(L"%s", lpolestr);
CoTaskMemFree(lpolestr);
}
In cases where the library name is no longer in scope, you can use __LIBID_ instead of __uuidof. For example:

StringFromCLSID(__LIBID_, &lpolestr);

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

From CString to char conversion...

Void CStrtoChar()
{
CString str = " test ";
char *p = new char [ str.GetLength () +1 ];
strcpy(p ,str);
delete p;
}

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

Check the image file as JPEG...
Hi buddies,
here is the code to check the given file format is JPEG. Useful one...

Bitmap bm(L"Picture.dat");
GUID guidFileFormat;

bm.GetRawFormat(&guidFileFormat);
if(guidFileFormat == ImageFormatJPEG)
MessageBox(0, " JPEG!", 0, MB_OK);
.............
thanks
__________________
Karpagarajan. R
Necessity is the mother of invention
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #50  
Old 08-02-2007, 04:13 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

Disable mouse wheel scrolling

Dear Visual C++ Friends,

here is the trick
To disable mouse wheel in comboBox (MFC)

Use it in place of your combobox control, capture the mousewheel messages WM_MOUSEWHEEL and then don't forward them to the base class...

..........
thanks
__________________
Karpagarajan. R
Necessity is the mother of invention

Last edited by Booom : 08-09-2007 at 05:45 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 05:12 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