Sunday, October 25, 2009

retrieve the horizontal resolution for a video display, or printer

Device-Independent Bitmaps
A device-independent bitmap (DIB) contains a color table. A color table describes how pixel values correspond to RGB color values, which describe colors that are produced by emitting light. Thus, a DIB can achieve the proper color scheme on any device. A DIB contains the following color and dimension information:
  • The color format of the device on which the rectangular image was created.
  • The resolution of the device on which the rectangular image was created.
  • The palette for the device on which the image was created.
  • An array of bits that maps red, green, blue (RGB) triplets to pixels in the rectangular image.
  • A data-compression identifier that indicates the data compression scheme (if any) used to reduce the size of the array of bits.
The color and dimension information is stored in a BITMAPINFO structure, which consists of a BITMAPINFOHEADER structure followed by two or more RGBQUAD structures. The BITMAPINFOHEADER structure specifies the dimensions of the pixel rectangle, describes the device's color technology, and identifies the compression schemes used to reduce the size of the bitmap. The RGBQUAD structures identify the colors that appear in the pixel rectangle.
There are two varieties of DIBs:
  • A bottom-up DIB, in which the origin lies at the lower-left corner.
  • A top-down DIB, in which the origin lies at the upper-left corner.
If the height of a DIB, as indicated by the Height member of the bitmap information header structure, is a positive value, it is a bottom-up DIB; if the height is a negative value, it is a top-down DIB. Top-down DIBs cannot be compressed.
The color format is specified in terms of a count of color planes and color bits. The count of color planes is always 1; the count of color bits is 1 for monochrome bitmaps, 4 for VGA bitmaps, and 8, 16, 24, or 32 for bitmaps on other color devices. An application retrieves the number of color bits that a particular display (or printer) uses by calling the GetDeviceCaps function, specifying BITSPIXEL as the second argument.
The resolution of a display device is specified in pixels-per-meter. An application can retrieve the horizontal resolution for a video display, or printer, by following this three-step process.
  1. Call the GetDeviceCaps function, specifying HORZRES as the second argument.
  2. Call GetDeviceCaps a second time, specifying HORZSIZE as the second argument.
  3. Divide the first return value by the second return value.
The application can retrieve the vertical resolution by using the same three-step process with different parameters: VERTRES in place of HORZRES, and VERTSIZE in place of HORZSIZE.
The palette is represented by an array of RGBQUAD structures that specify the red, green, and blue intensity components for each color in a display device's color palette. Each color index in the palette array maps to a specific pixel in the rectangular region associated with the bitmap. The size of this array, in bits, is equivalent to the width of the rectangle, in pixels, multiplied by the height of the rectangle, in pixels, multiplied by the count of color bits for the device. An application can retrieve the size of the device's palette by calling the GetDeviceCaps function, specifying NUMCOLORS as the second argument.
Windows supports the compression of the palette array for 8-bpp and 4-bpp bottom-up DIBs. These arrays can be compressed by using the run-length encoding (RLE) scheme. The RLE scheme uses 2-byte values, the first byte specifying the number of consecutive pixels that use a color index and the second byte specifying the index. For more information about bitmap compression, see the description of the BITMAPINFOHEADER, BITMAPFILEHEADER, BITMAPV4HEADER, and BITMAPV5HEADER structures.
An application can create a DIB from a DDB by initializing the required structures and calling the GetDIBits function. To determine whether a device supports this function, call the GetDeviceCaps function, specifying RC_DI_BITMAP as the RASTERCAPS flag.
An application that needs to copy a bitmap can use TransparentBlt to copy all pixels in a source bitmap to a destination bitmap except those pixels that match the transparent color.
An application can use a DIB to set pixels on the display device by calling the SetDIBitsToDevice or the StretchDIBits function. To determine whether a device supports the SetDIBitsToDevice function, call the GetDeviceCaps function, specifying RC_DIBTODEV as the RASTERCAPS flag. Specify RC_STRETCHDIB as the RASTERCAPS flag to determine if the device supports StretchDIBits.
An application that simply needs to display a pre-existing DIB can use the SetDIBitsToDevice function. For example, a spreadsheet application can open existing charts and display them in a window by using the SetDIBitsToDevice function. To repeatedly redraw a bitmap in a window, however, the application should use the BitBlt function. For example, a multimedia application that combines animated graphics with sound would benefit from calling the BitBlt function because it executes faster than SetDIBitsToDevice.

