Showing posts with label Microsoft Technologies. Show all posts
Showing posts with label Microsoft Technologies. Show all posts

Sunday, September 7, 2008

Working with GDI+

 

About GDI+
GDI+ is the portion of the Windows XP operating system that provides two-dimensional vector graphics, imaging, and typography. GDI+ improves on GDI (the Graphics Device Interface included with earlier versions of Windows) by adding new features and by optimizing existing features. It is required as a redistributable for applications that run on the Microsoft Windows NT 4.0 SP6, Windows 2000, Windows 98, and Windows Millennium Edition (Windows Me) operating systems. GDI+ requires GdiPlus.dll
What's New In GDI+?
Microsoft Windows GDI+ is different from Windows Graphics Device Interface (GDI) in a couple of ways. First, GDI+ expands on the features of GDI by providing new capabilities, such as gradient brushes and alpha blending. Second, the programming model has been revised to make graphics programming easier and more flexible.
I) Using GDI+ in MFC applications ( unmanaged VC++).
// What to include for GDI+? Header files and libraries;
#include <gdiplus.h>                      // Base include
using namespace Gdiplus;                  // The "name space"
#pragma comment(lib, "gdiplus.lib")       // The GDI+ binary
If you want to initialize GDI+ for your application (by calling GdiplusStartup in your InitInstance function), you will need to suppress the GDI+ background thread. Good place to call GdiplusStartup and the hook notification functions would be in an override of the virtual function CWinApp::Run, as shown below:

int CTestApp::Run()
{
      GdiplusStartupInput gdiSI;
      GdiplusStartupOutput gdiSO;
      ULONG_PTR gdiToken;
      ULONG_PTR gdiHookToken;
      gdiSI.SuppressBackgroundThread = TRUE;
      GdiplusStartup(&gdiToken,&gdiSI,&gdiSO);
      gdiSO.NotificationHook(&gdiHookToken);

      int nRet = CWinApp::Run();

      gdiSO.NotificationUnhook(gdiHookToken);
      GdiplusShutdown(gdiToken);
      return nRet;
}
For drawing any shape/image use Graphics class.
SDI Example :
// CView's OnDraw
void CGDIPTestView::OnDraw(CDC* pDC)
{
      Graphics graphics( pDC->GetSafeHdc());
      Pen pen(Color(20,255,0,0), 4.0f);
      graphics.DrawLine( &pen, Point(0,0), Point(100,100));
}
II) Using GDI+ in managed.
The GDI+ managed class interface (a set of wrappers) is part of the .NET Framework, an environment for building, deploying, and running XML Web services and other applications.
The System.Drawing namespace provides access to GDI+ basic graphics functionality.

C# code example:
//Paint event handler
private void Form1_Paint(object sender, PaintEventArgs e)
{
    // Create pen.
    Pen blackPen = new Pen(Color.Black, 4.0f);
    // Draw line to screen.
    e.Graphics.DrawLine(blackPen, new Point(0, 0), new Point(100, 100));
}

 

8/September/2008

 

 

 

Monday, July 7, 2008

Creating / Editing Icon using Visual Studio

Today Vivek created a C# windows application and he created a new ICON using visual studio. He applied same icon to the Form ,but after running the application we can’t see any change. I tried different scenario ,but no chance. So I decided to study about Icon format.

Icon Format

The ICO file format is an image file format used for icons in Microsoft Windows. The icon files can contain more than one image with multiple sizes and colour depths. This is why it's so use full in some situations. When Windows shows the file list it checks the viewing settings and then determines which images to extract from the files' icons. When, for instance, a user looks at a file list with small icons, Windows extracts the images with the dimension 16x16 pixels from the icons. Also if Windows can show only 256 colors (8 bpp) it searches for images with 256 colors. However, if Windows can't find the appropriate image it chooses the closest one that fits the description.

Creating / Editing Icon using Visual Studio

As early told editing an Icon means edit all Images inside the icon. In Image Menu we can select Current Icon image type, delete the current image type, and also we can insert new image type. After selecting current image type we can start editing . In VS2008 provides good UI for Editing Icons. There is an additional option for selecting image type , which is not in early versions of VS.

