Ace
Ace
org/wiki/Hwnd
Handle (computing)
From Wikipedia, the free encyclopedia
(Redirected from Hwnd)
In computer programming, a handle is an abstract reference to a resource. Handles are used when application software references blocks of memory or objects managed by another system, such as adatabase or an operating system. While a pointer literally contains the address of the item to which it refers, a handle is an abstraction of a reference which is managed externally; its opacity allows the referent to be relocated in memory by the system without invalidating the handle, which is impossible with pointers. The extra layer of indirection also increases the control the managing system has over operations performed on the referent. Typically the handle is an index or a pointer into a global array of tombstones. Handles were a popular solution to memory management in operating systems of the 1980s, such as Mac OS[1] and Windows. Unix file descriptors are essentially handles. Like other desktop environments, the Windows API heavily uses handles to represent objects in the system and to provide a communication pathway between the operating system and user space. For example, a window on the desktop is represented by a handle of type HWND (handle, window). Doubly indirect handles have fallen out of favour in recent times, as increases in available memory and improved virtual memory algorithms have made the use of the simpler pointer more attractive. However, many operating systems still apply the term to pointers to opaque, "private" data structuresopaque pointersor to indexes into internal arrays passed from one process to its client. A handle leak is a type of software bug that occurs when a computer program asks for a handle to a resource but does not free the handle when it is no longer used.
http://www.vbgreatone.8m.com/VB/g/GetModuleHandle.htm
GetModuleHandle Function
Declaration:
Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
Platforms:
Windows: Requires Windows 95 or later. Windows NT: Requires Windows NT 3.1 or later. Windows CE: Unsupported.
Description:
The GetModuleHandle function returns a module handle for the specified module if the file has been mapped into the address space of the calling process. The returned handle is not global, inheritable, or duplicative, and it cannot be used by another process.
Parameters:
lpModuleName Pointer to a null-terminated string that contains the name of the module (either a .DLL or .EXE file). If the filename extension is omitted, the default library extension .DLL is appended. The filename string can include a trailing point character (.) to indicate that the module name has no extension. The string does not have to specify a path. When specifying a path, be sure to use backslashes (\), not forward slashes (/). The name is compared (case independently) to the names of modules currently mapped into the address space of the calling process. If this parameter is NULL, GetModuleHandle returns a handle to the file used to create the calling process.
Return Values:
If the function succeeds, the return value is a handle to the specified module. If the function fails, the return value is NULL. To get extended error information, call GetLastError.
Example:
'Place a command button on the form. Option Explicit Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long Private Declare Function LoadString Lib "user32" Alias "LoadStringA" (ByVal hInstance As Long, ByVal wID As Long, ByVal lpBuffer As String, ByVal nBufferMax As Long) As Long Private Sub Command1_Click() Dim ihInst As Long Dim sUserName As String * 128 Dim sOrganization As String * 128 Dim sTitle As String Dim iLength As Long ihInst = GetModuleHandle("User") iLength = LoadString(ihInst, 514, sUserName, Len(sUserName)) sUserName = Left$(sUserName, iLength) iLength = LoadString(ihInst, 515, sOrganization, Len(sOrganization)) sOrganization = Left$(sOrganization, iLength) Print sUserName Print sOrganization
http://msdn.microsoft.com/enus/library/windows/desktop/ms633577(v=vs.8 5).aspx
WNDCLASSEX structure
45 out of 64 rated this helpful - Rate this topic Contains window class information. It is used with the RegisterClassEx and GetClassInfoEx functions. The WNDCLASSEX structure is similar to the WNDCLASS structure. There are two differences. WNDCLASSEX includes the cbSize member, which specifies the size of the structure, and the hIconSm member, which contains a handle to a small icon associated with the window class. Syntax
C++
typedef struct tagWNDCLASSEX { UINT UINT WNDPROC int int HICON HCURSOR HBRUSH LPCTSTR LPCTSTR HICON cbSize; style; lpfnWndProc; cbClsExtra; cbWndExtra; hIcon; hCursor; hbrBackground; lpszMenuName; lpszClassName; hIconSm;
HINSTANCE hInstance;
} WNDCLASSEX, *PWNDCLASSEX;
Members
cbSize Type: UINT The size, in bytes, of this structure. Set this member to sizeof(WNDCLASSEX). Be sure to set this member before calling the GetClassInfoEx function. style Type: UINT The class style(s). This member can be any combination of the Class Styles. lpfnWndProc Type: WNDPROC A pointer to the window procedure. You must use the CallWindowProc function to call the window procedure. For more information, see WindowProc. cbClsExtra Type: int
The number of extra bytes to allocate following the window-class structure. The system initializes the bytes to zero. cbWndExtra Type: int The number of extra bytes to allocate following the window instance. The system initializes the bytes to zero. If an application uses WNDCLASSEX to register a dialog box created by using the CLASS directive in the resource file, it must set this member to DLGWINDOWEXTRA. hInstance Type: HINSTANCE A handle to the instance that contains the window procedure for the class. hIcon Type: HICON A handle to the class icon. This member must be a handle to an icon resource. If this member is NULL, the system provides a default icon. hCursor Type: HCURSOR A handle to the class cursor. This member must be a handle to a cursor resource. If this member is NULL, an application must explicitly set the cursor shape whenever the mouse moves into the application's window. hbrBackground Type: HBRUSH A handle to the class background brush. This member can be a handle to the brush to be used for painting the background, or it can be a color value. A color value must be one of the following standard system colors (the value 1 must be added to the chosen color). If a color value is given, you must convert it to one of the followingHBRUSH types:
COLOR_ACTIVEBORDER COLOR_ACTIVECAPTION COLOR_APPWORKSPACE COLOR_BACKGROUND COLOR_BTNFACE COLOR_BTNSHADOW COLOR_BTNTEXT COLOR_CAPTIONTEXT COLOR_GRAYTEXT COLOR_HIGHLIGHT COLOR_HIGHLIGHTTEXT COLOR_INACTIVEBORDER
The system automatically deletes class background brushes when the class is unregistered by usingUnregisterClass. An application should not delete these brushes. When this member is NULL, an application must paint its own background whenever it is requested to paint in its client area. To determine whether the background must be painted, an application can either process theWM_ERASEBKGND message or test the fErase member of the PAINTSTRUCT structure filled by the BeginPaintfunction. lpszMenuName Type: LPCTSTR Pointer to a null-terminated character string that specifies the resource name of the class menu, as the name appears in the resource file. If you use an integer to identify the menu, use the MAKEINTRESOURCE macro. If this member is NULL, windows belonging to this class have no default menu. lpszClassName Type: LPCTSTR A pointer to a null-terminated string or is an atom. If this parameter is an atom, it must be a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low-order word oflpszClassName; the high-order word must be zero. If lpszClassName is a string, it specifies the window class name. The class name can be any name registered withRegisterClass or RegisterClassEx, or any of the predefined controlclass names. The maximum length for lpszClassName is 256. If lpszClassName is greater than the maximum length, theRegisterClassEx function will fail. hIconSm Type: HICON A handle to a small icon that is associated with the window class. If this member is NULL, the system searches the icon resource specified by the hIcon member for an icon of the appropriate size to use as the small icon.
http://msdn.microsoft.com/en-us/library/windows/desktop/ff729176(v=vs.85).aspx
CS_GLOBALCLASS 0x4000
CS_PARENTDC 0x0080
Sets the clipping rectangle of the child window to that of the parent window so that the child can draw on the parent. A window with the CS_PARENTDC style bit receives a regular device context from the system's cache of device contexts. It does not give the child the parent's device context or device context settings. Specifying CS_PARENTDCenhances an application's performance. Saves, as a bitmap, the portion of the screen image obscured by a window of this class. When the window is removed, the system uses the saved bitmap to restore the screen image, including other windows that were obscured. Therefore, the system does not sendWM_PAINT messages to windows that were obscured if the memory used by the bitmap has not been discarded and if other screen actions have not invalidated the stored image. This style is useful for small windows (for example, menus or dialog boxes) that are displayed briefly and then removed before other screen activity takes place. This style increases the time required to display the window, because the system must first allocate memory to store the bitmap. Redraws the entire window if a movement or size adjustment changes the height of the client area.
CS_SAVEBITS 0x0800
CS_VREDRAW 0x0001
http://www.gamedev.net/topic/440835-what-is-color_window--1/
What is COLOR_WINDOW + 1
It is a member of the WNDCLASS or WNDCLASSEX structure that describes the background of a window using that window class. The COLOR_WINDOW + 1 bit of that line says that the background color of a window using that window class should be a system color; that gives the advantage that when a user changes the color scheme on his/her computer, the color you used will change as well if I'm not mistaken. Just experiment with the addition to COLOR_WINDOW and see what kind of colors you can get :P
http://msdn.microsoft.com/en-us/library/windows/desktop/ms648072(v=vs.85).aspx
LoadIcon function
Loads the specified icon resource from the executable (.exe) file associated with an application instance. Note This function has been superseded by the LoadImage function.
Syntax
C++
Parameters
hInstance [in, optional] Type: HINSTANCE A handle to an instance of the module whose executable file contains the icon to be loaded. This parameter must be NULL when a standard icon is being loaded. lpIconName [in] Type: LPCTSTR The name of the icon resource to be loaded. Alternatively, this parameter can contain the resource identifier in the low-order word and zero in the high-order word. Use the MAKEINTRESOURCE macro to create this value. To use one of the predefined icons, set the hInstance parameter to NULL and the lpIconName parameter to one of the following values.
Meaning
IDI_ASTERISK MAKEINTRESOURCE(32516)
IDI_ERROR MAKEINTRESOURCE(32513)
Hand-shaped icon.
IDI_EXCLAMATION MAKEINTRESOURCE(32515)
IDI_HAND
MAKEINTRESOURCE(32513)
IDI_INFORMATION MAKEINTRESOURCE(32516)
Asterisk icon.
IDI_QUESTION MAKEINTRESOURCE(32514)
IDI_SHIELD MAKEINTRESOURCE(32518)
IDI_WARNING MAKEINTRESOURCE(32515)
IDI_WINLOGO MAKEINTRESOURCE(32517)
Return value
Type: HICON If the function succeeds, the return value is a handle to the newly loaded icon. If the function fails, the return value is NULL. To get extended error information, call GetLastError. Remarks LoadIcon loads the icon resource only if it has not been loaded; otherwise, it retrieves a handle to the existing resource. The function searches the icon resource for the icon most appropriate for the current display. The icon resource can be a color or monochrome bitmap. LoadIcon can only load an icon whose size conforms to the SM_CXICON and SM_CYICON system metric values. Use the LoadImage function to load icons of other sizes. Requirements Minimum supported client Windows 2000 Professional [desktop apps only]
Header
Library
User32.lib User32.dll
DLL
http://msdn.microsoft.com/en-us/library/windows/desktop/ms648391(v=vs.85).aspx
LoadCursor function
Loads the specified cursor resource from the executable (.EXE) file associated with an application instance. Note This function has been superseded by the LoadImage function. Syntax
C++
Parameters
hInstance [in, optional] Type: HINSTANCE A handle to an instance of the module whose executable file contains the cursor to be loaded. lpCursorName [in] Type: LPCTSTR The name of the cursor resource to be loaded. Alternatively, this parameter can consist of the resource identifier in the low-order word and zero in the high-order word. The MAKEINTRESOURCE macro can also be used to create this value. To use one of the predefined cursors, the application must set the hInstance parameter to NULL and the lpCursorName parameter to one the following values.
Meaning
IDC_ARROW MAKEINTRESOURCE(32512)
Standard arrow
IDC_CROSS MAKEINTRESOURCE(32515)
Crosshair
IDC_HAND MAKEINTRESOURCE(32649)
Hand
IDC_HELP MAKEINTRESOURCE(32651)
IDC_IBEAM MAKEINTRESOURCE(32513)
I-beam
IDC_ICON MAKEINTRESOURCE(32641)
IDC_NO MAKEINTRESOURCE(32648)
Slashed circle
IDC_SIZE MAKEINTRESOURCE(32640)
IDC_SIZEALL MAKEINTRESOURCE(32646)
IDC_SIZENESW
MAKEINTRESOURCE(32643)
IDC_SIZENS MAKEINTRESOURCE(32645)
IDC_SIZENWSE MAKEINTRESOURCE(32642)
IDC_SIZEWE MAKEINTRESOURCE(32644)
IDC_UPARROW MAKEINTRESOURCE(32516)
Vertical arrow
IDC_WAIT MAKEINTRESOURCE(32514)
Hourglass
Return value
Type: HCURSOR If the function succeeds, the return value is the handle to the newly loaded cursor. If the function fails, the return value is NULL. To get extended error information, call GetLastError. Remarks The LoadCursor function loads the cursor resource only if it has not been loaded; otherwise, it retrieves the handle to the existing resource. This function returns a valid cursor handle only if the lpCursorName parameter is a pointer to a cursor resource. If lpCursorName is a pointer to any type of resource other than a cursor (such as an icon), the return value is not NULL, even though it is not a valid cursor handle. The LoadCursor function searches the cursor resource most appropriate for the cursor for the current display device. The cursor resource can be a color or monochrome bitmap. Examples For an example, see Creating a Cursor. Requirements Minimum supported client Windows 2000 Professional [desktop apps only]
Windows 2000 Server [desktop apps only] Winuser.h (include Windows.h) User32.lib User32.dll
Header
Library DLL
http://msdn.microsoft.com/en-us/library/windows/desktop/ms632600(v=vs.85).aspx
Window Styles
he following are the window styles. After the window has been created, these styles cannot be modified, except as noted. Constant/value WS_BORDER 0x00800000L WS_CAPTION 0x00C00000L WS_CHILD 0x40000000L WS_CHILDWINDOW 0x40000000L WS_CLIPCHILDREN 0x02000000L Description The window has a thin-line border.
The window is a child window. A window with this style cannot have a menu bar. This style cannot be used with the WS_POPUP style. Same as the WS_CHILD style.
Excludes the area occupied by child windows when drawing occurs within the parent window. This style is used when creating the parent window.
WS_CLIPSIBLINGS 0x04000000L
Clips child windows relative to each other; that is, when a particular child window receives a WM_PAINT message, the WS_CLIPSIBLINGS style clips all other overlapping child windows out of the region of the child window to be updated. IfWS_CLIPSIBLINGS is not specified and child windows overlap, it is possible, when drawing within the client area of a child window, to draw within the client area of a neighboring child window. The window is initially disabled. A disabled window cannot receive input from the user. To change this after a window has been created, use the EnableWindow function. The window has a border of a style typically used with dialog boxes. A window with this style cannot have a title bar. The window is the first control of a group of controls. The group consists of this first control and all controls defined after it, up to the next control with the WS_GROUPstyle. The first control in each group usually has the WS_TABSTOP style so that the user can move from group to group. The user can subsequently change the keyboard focus from one control in the group to the next control in the group by using the direction keys. You can turn this style on and off to change dialog box navigation. To change this style after a window has been created, use the SetWindowLong function. The window has a horizontal scroll bar.
WS_DISABLED 0x08000000L
The window has a maximize button. Cannot be combined with theWS_EX_CONTEXTHELP style. The WS_SYSMENU style must also be specified. The window is initially minimized. Same as the WS_ICONIC style.
0x00020000L
theWS_EX_CONTEXTHELP style. The WS_SYSMENU style must also be specified. The window is an overlapped window. An overlapped window has a title bar and a border. Same as the WS_TILED style. The window is an overlapped window. Same as the WS_TILEDWINDOW style.
WS_OVERLAPPED 0x00000000L WS_OVERLAPPEDWINDOW (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX) WS_POPUP 0x80000000L WS_POPUPWINDOW (WS_POPUP | WS_BORDER | WS_SYSMENU) WS_SIZEBOX 0x00040000L WS_SYSMENU 0x00080000L WS_TABSTOP 0x00010000L
The windows is a pop-up window. This style cannot be used with the WS_CHILD style. The window is a pop-up window. The WS_CAPTION and WS_POPUPWINDOW styles must be combined to make the window menu visible. The window has a sizing border. Same as the WS_THICKFRAME style.
The window has a window menu on its title bar. The WS_CAPTION style must also be specified. The window is a control that can receive the keyboard focus when the user presses the TAB key. Pressing the TAB key changes the keyboard focus to the next control with theWS_TABSTOP style. You can turn this style on and off to change dialog box navigation. To change this style after a window has been created, use the SetWindowLong function. For user-created windows and modeless dialogs to work with tab stops, alter the message loop to call the IsDialogMessage function. The window has a sizing border. Same as the WS_SIZEBOX style.
The window is an overlapped window. An overlapped window has a title bar and a border. Same as the WS_OVERLAPPED style. The window is an overlapped window. Same as the WS_OVERLAPPEDWINDOW style.
WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX) WS_VISIBLE 0x10000000L The window is initially visible. This style can be turned on and off by using the ShowWindow or SetWindowPosfunction. The window has a vertical scroll bar.
WS_VSCROLL 0x00200000L
http://msdn.microsoft.com/en-us/library/windows/desktop/ms632679(v=vs.85).aspx
CreateWindow function
Creates an overlapped, pop-up, or child window. It specifies the window class, window title, window style, and (optionally) the initial position and size of the window. The function also specifies the window's parent or owner, if any, and the window's menu. To use extended window styles in addition to the styles supported by CreateWindow, use the CreateWindowExfunction. Syntax
C++
HWND WINAPI CreateWindow( _In_opt_ _In_opt_ _In_ _In_ _In_ _In_ _In_ _In_opt_ _In_opt_ _In_opt_ _In_opt_ ); LPCTSTR lpClassName, LPCTSTR lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam
Parameters
lpClassName [in, optional]
Type: LPCTSTR A null-terminated string or a class atom created by a previous call to the RegisterClass or RegisterClassExfunction. The atom must be in the low-order word of lpClassName; the high-order word must be zero. IflpClassName is a string, it specifies the window class name. The class name can be any name registered withRegisterClass or RegisterClassEx, provided that the module that registers the class is also the module that creates the window. The class name can also be any of the predefined system class names. For a list of system class names, see the Remarks section. lpWindowName [in, optional] Type: LPCTSTR The window name. If the window style specifies a title bar, the window title pointed to by lpWindowName is displayed in the title bar. When using CreateWindow to create controls, such as buttons, check boxes, and static controls, use lpWindowName to specify the text of the control. When creating a static control with the SS_ICONstyle, use lpWindowName to specify the icon name or identifier. To specify an identifier, use the syntax "#num". dwStyle [in] Type: DWORD The style of the window being created. This parameter can be a combination of the window style values, plus the control styles indicated in the Remarks section. x [in] Type: int The initial horizontal position of the window. For an overlapped or pop-up window, the x parameter is the initial x-coordinate of the window's upper-left corner, in screen coordinates. For a child window, x is the x-coordinate of the upper-left corner of the window relative to the upper-left corner of the parent window's client area. If this parameter is set to CW_USEDEFAULT, the system selects the default position for the window's upper-left corner and ignores the y parameter. CW_USEDEFAULT is valid only for overlapped windows; if it is specified for a pop-up or child window, the x and y parameters are set to zero. y [in] Type: int The initial vertical position of the window. For an overlapped or pop-up window, the y parameter is the initial y-coordinate of the window's upper-left corner, in screen coordinates. For a child window, y is the initial y-coordinate of the upper-left corner of the child window relative to the upper-left corner of the parent window's client area. For a list box, y is the initial y-coordinate of the upper-left corner of the list box's client area relative to the upper-left corner of the parent window's client area. If an overlapped window is created with the WS_VISIBLE style bit set and the x parameter is set toCW_USEDEFAULT, then the y parameter determines how the window is shown. If the y parameter isCW_USEDEFAULT, then the window manager calls ShowWindow with
the SW_SHOW flag after the window has been created. If the y parameter is some other value, then the window manager calls ShowWindow with that value as the nCmdShow parameter. nWidth [in] Type: int The width, in device units, of the window. For overlapped windows, nWidth is either the window's width, in screen coordinates, or CW_USEDEFAULT. If nWidth is CW_USEDEFAULT, the system selects a default width and height for the window; the default width extends from the initial x-coordinate to the right edge of the screen, and the default height extends from the initial y-coordinate to the top of the icon area. CW_USEDEFAULT is valid only for overlapped windows; if CW_USEDEFAULT is specified for a pop-up or child window, nWidth and nHeight are set to zero. nHeight [in] Type: int The height, in device units, of the window. For overlapped windows, nHeight is the window's height, in screen coordinates. If nWidth is set to CW_USEDEFAULT, the system ignores nHeight. hWndParent [in, optional] Type: HWND A handle to the parent or owner window of the window being created. To create a child window or an owned window, supply a valid window handle. This parameter is optional for pop-up windows. To create a message-only window, supply HWND_MESSAGE or a handle to an existing message-only window. hMenu [in, optional] Type: HMENU A handle to a menu, or specifies a child-window identifier depending on the window style. For an overlapped or pop-up window, hMenu identifies the menu to be used with the window; it can be NULL if the class menu is to be used. For a child window, hMenu specifies the child-window identifier, an integer value used by a dialog box control to notify its parent about events. The application determines the child-window identifier; it must be unique for all child windows with the same parent window. hInstance [in, optional] Type: HINSTANCE A handle to the instance of the module to be associated with the window. lpParam [in, optional] Type: LPVOID
A pointer to a value to be passed to the window through the CREATESTRUCT structure (lpCreateParamsmember) pointed to by the lParam param of the WM_CREATE message. This message is sent to the created window by this function before it returns. If an application calls CreateWindow to create a MDI client window, lpParam should point to aCLIENTCREATESTRUCT structure. If an MDI client window calls CreateWindow to create an MDI child window,lpParam should point to a MDICREATESTRUCT structure. lpParam may be NULL if no additional data is needed. Return value Type: Type: HWND If the function succeeds, the return value is a handle to the new window. If the function fails, the return value is NULL. To get extended error information, call GetLastError. This function typically fails for one of the following reasons:
an invalid parameter value the system class was registered by a different module The WH_CBT hook is installed and returns a failure code if one of the controls in the dialog template is not registered, or its window window procedure fails WM_CREATEor WM_NCCREATE
Remarks
Before returning, CreateWindow sends a WM_CREATE message to the window procedure. For overlapped, pop-up, and child windows, CreateWindow sends WM_CREATE, WM_GETMINMAXINFO, and WM_NCCREATE messages to the window. The lParam parameter of the WM_CREATE message contains a pointer to a CREATESTRUCT structure. If theWS_VISIBLE style is specified, CreateWindow sends the window all the messages required to activate and show the window. If the created window is a child window, its default position is at the bottom of the Z-order. If the created window is a top-level window, its default position is at the top of the Z-order (but beneath all topmost windows unless the created window is itself topmost). For information on controlling whether the Taskbar displays a button for the created window, see Managing Taskbar Buttons. For information on removing a window, see the DestroyWindow function. The following predefined system classes can be specified in the lpClassName parameter. Note the corresponding control styles you can use in the dwStyle parameter. System class Meaning Designates a small rectangular child window that represents a button the user can click to turn it on or off. Button controls can be used alone or in groups, and they can either be labeled or appear without text. Button controls typically change appearance when the user
BUTTON
clicks them. For more information, see Buttons For a table of the button styles you can specify in the dwStyle parameter, see Button Styles. COMBOBOX Designates a control consisting of a list box and a selection field similar to an edit control. When using this style, an application should either display the list box at all times or enable a drop-down list box. If the list box is visible, typing characters into the selection field highlights the first list box entry that matches the characters typed. Conversely, selecting an item in the list box displays the selected text in the selection field. For more information, see Combo Boxes. For a table of the combo box styles you can specify in the dwStyle parameter, see Combo Box Styles. Designates a rectangular child window into which the user can type text from the keyboard. The user selects the control and gives it the keyboard focus by clicking it or moving to it by pressing the TAB key. The user can type text when the edit control displays a flashing caret; use the mouse to move the cursor, select characters to be replaced, or position the cursor for inserting characters; or use the BACKSPACE key to delete characters. For more information, see Edit Controls. For a table of the edit control styles you can specify in the dwStyle parameter, see Edit Control Styles. Designates a list of character strings. Specify this control whenever an application must present a list of names, such as file names, from which the user can choose. The user can select a string by clicking it. A selected string is highlighted, and a notification message is passed to the parent window. For more information, see List Boxes. For a table of the list box styles you can specify in the dwStyle parameter, see List Box Styles. Designates an MDI client window. This window receives messages that control the MDI application's child windows. The recommended style bits are WS_CLIPCHILDREN and WS_CHILD. Specify the WS_HSCROLL and WS_VSCROLL styles to create an MDI client window that allows the user to scroll MDI child windows into view. For more information, see Multiple Document Interface. Designates a Microsoft Rich Edit 1.0 control. This window lets the user view and edit text with character and paragraph formatting, and can include embedded Component Object Model (COM) objects. For more information, see Rich Edit Controls. For a table of the rich edit control styles you can specify in the dwStyle parameter, see Rich Edit Control Styles. Designates a Microsoft Rich Edit 2.0 control. This controls let the user view and edit text with character and paragraph formatting, and can include embedded COM objects. For
EDIT
LISTBOX
MDICLIENT
RichEdit
RICHEDIT_CLASS
more information, see Rich Edit Controls. For a table of the rich edit control styles you can specify in the dwStyle parameter, see Rich Edit Control Styles. SCROLLBAR Designates a rectangle that contains a scroll box and has direction arrows at both ends. The scroll bar sends a notification message to its parent window whenever the user clicks the control. The parent window is responsible for updating the position of the scroll box, if necessary. For more information, see Scroll Bars. For a table of the scroll bar control styles you can specify in the dwStyle parameter, see Scroll Bar Control Styles. Designates a simple text field, box, or rectangle used to label, box, or separate other controls. Static controls take no input and provide no output. For more information, see Static Controls. For a table of the static control styles you can specify in the dwStyle parameter, see Static Control Styles.
STATIC
Examples
For an example, see Using Window Classes. Requirements Minimum supported client Windows 2000 Professional [desktop apps only]
Header
http://msdn.microsoft.com/enus/library/windows/desktop/ms644936(v=vs.8 5).aspx
GetMessage function
Retrieves a message from the calling thread's message queue. The function dispatches incoming sent messages until a posted message is available for retrieval. Unlike GetMessage, the PeekMessage function does not wait for a message to be posted before returning. Syntax
C++
BOOL WINAPI GetMessage( _Out_ _In_opt_ _In_ _In_ ); LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax
Parameters
lpMsg [out] Type: LPMSG
A pointer to an MSG structure that receives message information from the thread's message queue. hWnd [in, optional] Type: HWND A handle to the window whose messages are to be retrieved. The window must belong to the current thread. If hWnd is NULL, GetMessage retrieves messages for any window that belongs to the current thread, and any messages on the current thread's message queue whose hwnd value is NULL (see the MSG structure). Therefore if hWnd is NULL, both window messages and thread messages are processed. If hWnd is -1, GetMessage retrieves only messages on the current thread's message queue whose hwnd value isNULL, that is, thread messages as posted by PostMessage (when the hWnd parameter is NULL) orPostThreadMessage. wMsgFilterMin [in] Type: UINT The integer value of the lowest message value to be retrieved. Use WM_KEYFIRST (0x0100) to specify the first keyboard message or WM_MOUSEFIRST (0x0200) to specify the first mouse message. Use WM_INPUT here and in wMsgFilterMax to specify only the WM_INPUT messages. If wMsgFilterMin and wMsgFilterMax are both zero, GetMessage returns all available messages (that is, no range filtering is performed). wMsgFilterMax [in] Type: UINT The integer value of the highest message value to be retrieved. Use WM_KEYLAST to specify the last keyboard message or WM_MOUSELAST to specify the last mouse message. Use WM_INPUT here and in wMsgFilterMin to specify only the WM_INPUT messages. If wMsgFilterMin and wMsgFilterMax are both zero, GetMessage returns all available messages (that is, no range filtering is performed). Return value Type: Type: BOOL If the function retrieves a message other than WM_QUIT, the return value is nonzero. If the function retrieves the WM_QUIT message, the return value is zero. If there is an error, the return value is -1. For example, the function fails if hWnd is an invalid window handle or lpMsg is an invalid pointer. To get extended error information, call GetLastError. Because the return value can be nonzero, zero, or -1, avoid code like this:
while (GetMessage( lpMsg, hWnd, 0, 0)) ...
The possibility of a -1 return value means that such code can lead to fatal application errors. Instead, use code like this:
BOOL bRet; while( (bRet = GetMessage( &msg, hWnd, 0, 0 )) != 0) { if (bRet == -1) { // handle the error and possibly exit } else { TranslateMessage(&msg); DispatchMessage(&msg); } }
Remarks
An application typically uses the return value to determine whether to end the main message loop and exit the program. The GetMessage function retrieves messages associated with the window identified by the hWnd parameter or any of its children, as specified by the IsChild function, and within the range of message values given by the wMsgFilterMin andwMsgFilterMax parameters. Note that an application can only use the low word in the wMsgFilterMin and wMsgFilterMaxparameters; the high word is reserved for the system. Note that GetMessage always retrieves WM_QUIT messages, no matter which values you specify for wMsgFilterMin andwMsgFilterMax. During this call, the system delivers pending, nonqueued messages, that is, messages sent to windows owned by the calling thread using the SendMessage, SendMessageCallback, SendMessageTimeout, or SendNotifyMessagefunction. Then the first queued message that matches the specified filter is retrieved. The system may also process internal events. If no filter is specified, messages are processed in the following order:
Sent messages Posted messages Input (hardware) messages and system internal events Sent messages (again) WM_PAINT messages WM_TIMER messages
To retrieve input messages before posted messages, use the wMsgFilterMin and wMsgFilterMax parameters.
GetMessage does not remove WM_PAINT messages from the queue. The messages remain in the queue until processed. If a top-level window stops responding to messages for more than several seconds, the system considers the window to be not responding and replaces it with a ghost window that has the same zorder, location, size, and visual attributes. This allows the user to move it, resize it, or even close the application. However, these are the only actions available because the application is actually not responding. When in the debugger mode, the system does not generate a ghost window. Examples For an example, see Creating a Message Loop. Requirements Minimum supported client Windows 2000 Professional [desktop apps only]
Header Library
User32.lib User32.dll
DLL
http://msdn.microsoft.com/en-us/library/x0sksh43.aspx
The uint keyword signifies an integral type that stores values according to the size and range shown in the following table.
Type uint
Range 0 to 4,294,967,295
.NET Frame
System.UInt3
Note The uint type is not CLS-compliant. Use int whenever possible.
Literals
You can declare and initialize a variable of the type uint like this example: uint myUint = 4294967290; When an integer literal has no suffix, its type is the first of these types in which its value can be represented: int, uint, long, ulong. In this example, it is uint: uint uInt1 = 123; You can also use the suffix u or U, such as this: uint uInt2 = 123U; When you use the suffix U or u, the type of the literal is determined to be either uint or ulong according to the numeric value of the literal. For example: Console.WriteLine(44U.GetType()); Console.WriteLine(323442434344U.GetType()); This code displays System.UInt32, followed by System.UInt64 -- the underlying types for uint and ulong respectively -- because the second literal is too large to be stored by the uint type.
Conversions
There is a predefined implicit conversion from uint to long, ulong, float, double, or decimal. For example: float myFloat = 4294967290; // OK: implicit conversion to float There is a predefined implicit conversion from byte, ushort, or char to uint. Otherwise you must use a cast. For example, the following assignment statement will produce a compilation error without a cast: long aLong = 22; // Error -- no implicit conversion from long: uint uInt1 = aLong; // OK -- explicit conversion: uint uInt2 = (uint)aLong; Notice also that there is no implicit conversion from floating-point types to uint. For example, the following statement generates a compiler error unless an explicit cast is used: // Error -- no implicit conversion from double: uint x = 3.0; // OK -- explicit conversion: uint y = (uint)3.0; For information about arithmetic expressions with mixed floating-point types and integral types, see float and double. For more information about implicit numeric conversion rules, see the Implicit Numeric Conversions Table (C# Reference).
C# Language Specification
For more information, see the C# Language Specification. The language specification is the definitive source for C# syntax and usage.
http://msdn.microsoft.com/enus/library/system.windows.forms.message.wp aram.aspx
Message.WParam Property
.NET Framework 4.5 Other Versions
Gets or sets the WParam field of the message. Namespace: System.Windows.Forms Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Syntax
C# C++ F# VB public IntPtr WParam { get; set; }
Property Value
Remarks
The value of this field depends on the message. Use the WParam field to get information that is important to handling the message. This field is typically used to store small pieces of information, such as flags.
Examples
The following code example demonstrates overriding the WndProc method to handle operating system messages identified in the Message. The WM_ACTIVATEAPP operating system message is handled in this example to know when another application is becoming active. For information about the available Message.Msg, Message.LParam, and Message.WParam values, see the MSG Structure documentation. For information about the actual constant values, see Message Constants. C# C++ VB using System; using System.Drawing; using System.Windows.Forms; namespace csTempWindowsApplication1 { public class Form1 : System.Windows.Forms.Form { // Constant value was found in the "windows.h" header file. private const int WM_ACTIVATEAPP = 0x001C; private bool appActive = true; [STAThread] static void Main() { Application.Run(new Form1()); } public Form1() { this.Size = new System.Drawing.Size(300,300); this.Text = "Form1"; this.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); } protected override void OnPaint(PaintEventArgs e) { // Paint a string in different styles depending on whether the // application is active. if (appActive) {
e.Graphics.FillRectangle(SystemBrushes.ActiveCaption,20,20,260,50); e.Graphics.DrawString("Application is active", this.Font, SystemBrushes.ActiveCaptionText, 20,20); } else { e.Graphics.FillRectangle(SystemBrushes.InactiveCaption,20,20,260,50); e.Graphics.DrawString("Application is Inactive", this.Font, SystemBrushes.ActiveCaptionText, 20,20); } } [System.Security.Permissions.PermissionSet(System.Security.Permissions.Secur ityAction.Demand, Name="FullTrust")] protected override void WndProc(ref Message m) { // Listen for operating system messages. switch (m.Msg) { // The WM_ACTIVATEAPP message occurs when the application // becomes the active application or becomes inactive. case WM_ACTIVATEAPP: // The WParam value identifies what is occurring. appActive = (((int)m.WParam != 0)); // Invalidate to get new text painted. this.Invalidate(); break; } base.WndProc(ref m); } } }
Version Information
.NET Framework
Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0
Platforms
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported) The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
http://msdn.microsoft.com/en-us/library/system.windows.forms.message.lparam.aspx
Message.LParam Property
.NET Framework 4.5 Other Versions
Specifies the LParam field of the message. Namespace: System.Windows.Forms Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Syntax
C# C++ F# VB public IntPtr LParam { get; set; }
Property Value
Remarks
The value of this field depends on the message. Use the LParam field to get information that is important for handling the message. LParam is typically used to store an object if it is needed by the message. Use the GetLParam method to retrieve and convert information from the LParam field into an object.
Version Information
.NET Framework
Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0
Platforms
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported) The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.