Wednesday, October 21, 2009

How to make auto line break in HTML table td element

CSS can imperfectly solved this issue asa below

.table
{
    table-layout: fixed;
}
.td
{
    word-break: break-all;
    word-wrap:break-word;
}

Friday, October 9, 2009

How to pass parameters to UserControl

  1. Define a constructor method in your UserControl class
    public partial class MyUserControl : System.Web.UI.UserControl
    {
        public MyUserControl()
        {
        }
        public MyUserControl(string param1, int param2, bool param3)
        {
            // Do anything you whant for your parameters here
            textbox1.Text = param1;
            .....

        }
    }
  2. Define our customize LoadControl() method so that the parameters can be pass into the UserControl
    private UserControl LoadUserControl(string controlPath, params object[] parameters)
    {
        List<Type> paramTypes = new List<Type>();
        foreach(object param in parameters)
        {
            paramTypes.Add(param.GetType());
        }
        Page page = new Page();
        UserControl uc = page.LoadControl(controlPath) as UserControl;
        ConstructorInfo ci = uc.GetType().BaseType.GetConstructor(paramTypes.ToArray());
        if(ci == null)
        {
            throw new MemberAccessException(
                "The requested constructor was not found on : "
               
    + uc.GetType().BaseType.ToString());
        }
        else
        {
            ci.Invoke(uc, parameters);
        }
        return uc;
    }
  3. Now you can use the LoadControl as below to pass the parameters to the UserControl
    // Initiallize the UserControl with it parameters .....UserControl myControl = LoadControl(
                                        "MyUserControl.ascx"
                                      , "This is value of param1"
                                      ,  1234, true);
 
 
 
 
 

Friday, September 25, 2009

身份證字號說明

身份證字號 共有十碼, 以下是位置說明,僅供各位參考

N1 N2 N3 N4 N5 N6 N7 N8 N9 N10
戶籍 性別 ~流~~~~~~~~水~~~~~~~~~~~碼~

代表說明

戶籍代表字母
A台北市 B台中市 C基隆市 D台南市 E高雄市 F台北縣
G宜蘭縣 H桃園縣 I嘉義市 J新竹縣 K苗栗縣 L台中縣
M南投縣 N彰化縣 O新竹市 P雲林縣 Q嘉義縣 R台南縣
S高雄縣 T屏東縣 U花蓮縣 V台東縣 W金門縣 X澎湖縣
Y陽明山 Z連江縣

英文字母代表的數字
A=10 B=11 C=12 D=13 E=14 F=15 G=16 H=17 I=34 J=18 K=19 L=20
M=21 N=22 O=35 P=23 Q=24 R=25 S=26 T=27 U=28 V=29 W=32 X=30
Y=31 Z=33

性別代表數字
1:男性
2:女性

步驟

1. 查出英文字所代表的數字

再將所查出的數字 "十位數+個位數x9"
例: 台北市=10
1 + 0x9 =1
台中市=11
1 + 1x9 =10

2. N2x8+N3x7+N4x6+N5x5+N6x4+N7x3+N8x2+N9+N10

將流水碼依序乘8765432
一個個乘.乘完要加起來. (別忘了先乘除後加減)
例: 123456789
1x8+2x7+3x6+4x5+5x4+6x3+7x2+8+9


3.將步驟1 和步驟2 的兩個數加起來除以10.

例:步驟1 台北計算結果 =1
步驟2 1x8+2x7+3x6+4x5+5x4+6x3+7x2+8+9 =129 (1+129)/10

除10後看看是否可以整除.如可以整除即為正確的
身份證字號. 如無法整除即是錯誤的身份證字號

(1+129)/10 = 13 => 可以整除.正確

Wednesday, September 16, 2009