Following Figure shows different New Image Type dialog boxes.


Visual C++ 2008 Feature Pack Released : MFC 9.0.30411

Overview
The Visual C++ 2008 Feature Pack extends the VC++ Libraries shipped with Visual Studio 2008 and is fully covered under Microsoft's standard support policies. The MFC application wizard has also been upgraded to support the new features - including a check-box to select whether the application will use the Ribbon or the Visual Studio 2005 user interface elements.

Feature pack is available for download at http://www.microsoft.com/downloads/details.aspx?FamilyId=D466226B-8DAB-445F-A7B4-448B326C48E7&displaylang=en.]

I) The MFC Feature Pack library supports new features in the following areas:

· Office Ribbon style interface

· Office 2007, Office 2003 and Office XP look and feel

· Modern Visual Studio-style docking toolbars and panes

· Fully customizable toolbars and menus

· A rich set of advanced GUI controls

· Advanced MDI tabs and groups

· And much more! Click http://msdn.microsoft.com/en-us/library/bb984556.aspx

II) This feature pack also includes an implementation of TR1*.

· Smart pointers

· Regular expression parsing

· New containers (tuple, array, unordered set, etc)

· Sophisticated random number generators

· Polymorphic function wrappers

· Type traits

· And more click http://msdn2.microsoft.com/en-us/library/bb982198.aspx


Office Fluent UI
The new UI, including the Office Fluent Ribbon, provides improved context menus, enhanced screen tips, a Mini toolbar, and keyboard shortcuts that help to improve user efficiency and productivity. The new Office Fluent UI is implemented in several applications in the 2007 Microsoft Office suite, including Access, Excel, Outlook, PowerPoint, and Word.


Office Fluent UI Licensing:
The Ribbon functionality and MS Office 2007 Visual Styles included in this Feature Pack are subject to the license. These include a requirement to adhere to Microsoft UI Design Guidelines, and a prohibition against using such a UI in applications which compete with Microsoft applications.


The license is provided at no cost. It is a royalty-free license. License terms to copy, use or distribute the Fluent UI are available separately

More about UI Design Guidelines and Licensing : http://SenAPI.4shared.com/

*Technical Report 1 (TR1) is a draft document specifying additions to the C++ Standard Library such as regular expressions, smart pointers, hash tables, and random number generators. TR1 is not yet standardized, but likely will be part of the next official standard mostly as it stands now. Much of it is available in Boost.

Wednesday, July 2, 2008

How to Show a wait cursor - VC++, C#

When my project mate(Omar) asked me about wait curser ( for search process ),  I suddenly started implementing using LoadCursor and SetCursor.

In main frame I loaded wait curser.
HCURSOR m_hWaitCursor = ::LoadCursor(NULL,IDC_WAIT);

after this added a message map for WM_SETCURSOR in the main frame ,

BOOL CMainFrame::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
      if( NULL != m_hWaitCursor && true == m_bShowWaitCursor)
      {
            m_hPreviousCursor = ::SetCursor(m_hWaitCursor);
            return TRUE;
      }
      else
      {
            return CDialog::OnSetCursor(pWnd, nHitTest, message);
      }
}

Finally I felt very hard to manage this, and thought about to build a custom singleton class which can be called from anywhere. After a short time Omar got some information about CWaintCursor, and I stopped writing custom class.

I got following information from MSDN:
Good Windows programming practices require that you display a wait cursor whenever you're performing an operation that takes a noticeable amount of time.

Method1:Using CWaitCursor class

Provides a one-line way to show a wait cursor, which is usually displayed as an hourglass, while you're doing a lengthy operation.


When the object goes out of scope (at the end of the block in which the CWaitCursor object is declared), its destructor sets the cursor to the previous cursor. In other words, the object performs the necessary clean-up automatically.

void SomeLengthyProcess()
{
      CWaitCursor wait;
      //Do the lengthProcessing.
      Sleep(1000);

      AfxMessageBox(_T("Some result"));      //This changes the cursor.
      wait.Restore();                                    //Restore the Wait cursor.
      //Continue lengthProcessing.
      Sleep(1000);
      //The destructor changes the cursor back to Regular cursor.
}

Method2: Using CCmdTarget class