Clear Drop Down List of Recent Connection From SQL Server Management Studio


SQL Server Management Studio 2017 delete the file C:\Users\%username%\AppData\Roaming\Microsoft\SQL Server Management Studio\14.0\SqlStudio.bin
SQL Server Management Studio 2016 delete the file C:\Users\%username%\AppData\Roaming\Microsoft\SQL Server Management Studio\13.0\SqlStudio.bin
SQL Server Management Studio 2014 delete the file C:\Users\%username%\AppData\Roaming\Microsoft\SQL Server Management Studio\12.0\SqlStudio.bin
SQL Server Management Studio 2012 delete the file C:\Users\%username%\AppData\Roaming\Microsoft\SQL Server Management Studio\11.0\SqlStudio.bin
SQL Server Management Studio 2008 delete the fileC:\Users\%username%\AppData\Roaming\Microsoft\Microsoft SQL Server\100\Tools\Shell\SqlStudio.bin
SQL Server Management Studio 2005 delete the file – same as above answer but the Vista path. C:\Users\%username%\AppData\Roaming\Microsoft\Microsoft SQL Server\90\Tools\Shell\mru.dat


In fact there's a way to delete all the history info in the dialog fields.
For SQL Server 2005:
C:\Documents and Settings\<user>\Application Data\Microsoft\Microsoft SQL Server\90\Tools\Shell\mru.dat
If you can not find mru.dat at above location look for mru.dat in following folder.
C:\Documents and Settings\[user]\Application Data\Microsoft\Microsoft SQL Server\90\Tools\ShellSEM\mru.dat
For SQL Server 2008:
C:\Documents and Settings\<user>\Application Data\Microsoft\Microsoft SQL Server\100\Tools\Shell\SqlStudio.bin
If you can not find mru.dat at above location look for mru.dat in following folder.
C:\Documents and Settings\[user]\Application Data\Microsoft\Microsoft SQL Server\100\Tools\ShellSEM\mru.dat
If you are using VISTA OS instead of XP OS. Replace C:\Documents and Settings\[user]\Application Data\Microsoft\ with
C:\Users\\AppData\Roaming\Microsoft\ and it should work.
Make sure to take note down any IP address of SQL Server you may need in future.
Reference : Pinal Dave (http://www.SQLAuthority.com)

Saturday, September 5, 2009

How to reset MS SQL Server IDENTITY

If the table is new create you can use this to reset the identity
DBCC CHECKIDENT (yourtable, reseed, seed_value)

If you delete that data in the table u can use
DBCC CHECKIDENT (yourtable, reseed, 0)

Thursday, August 27, 2009

How to Install/UnInstall COM Componets

If the COM file is a executive .exe file.Excute the file with a argument as below:
 -Service            // Install .exe COM file as a windows service.
 -UnregServer    // Uninstall .exe COM componet.
 -RegServer       // Install .exe COM file as a windows COM componet.


If the COM file is a DLL file, suppose the file name is mycom.dll.
regsvr32 mycom.dll              // To install dll COM
regsvr32 /u mycom.dll          // Run regsvr32 with argument /u to uninstall the dll COM

dcomcnfg    // This tool can see the all DCOM componets has installed in the system.


The Installutil.exe is a tool for .NET componets registration
Here some argument options
Option Description
/h[elp] Displays command syntax and options for the tool.
/help assemblypath Displays any additional options recognized by individual installers within the specified assembly.
/logFile=[filename] Specifies the name of the log file where install progress is recorded. The default is assemblyname.InstallLog.
/logToConsole={true|false} If true, displays output to the console. If false (the default), suppresses output to the console.
/showCallStack Prints the call stack to the log if an exception occurs at any point during installation.
/u[ninstall] Uninstalls an assembly. Unlike other options, /u applies to all assemblies regardless of where it appears on the command line.
/? assemblypath Displays any additional options recognized by individual installers within the specified assembly.
/? Displays command syntax and options for the tool.

The SC.exe is a Windows SDK tool
The SC.exe can be used to Query, Install, Uninstall and Setting Windows Service and Windows Hardware Drivers.

How to use it go ask google!