void CwaitTestDlg::SomeLengthyProcess()
{
      CCmdTarget::BeginWaitCursor(); // display the hourglass cursor
      Sleep(1000);
      CCmdTarget::RestoreWaitCursor();
      CCmdTarget::EndWaitCursor(); // remove the hourglass cursor
}

Method3: Using CWinApp::DoWaitCursor

virtual void DoWaitCursor(   int nCode );
void SomeLengthyProcess()
{
   AfxGetApp()->DoWaitCursor(1); // display the hourglass cursor
   // do some lengthy processing
   Sleep(1000);
   // The message box will normally change the cursor to
   // the standard arrow cursor, and leave the cursor in
   // as the standard arrow cursor when the message box is
   // closed.
   AfxMessageBox(_T("DoWaitCursor Sample"));
   // Call DoWaitCursor with parameter 0 to restore
   // the cursor back to the hourglass cursor.
   AfxGetApp()->DoWaitCursor(0);
   // do some more lengthy processing
   Sleep(1000);
   AfxGetApp()->DoWaitCursor(-1); // remove the hourglass cursor
}

Show a wait cursor in C#

Example1: Using  UseWaitCursor property in the System.Windows.Forms.Control class
//method in Form derived class.

private void SomeLengthyProcess()//not working.
{
   this.UseWaitCursor = true;
   System.Threading.Thread.Sleep(1000);//Alternative for Sleep() in VC++
   this.UseWaitCursor = false;
}


But the above code is not working. So I started searching and found another method.

Example2: Using  Cursor property in the System.Windows.Forms.Control class
private void SomeLengthyProcess()//working.
{
    Cursor currentCursor = this.Cursor;
    this.Cursor = Cursors.WaitCursor;
    System.Threading.Thread.Sleep(1000);
    this.Cursor = currentCursor;
}
Example3: Using  UseWaitCursor property in the System.Windows.Forms.Application class
private void SomeLengthyProcess()//not working.
{
     Application.UseWaitCursor = true;
     System.Threading.Thread.Sleep(1000);
     Application.UseWaitCursor = false;
}

 

 

Sunday, March 9, 2008

How to create Auto Increment column in SQL Server.


In Access and MySQL there is Auto increment data type, but in MS SQL Server there is no Auto increment data type.But we can set assign a column like Auto increment,
Example:
CREATE TABLE MyTable
(
User_ID bigint IDENTITY(1,1)PRIMARY KEY CLUSTERED,
UserName varchar(50) NOT NULL DEFAULT
)
IDENTITY(Identity Seed, Identity Increment)

The Identity Seed is the value of the first entry in the table. The Identity Increment is the value that will be added to the previous row to get the next identity value.

If you are using designer tool like SQL Server Enterprise manager or Visual studio 2005 then you should change Identity Property to YES [by default it is NO]. Check the Identity checkbox and the Identity Seed and Identity Increment will be set to 1 automatically.



“Without knowing this property we are forced to calculate the next primary value by using max or any other technique.”

Problem with auto increment.

· we have no idea about what is the next ID.

· Auto Increment value never reset to 1 ,after deleting all rows from a table.[ but we can reset]

Resetting current identity value
DBCC CHECKIDENT ('TableName', RESEED,0)

DBCC CHECKIDENT
( 'table_name'
[ , { NORESEED
{ RESEED [ , new_reseed_value ] }
}

]
)

Arguments

'table_name'

Is the name of the table for which to check the current identity value. Table names must conform to the rules for identifiers. For more information, see Using Identifiers. The table specified must contain an identity column.

NORESEED

Specifies that the current identity value should not be corrected.

RESEED

Specifies that the current identity value should be corrected.

new_reseed_value

Is the value to use in reseeding the identity column.

Inserting Explicit Values into an Identity Column
If you want to insert a value into an identity column you can use the SET IDENTITY_INSERT statement.
SET IDENTITY_INSERT
MyTable ON
INSERT INTO dbo.
MyTable (User_ID , UserName) Values(1, 'Sen SD')
SET IDENTITY_INSERT Yaks OFF

You can only turn on IDENTITY_INSERT for one table per session so it's always a good idea to turn it off when you're done with it

10/March/2008

Thursday, December 20, 2007

Handling Errors and Messages in Applications SQL

MS SQL

The Database Engine can return information to the caller in one of two ways:
1) Errors
The errors from sys.messages with a severity of 11 or higher.
Any RAISERROR statement with a severity of 11 or higher.
2) Messages
The output of the PRINT statement.
The output of several DBCC statements.
The errors from sys.messages with a severity of 10 or lower.
Any RAISERROR statement with a severity of 10 or lower.

SqlClient Error Handling

The SqlClient managed provider throws an SqlException exception when an unhandled error is raised by the SQL Server Database Engine. Through the SqlException class, applications can retrieve information about errors produced on the server side, including error number, error message, error severity, and other exception context information.

For processing warnings or informational messages sent by the SQL Server Database Engine, applications can create a SqlInfoMessageEventHandler delegate to listen for the InfoMessage event on the SqlConnection class. Similar to the exception case, message context information such as severity and state are passed as arguments to the callback.

Raising Error message – stored procedure Example

ALTER PROCEDURE dbo.SenTest
      (
      @unserId int,
      @returnValue varchar OUTPUT
      )
AS    /* SET NOCOUNT ON */
      RAISERROR (N'This is message %s %d.', -- Message text.
          11, -- Severity Levels 11 through 16
             ---These messages indicate errors that can be corrected by the user.
           1, -- State,
           N'number', -- First argument.
           5); -- Second argument.

      RETURN 0

 

Monday, November 19, 2007

Register ActiveX Files Using the Mouse ..reg

Register ActiveX Files Using the Mouse .reg

Do you find yourself constantly registering and unregistering ActiveX .exe, .dll, .ocx, or .olb files? This script allows you to do so with just a mouse click. Here's how to use it:

Open Notepad. Paste the following code into Notepad:

REGEDIT4

 

[HKEY_CLASSES_ROOT\.exe]

@="exefile"

 

[HKEY_CLASSES_ROOT\.dll]

@="dllfile"

 

[HKEY_CLASSES_ROOT\.ocx]

@="ocxfile"

 

[HKEY_CLASSES_ROOT\.olb]

@="olbfile"

 

[HKEY_CLASSES_ROOT\exefile\shell\Register\command]

@="%1 /register"

 

[HKEY_CLASSES_ROOT\dllfile\shell\Register\command]

@="regsvr32.exe %1"

 

[HKEY_CLASSES_ROOT\ocxfile\shell\Register\command]

@="regsvr32.exe %1"

 

[HKEY_CLASSES_ROOT\olbfile\shell\Register\command]

@="regsvr32.exe %1"

 

[HKEY_CLASSES_ROOT\dllfile\shell\Silent Register\command]

@="regsvr32.exe /s %1"

 

[HKEY_CLASSES_ROOT\ocxfile\shell\Silent Register\command]

@="regsvr32.exe /s %1"

 

[HKEY_CLASSES_ROOT\olbfile\shell\Silent Register\command]

@="regsvr32.exe /s %1"

 

[HKEY_CLASSES_ROOT\exefile\shell\UnRegister\command]

@="%1 /unregister"

 

[HKEY_CLASSES_ROOT\dllfile\shell\UnRegister\command]

@="regsvr32.exe /u %1"

 

[HKEY_CLASSES_ROOT\ocxfile\shell\UnRegister\command]

@="regsvr32.exe /u %1"

 

[HKEY_CLASSES_ROOT\olbfile\shell\UnRegister\command]

@="regsvr32.exe /u %1"

 

[HKEY_CLASSES_ROOT\dllfile\shell\Silent UnRegister\command]

@="regsvr32.exe /u /s %1"

 

[HKEY_CLASSES_ROOT\ocxfile\shell\Silent UnRegister\command]

@="regsvr32.exe /u /s %1"

 

[HKEY_CLASSES_ROOT\olbfile\shell\Silent UnRegister\command]

@="regsvr32.exe /u /s %1"

Save the file as register.reg.

Right click on register.reg and select Merge from the context menu. Alternatively, you can run regedit and import the file

After merging the script, you should be able to right click on any .exe, .dll, .ocx, or .olb file and see a list of register and unregister options.

Note: Make sure that regsvr32.exe is in your path or the menu commands will fail.

Sen Paravur

 

Wednesday, November 7, 2007

Why we can't create con folder?

Why we can’t create con folder?
we cant create a folder(or file) named CON, PRN, AUX, CLOCK$, NUL, COM1, COM2, COM3, COM4,
 COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, LPT9.

"CON" is for "CONSOLE", which is... the keyboard.

Example: Command using CON

The following COPY command copies what you type at the keyboard to the OUTPUT.TXT file:
 copy con output.txt

After you type this command and press ENTER, MS-DOS copies everything you type to the file OUTPUT.TXT. When you are finished typing, press CTRL+Z to indicate that you want to end the file. The CTRL+Z character will appear on the screen as "Z". You can also end a COPY CON command by pressing the F6 key. When you press F6, it generates the CTRL+Z character, which appears on the screen as Z.
The following example copies information from the keyboard to the printer connected to LPT1:

 copy con lpt1

 

How to create a folder named CON ?

command prompt type mkdir \\.\c:\con will create a folder CON in c:\
See how this works???now try to delete it!!
The reason this is possible is down to UNC naming conventions..by adding the \\ in the statement it makes windows ignore the old DOS command to reserve this folder name.
md \\.\c:\XXX\CON will create a Folder  c:\XXX\ CON

 

Wednesday, October 31, 2007

Path Combine Fucction C# and VC++

Path.Combine Function C#

public static string Combine ( string path1, string path2 )

A string containing the combined paths. If one of the specified paths is a zero-length string, this method returns the other path. If path2 contains an absolute path, this method returns path2.
System.IO Namespace

PathCombine Function VC++

LPTSTR PathCombine(  LPTSTR lpszDest  LPCTSTR lpszDir, LPCTSTR lpszFile );

Returns a pointer to a string with the concatenated path if successful, or NULL otherwise.
Header shlwapi.h

 

 

Monday, October 22, 2007

How to disable WebDAV for IIS 5.0





1.Start Registry Editor (Regedt32.exe).
2.Locate and click the following key in the registry:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters
3.On the Edit menu, click Add Value, and then add the following registry value:
Value name: DisableWebDAVData type: DWORDValue data: 1
4.Restart IIS. This change does not take effect until the IIS service or the server is restarted.

IIS 5.0 User Interface Bug

We can't add new Extension ,
on add ..
we should change the cul position to first textbox(browse) then the ok button will be active and we can now click OK.

Sunday, October 21, 2007

IIS 7 and ASP.NET

ASP.NET and IIS 7.0 Integration

IIS 7.0 is one of the products that my team is shipping later this year that I'm most excited about. It is the most significant release of our web-server that we've done since IIS 1.0, and introduces a huge number of improvements for both administrators and developers.

In previous versions of IIS, developers had to write ISAPI extensions/filters to extend the server. In addition to being a royal pain to write, ISAPIs were also limited in how they plugged into the server and in what they allowed developers to customize. For example, you can't implement URL Rewriting code within an ISAPI Extension (note: ASP.NET is implemented as an ISAPI extension). And you end up tying up the I/O threads of the web-server if you write long-running code as an ISAPI Filter (which is why we didn't enable managed code to run in the filter execution phase of a request).
One of the major architectural changes we made to the core IIS processing engine with IIS7 was to enable much, much richer extensibility via a new modular request pipeline architecture. You can now write code anywhere within the lifetime of any HTTP request by registering an HTTP Extensibility Module with the web-server. These extensibility modules can be written using either native C++ code or .NET managed code (you can use the existing ASP.NET System.Web.IHttpModule interface to implement this).
All "built-in" IIS7 functionality (authentication, authorization, static file serving, directory listing support, classic ASP, logging, etc) is now implemented using this public modular pipeline API. This means you can optionally remove any of these IIS7 "built-in" features and replace/extend them with your own implementation.
ASP.NET on IIS 7.0 has itself been changed from being implemented as an ISAPI to instead plug in directly as modules within the IIS7 pipeline:

for more information : http://msdn.microsoft.com/msdnmag/issues/07/03/IIS7/