Eclipse SWT
Reference: http://www.eclipse.org/swt/
http://www.functionx.com/win32/Lesson01.htm
http://www.win32developer.com/tutorial/windows/windows_tutorial_2.shtm
http://download.ourdev.cn/bbs_upload782111/files_35/ourdev_606687D1GBNL.pdf
http://msdn.microsoft.com/en-us/library/windows/desktop/ff381399%28v=vs.85%29.aspx
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/WinPanel/Introduction.html#//apple_ref/doc/uid/10000031-SW1





- Drawable:
Implementers of Drawable can have a graphics context (GC) created for them, and then they can be drawn on by sending messages to their associated GC. SWT images, and device objects such as the Display device and the Printer device, are drawables.Invokes platform specific functionality to dispose a GC handle or to allocate a new GC handle.
public interface Drawable {
public int /*long*/ internal_new_GC (GCData data);
public void internal_dispose_GC (int /*long*/ handle, GCData data);
}- Device: This class is the abstract superclass of all device objects, such as the Display device and the Printer device. Devices can have a graphics context (GC) created for them, and they can be drawn on by sending messages to the associated GC.
- Some member:
public int /*long*/ hPalette = 0;
Font systemFont;
protected static Device CurrentDevice;
protected static Runnable DeviceFinder;
static {
try
{
Class.forName ("org.eclipse.swt.widgets.Display"); //$NON-NLS-1$
}
catch (ClassNotFoundException e)
{}
}- Create only one new Device
- some methods in OS class, looks so like methods declared in <afxwin.h>(<afxwin1.inl>(WinDGI.h>))<WinUser.h>
- In fact, native method will invoke the method defined in xxx.h for window in dll "".
- Make Widget or controls to wrap the basic OS window functions in order to converting procedure programming to OO programming.

public static final native int SetPixel (int /*long*/ hdc, int X, int Y, int crColor);
public static final native int SetPolyFillMode (int /*long*/ hdc, int iPolyFillMode);
public static final native boolean SetProcessDPIAware ();
public static final native boolean SetRect (RECT lprc, int xLeft, int yTop, int xRight, int yBottom);
public static final native boolean SetRectRgn (int /*long*/ hrgn, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);
public static final native int SetROP2 (int /*long*/ hdc, int fnDrawMode);
public static final native boolean SetScrollInfo (int /*long*/ hwnd, int flags, SCROLLINFO info, boolean fRedraw);
public static final native int SetStretchBltMode (int /*long*/ hdc, int iStretchMode);
/**
* @param hWnd cast=(HWND)
* @param lpString cast=(LPCWSTR)
* @param hData cast=(HANDLE)
*/
public static final native boolean SetPropW (int /*long*/ hWnd, int /*long*/ lpString, int /*long*/ hData);
/**
* @param hWnd cast=(HWND)
* @param lpString cast=(LPCTSTR)
* @param hData cast=(HANDLE)
*/
public static final native boolean SetPropA (int /*long*/ hWnd, int /*long*/ lpString, int /*long*/ hData);
/** @param hdc cast=(HDC) */
public static final native int SetTextAlign (int /*long*/ hdc, int fMode);
/**
* @param hdc cast=(HDC)
* @param colorRef cast=(COLORREF)
*/
public static final native int SetTextColor (int /*long*/ hdc, int colorRef);
/**
* @param hWnd cast=(HWND)
* @param lpTimerFunc cast=(TIMERPROC)
*/
public static final native int /*long*/ SetTimer (int /*long*/ hWnd, int /*long*/ nIDEvent, int Elapse, int /*long*/ lpTimerFunc);
/** @param hdc cast=(HDC) */
public static final native boolean SetViewportExtEx (int /*long*/ hdc, int nXExtent, int nYExtent, SIZE lpSize);
/** @param hdc cast=(HDC) */
public static final native boolean SetViewportOrgEx (int /*long*/ hdc, int X, int Y, POINT lpPoint);
/** @param hWnd cast=(HWND) */
public static final native int SetWindowLongW (int /*long*/ hWnd, int nIndex, int dwNewLong);
/** @param hWnd cast=(HWND) */
public static final native int SetWindowLongA (int /*long*/ hWnd, int nIndex, int dwNewLong);
/**
* @param hWnd cast=(HWND)
* @param dwNewLong cast=(LONG_PTR)
*/
public static final native int /*long*/ SetWindowLongPtrW (int /*long*/ hWnd, int nIndex, int /*long*/ dwNewLong);
/**
* @param hWnd cast=(HWND)
* @param dwNewLong cast=(LONG_PTR)
*/
public static final native int /*long*/ SetWindowLongPtrA (int /*long*/ hWnd, int nIndex, int /*long*/ dwNewLong);
/** @param hdc cast=(HDC) */
public static final native boolean SetWindowExtEx (int /*long*/ hdc, int nXExtent, int nYExtent, SIZE lpSize);
/** @param hdc cast=(HDC) */
public static final native boolean SetWindowOrgEx (int /*long*/ hdc, int X, int Y, POINT lpPoint);
/** @param hWnd cast=(HWND) */
public static final native boolean SetWindowPlacement (int /*long*/ hWnd, WINDOWPLACEMENT lpwndpl);
/**
* @param hWnd cast=(HWND)
* @param hWndInsertAfter cast=(HWND)
*/
public static final native boolean SetWindowPos(int /*long*/ hWnd, int /*long*/ hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);
/**
* @param hWnd cast=(HWND)
* @param hRgn cast=(HRGN)
*/
public static final native int SetWindowRgn (int /*long*/ hWnd, int /*long*/ hRgn, boolean bRedraw);
/**
* @param hWnd cast=(HWND)
* @param lpString cast=(LPWSTR)
*/
public static final native boolean SetWindowTextW (int /*long*/ hWnd, char [] lpString);
/**
* @param hWnd cast=(HWND)
* @param lpString cast=(LPSTR)
*/
public static final native boolean SetWindowTextA (int /*long*/ hWnd, byte [] lpString);public Device() {
this(null);
}
public Device(DeviceData data) {
synchronized (Device.class) {
if (data != null) {
debug = data.debug;
tracking = data.tracking;
}
if (tracking) {
errors = new Error [128];
objects = new Object [128];
trackingLock = new Object ();
}
create (data);
init ();
}
}
protected void create (DeviceData data) {
}
protected void init () {
if (debug) {
if (!OS.IsWinCE) OS.GdiSetBatchLimit(1);
} /* Initialize the system font slot */
systemFont = getSystemFont(); /* Initialize scripts list */
if (!OS.IsWinCE) {
int /*long*/ [] ppSp = new int /*long*/ [1];
int [] piNumScripts = new int [1];
OS.ScriptGetProperties (ppSp, piNumScripts);
scripts = new int /*long*/ [piNumScripts [0]];
OS.MoveMemory (scripts, ppSp [0], scripts.length * OS.PTR_SIZEOF);
} /*
* If we're not on a device which supports palettes,
* don't create one.
*/
int /*long*/ hDC = internal_new_GC (null);
int rc = OS.GetDeviceCaps (hDC, OS.RASTERCAPS);
int bits = OS.GetDeviceCaps (hDC, OS.BITSPIXEL);
int planes = OS.GetDeviceCaps (hDC, OS.PLANES); bits *= planes;
if ((rc & OS.RC_PALETTE) == 0 || bits != 8) {
internal_dispose_GC (hDC, null);
return;
} int numReserved = OS.GetDeviceCaps (hDC, OS.NUMRESERVED);
int numEntries = OS.GetDeviceCaps (hDC, OS.SIZEPALETTE); if (OS.IsWinCE) {
/*
* Feature on WinCE. For some reason, certain 8 bit WinCE
* devices return 0 for the number of reserved entries in
* the system palette. Their system palette correctly contains
* the usual 20 system colors. The workaround is to assume
* there are 20 reserved system colors instead of 0.
*/
if (numReserved == 0 && numEntries >= 20) numReserved = 20;
} /* Create the palette and reference counter */
colorRefCount = new int [numEntries]; /* 4 bytes header + 4 bytes per entry * numEntries entries */
byte [] logPalette = new byte [4 + 4 * numEntries]; /* 2 bytes = special header */
logPalette [0] = 0x00;
logPalette [1] = 0x03; /* 2 bytes = number of colors, LSB first */
logPalette [2] = 0;
logPalette [3] = 1; /*
* Create a palette which contains the system entries
* as they are located in the system palette. The
* MSDN article 'Memory Device Contexts' describes
* where system entries are located. On an 8 bit
* display with 20 reserved colors, the system colors
* will be the first 10 entries and the last 10 ones.
*/
byte[] lppe = new byte [4 * numEntries];
OS.GetSystemPaletteEntries (hDC, 0, numEntries, lppe);
/* Copy all entries from the system palette */
System.arraycopy (lppe, 0, logPalette, 4, 4 * numEntries);
/* Lock the indices corresponding to the system entries */
for (int i = 0; i < numReserved / 2; i++) {
colorRefCount [i] = 1;
colorRefCount [numEntries - 1 - i] = 1;
}
internal_dispose_GC (hDC, null);
hPalette = OS.CreatePalette (logPalette);
}
- Display:Instances of this class are responsible for managing the connection between SWT and the underlying operating system. Their most important function is to implement the SWT event loop in terms of the platform event model. They also provide various methods for accessing information about the operating system, and have overall control over the operating system resources which SWT allocates.
Applications which are built with SWT will almost always require only a single display. In particular, some platforms which SWT supports will not allow more than one active display. In other words, some platforms do not support creating a new display if one already exists that has not been sent the
dispose()message.In SWT, the thread which creates aDisplayinstance is distinguished as the user-interface thread for that display.The user-interface thread for a particular display has the following special attributes:- The event loop for that display must be run from the thread.
- Some SWT API methods (notably, most of the public methods in
Widgetand its subclasses), may only be called from the thread. (To support multi-threaded user-interface applications, classDisplayprovides inter-thread communication methods which allow threads other than the user-interface thread to request that it perform operations on their behalf.) - The thread is not allowed to construct other
Displays until that display has been disposed. (Note that, this is in addition to the restriction mentioned above concerning platform support for multiple displays. Thus, the only way to have multiple simultaneously active displays, even on platforms which support it, is to have multiple threads.)
Enforcing these attributes allows SWT to be implemented directly on the underlying operating system's event model. This has numerous benefits including smaller footprint, better use of resources, safer memory management, clearer program logic, better performance, and fewer overall operating system threads required. The down side however, is that care must be taken (only) when constructing multi-threaded applications to use the inter-thread communication mechanisms which this class provides when required.
public class Display extends Device
Variables in Display
public MSG msg = new MSG ();
static String APP_NAME = "SWT"; //$NON-NLS-1$
static String APP_VERSION = ""; //$NON-NLS-1$
/* Windows and Events */
Event [] eventQueue;
Callback windowCallback;
int /*long*/ windowProc;
int threadId;
Control [] controlTable;
static final int GROW_SIZE = 1024;
static final int SWT_OBJECT_INDEX;
static final boolean USE_PROPERTY = !OS.IsWinCE;
Menu [] bars, popups;
MenuItem [] items;
Callback msgFilterCallback;
int /*long*/ msgFilterProc, filterHook;
MSG hookMsg = new MSG ();
/* Sync/Async Widget Communication */
Synchronizer synchronizer = new Synchronizer (this);
/* Deferred Layout list */
Composite[] layoutDeferred;
/* Timers */
int /*long*/ [] timerIds;
Runnable [] timerList;
/* Message Only Window */
Callback messageCallback;
int /*long*/ hwndMessage, messageProc;
static {
DeviceFinder = new Runnable () {
public void run () {
Device device = getCurrent ();
if (device == null) {
device = getDefault ();
}
setDevice (device);
}
};
}Methods in Display
void wakeThread () {
if (OS.IsWinCE) {
OS.PostMessage (hwndMessage, OS.WM_NULL, 0, 0);
} else {
OS.PostThreadMessage (threadId, OS.WM_NULL, 0, 0);
}
}public void wake () {
synchronized (Device.class) {
if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
if (thread == Thread.currentThread ()) return;
wakeThread ();
}
}public void update() {
checkDevice ();
if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (4, 10)) {
if (OS.IsHungAppWindow (hwndMessage)) {
MSG msg = new MSG ();
int flags = OS.PM_REMOVE | OS.PM_NOYIELD;
OS.PeekMessage (msg, hwndMessage, SWT_NULL, SWT_NULL, flags);
}
}
Shell[] shells = getShells ();
for (int i=0; i<shells.length; i++) {
Shell shell = shells [i];
if (!shell.isDisposed ()) shell.update (true);
}
}public void syncExec (Runnable runnable) {
Synchronizer synchronizer;
synchronized (Device.class) {
if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
synchronizer = this.synchronizer;
}
synchronizer.syncExec (runnable);
}public boolean sleep () {
checkDevice ();
if (runMessages && getMessageCount () != 0) return true;
if (OS.IsWinCE) {
OS.MsgWaitForMultipleObjectsEx (0, 0, OS.INFINITE, OS.QS_ALLINPUT, OS.MWMO_INPUTAVAILABLE);
return true;
}
return OS.WaitMessage ();
}boolean runTimer (int /*long*/ id) {
if (timerList != null && timerIds != null) {
int index = 0;
while (index <timerIds.length) {
if (timerIds [index] == id) {
OS.KillTimer (hwndMessage, timerIds [index]);
timerIds [index] = 0;
Runnable runnable = timerList [index];
timerList [index] = null;
if (runnable != null) runnable.run ();
return true;
}
index++;
}
}
return false;
}public void asyncExec (Runnable runnable) {
synchronized (Device.class) {
if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
synchronizer.asyncExec (runnable);
}
}public void addListener (int eventType, Listener listener) {
checkDevice ();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
if (eventTable == null) eventTable = new EventTable ();
eventTable.hook (eventType, listener);
}- Widget:This class is the abstract superclass of all user interface objects. Widgets are created, disposed and issue notification to listeners when events occur which affect them.
- Members in Widget
Display display;
EventTable eventTable;static {
if (!OS.IsWinCE) {
if (OS.COMCTL32_VERSION < OS.VERSION (MAJOR, MINOR)) {
System.out.println ("***WARNING: SWT requires comctl32.dll version " + MAJOR + "." + MINOR + " or greater"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
System.out.println ("***WARNING: Detected: " + OS.COMCTL32_MAJOR + "." + OS.COMCTL32_MINOR); //$NON-NLS-1$ //$NON-NLS-2$
}
}
OS.InitCommonControls ();
}/* Global state flags */
static final int DISPOSED = 1<<0;
static final int CANVAS = 1<<1;
static final int KEYED_DATA = 1<<2;
static final int DISABLED = 1<<3;
static final int HIDDEN = 1<<4;- Methods in Widget
public Widget (Widget parent, int style) {
checkSubclass ();
checkParent (parent);
this.style = style;
display = parent.display;
reskinWidget ();
} void _addListener (int eventType, Listener listener) {
if (eventTable == null) eventTable = new EventTable ();
eventTable.hook (eventType, listener);
}protected void checkWidget () {
Display display = this.display;
if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
if (display.thread != Thread.currentThread ()) {
if (display.threadId != OS.GetCurrentThreadId ()) {
error (SWT.ERROR_THREAD_INVALID_ACCESS);
}
}
if ((state & DISPOSED) != 0) error (SWT.ERROR_WIDGET_DISPOSED);
}public void notifyListeners (int eventType, Event event) {
checkWidget();
if (event == null) event = new Event ();
sendEvent (eventType, event);
}
void postEvent (int eventType) {
sendEvent (eventType, null, false);
}
void postEvent (int eventType, Event event) {
sendEvent (eventType, event, false);
}EventTable:sendEvent()
public void sendEvent (Event event) {
if (types == null) return;
level += level >= 0 ? 1 : -1;
try {
for (int i=0; i<types.length; i++) {
if (event.type == SWT.None) return;
if (types [i] == event.type) {
Listener listener = listeners [i];
if (listener != null) listener.handleEvent (event);
}
}
} finally {
boolean compact = level < 0;
level -= level >= 0 ? 1 : -1;
if (compact && level == 0) {
int index = 0;
for (int i=0; i<types.length; i++) {
if (types [i] != 0) {
types [index] = types [i];
listeners [index] = listeners [i];
index++;
}
}
for (int i=index; i<types.length; i++) {
types [i] = 0;
listeners [i] = null;
}
}
}
}boolean showMenu (int x, int y, int detail) {
Event event = new Event ();
event.x = x;
event.y = y;
event.detail = detail;
if (event.detail == SWT.MENU_KEYBOARD) {
updateMenuLocation (event);
}
sendEvent (SWT.MenuDetect, event);
// widget could be disposed at this point
if (isDisposed ()) return false;
if (!event.doit) return true;
Menu menu = getMenu ();
if (menu != null && !menu.isDisposed ()) {
if (x != event.x || y != event.y) {
menu.setLocation (event.x, event.y);
}
menu.setVisible (true);
return true;
}
return false;
}
- Control
- Members in Control
public int /*long*/ handle;
Composite parent;
Cursor cursor;
Menu menu;
String toolTipText;
Object layoutData;
Accessible accessible;
Image backgroundImage;
Region region;- Methods in Control
public Control (Composite parent, int style) {
super (parent, style);
this.parent = parent;
createWidget ();
}void createWidget () {
state |= DRAG_DETECT;
foreground = background = -1;
checkOrientation (parent);
createHandle ();
checkBackground ();
checkBuffered ();
checkComposited ();
register ();
subclass ();
setDefaultFont ();
checkMirrored ();
checkBorder ();
checkGesture ();
if ((state & PARENT_BACKGROUND) != 0) {
setBackground ();
}
}void createHandle () {
int /*long*/ hwndParent = widgetParent ();
handle = OS.CreateWindowEx (
widgetExtStyle (),
windowClass (),
null,
widgetStyle (),
OS.CW_USEDEFAULT, 0, OS.CW_USEDEFAULT, 0,
hwndParent,
0,
OS.GetModuleHandle (null),
widgetCreateStruct ());
if (handle == 0) error (SWT.ERROR_NO_HANDLES);
int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
if ((bits & OS.WS_CHILD) != 0) {
OS.SetWindowLongPtr (handle, OS.GWLP_ID, handle);
}
if (OS.IsDBLocale && hwndParent != 0) {
int /*long*/ hIMC = OS.ImmGetContext (hwndParent);
OS.ImmAssociateContext (handle, hIMC);
OS.ImmReleaseContext (hwndParent, hIMC);
} }void subclass () {
int /*long*/ oldProc = windowProc ();
int /*long*/ newProc = display.windowProc;
if (oldProc == newProc) return;
OS.SetWindowLongPtr (handle, OS.GWLP_WNDPROC, newProc);
}int /*long*/ windowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
LRESULT result = null;
switch (msg) {
case OS.WM_ACTIVATE: result = WM_ACTIVATE (wParam, lParam); break;
case OS.WM_COMMAND: result = WM_COMMAND (wParam, lParam); break;
.......
}LRESULT WM_COMMAND (int /*long*/ wParam, int /*long*/ lParam) {
/*
* When the WM_COMMAND message is sent from a
* menu, the HWND parameter in LPARAM is zero.
*/
if (lParam == 0) {
Decorations shell = menuShell ();
if (shell.isEnabled ()) {
int id = OS.LOWORD (wParam);
MenuItem item = display.getMenuItem (id);
if (item != null && item.isEnabled ()) {
return item.wmCommandChild (wParam, lParam);
}
}
return null;
}
Control control = display.getControl (lParam);
if (control == null) return null;
return control.wmCommandChild (wParam, lParam);
}
- Composite
- Members in Composite
Layout layout;
WINDOWPOS [] lpwp;
Control [] tabList;
int layoutCount, backgroundMode;- Methods in Composite
Control [] _getChildren () {
int count = 0;
int /*long*/ hwndChild = OS.GetWindow (handle, OS.GW_CHILD);
if (hwndChild == 0) return new Control [0];
while (hwndChild != 0) {
count++;
hwndChild = OS.GetWindow (hwndChild, OS.GW_HWNDNEXT);
}
Control [] children = new Control [count];
int index = 0;
hwndChild = OS.GetWindow (handle, OS.GW_CHILD);
while (hwndChild != 0) {
Control control = display.getControl (hwndChild);
if (control != null && control != this) {
children [index++] = control;
}
hwndChild = OS.GetWindow (hwndChild, OS.GW_HWNDNEXT);
}
if (count == index) return children;
Control [] newChildren = new Control [index];
System.arraycopy (children, 0, newChildren, 0, index);
return newChildren;
} Control [] _getTabList () {
if (tabList == null) return tabList;
int count = 0;
for (int i=0; i<tabList.length; i++) {
if (!tabList [i].isDisposed ()) count++;
}
if (count == tabList.length) return tabList;
Control [] newList = new Control [count];
int index = 0;
for (int i=0; i<tabList.length; i++) {
if (!tabList [i].isDisposed ()) {
newList [index++] = tabList [i];
}
}
tabList = newList;
return tabList;
}
- Shell
- Members in Shell
Menu activeMenu;
ToolTip [] toolTips;
int /*long*/ hIMC, hwndMDIClient, lpstrTip, toolTipHandle, balloonTipHandle;
int minWidth = SWT.DEFAULT, minHeight = SWT.DEFAULT;
int /*long*/ [] brushes;
boolean showWithParent, fullScreen, wasMaximized, modified, center;
String toolTitle, balloonTitle;
int /*long*/ toolIcon, balloonIcon;
int /*long*/ windowProc;
Control lastActive;
SHACTIVATEINFO psai;
static /*final*/ int /*long*/ ToolTipProc;
static final int /*long*/ DialogProc;
static final TCHAR DialogClass = new TCHAR (0, OS.IsWinCE ? "Dialog" : "#32770", true);
final static int [] SYSTEM_COLORS = {
OS.COLOR_BTNFACE,
OS.COLOR_WINDOW,
OS.COLOR_BTNTEXT,
OS.COLOR_WINDOWTEXT,
OS.COLOR_HIGHLIGHT,
OS.COLOR_SCROLLBAR,
};
final static int BRUSHES_SIZE = 32;
static {
WNDCLASS lpWndClass = new WNDCLASS ();
OS.GetClassInfo (0, DialogClass, lpWndClass);
DialogProc = lpWndClass.lpfnWndProc;
}- Methods in Shell
public Shell (Display display) {
this (display, OS.IsWinCE ? SWT.NONE : SWT.SHELL_TRIM);
}Shell (Display display, Shell parent, int style, int /*long*/ handle, boolean embedded) {
super ();
checkSubclass ();
if (display == null) display = Display.getCurrent ();
if (display == null) display = Display.getDefault ();
if (!display.isValidThread ()) {
error (SWT.ERROR_THREAD_INVALID_ACCESS);
}
if (parent != null && parent.isDisposed ()) {
error (SWT.ERROR_INVALID_ARGUMENT);
}
this.center = parent != null && (style & SWT.SHEET) != 0;
this.style = checkStyle (parent, style);
this.parent = parent;
this.display = display;
this.handle = handle;
if (handle != 0 && !embedded) {
state |= FOREIGN_HANDLE;
}
reskinWidget();
createWidget ();
}public void addShellListener (ShellListener listener) {
checkWidget ();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Close,typedListener);
addListener (SWT.Iconify,typedListener);
addListener (SWT.Deiconify,typedListener);
addListener (SWT.Activate, typedListener);
addListener (SWT.Deactivate, typedListener);
}int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
if (handle == 0) return 0;
if (hwnd == toolTipHandle || hwnd == balloonTipHandle) {
return OS.CallWindowProc (ToolTipProc, hwnd, msg, wParam, lParam);
}
if (hwndMDIClient != 0) {
return OS.DefFrameProc (hwnd, hwndMDIClient, msg, wParam, lParam);
}
if (windowProc != 0) {
return OS.CallWindowProc (windowProc, hwnd, msg, wParam, lParam);
}
if ((style & SWT.TOOL) != 0) {
int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX | SWT.BORDER | SWT.RESIZE;
if ((style & trim) == 0) return OS.DefWindowProc (hwnd, msg, wParam, lParam);
}
if (parent != null) {
switch (msg) {
case OS.WM_KILLFOCUS:
case OS.WM_SETFOCUS:
return OS.DefWindowProc (hwnd, msg, wParam, lParam);
}
return OS.CallWindowProc (DialogProc, hwnd, msg, wParam, lParam);
}
return OS.DefWindowProc (hwnd, msg, wParam, lParam);
}void createHandle () {
boolean embedded = handle != 0 && (state & FOREIGN_HANDLE) == 0;
if (handle == 0 || embedded) {
super.createHandle ();
} else {
state |= CANVAS;
if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
state |= THEME_BACKGROUND;
}
windowProc = OS.GetWindowLongPtr (handle, OS.GWL_WNDPROC);
} if (!embedded) {
int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
bits &= ~(OS.WS_OVERLAPPED | OS.WS_CAPTION);
if (!OS.IsWinCE) bits |= OS.WS_POPUP;
if ((style & SWT.TITLE) != 0) bits |= OS.WS_CAPTION;
if ((style & SWT.NO_TRIM) == 0) {
if ((style & (SWT.BORDER | SWT.RESIZE)) == 0) bits |= OS.WS_BORDER;
}
OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
int flags = OS.SWP_DRAWFRAME | OS.SWP_NOMOVE | OS.SWP_NOSIZE | OS.SWP_NOZORDER | OS.SWP_NOACTIVATE;
SetWindowPos (handle, 0, 0, 0, 0, 0, flags);
if (OS.IsWinCE) _setMaximized (true);
if (OS.IsPPC) {
psai = new SHACTIVATEINFO ();
psai.cbSize = SHACTIVATEINFO.sizeof;
}
}
if (OS.IsDBLocale) {
hIMC = OS.ImmCreateContext ();
if (hIMC != 0) OS.ImmAssociateContext (handle, hIMC);
}
}void createToolTip (ToolTip toolTip) {
int id = 0;
if (toolTips == null) toolTips = new ToolTip [4];
while (id < toolTips.length && toolTips [id] != null) id++;
if (id == toolTips.length) {
ToolTip [] newToolTips = new ToolTip [toolTips.length + 4];
System.arraycopy (toolTips, 0, newToolTips, 0, toolTips.length);
toolTips = newToolTips;
}
toolTips [id] = toolTip;
toolTip.id = id + Display.ID_START;
if (OS.IsWinCE) return;
TOOLINFO lpti = new TOOLINFO ();
lpti.cbSize = TOOLINFO.sizeof;
lpti.hwnd = handle;
lpti.uId = toolTip.id;
lpti.uFlags = OS.TTF_TRACK;
lpti.lpszText = OS.LPSTR_TEXTCALLBACK;
OS.SendMessage (toolTip.hwndToolTip (), OS.TTM_ADDTOOL, 0, lpti);
}void createToolTipHandle () {
toolTipHandle = OS.CreateWindowEx (
0,
new TCHAR (0, OS.TOOLTIPS_CLASS, true),
null,
OS.TTS_ALWAYSTIP | OS.TTS_NOPREFIX,
OS.CW_USEDEFAULT, 0, OS.CW_USEDEFAULT, 0,
handle,
0,
OS.GetModuleHandle (null),
null);
if (toolTipHandle == 0) error (SWT.ERROR_NO_HANDLES);
if (ToolTipProc == 0) {
ToolTipProc = OS.GetWindowLongPtr (toolTipHandle, OS.GWLP_WNDPROC);
}
OS.SendMessage (toolTipHandle, OS.TTM_SETMAXTIPWIDTH, 0, 0x7FFF);
display.addControl (toolTipHandle, this);
OS.SetWindowLongPtr (toolTipHandle, OS.GWLP_WNDPROC, display.windowProc);
}public Rectangle getBounds () {
checkWidget ();
if (!OS.IsWinCE) {
if (OS.IsIconic (handle)) return super.getBounds ();
}
RECT rect = new RECT ();
OS.GetWindowRect (handle, rect);
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
return new Rectangle (rect.left, rect.top, width, height);
}public Point getLocation () {
checkWidget ();
if (!OS.IsWinCE) {
if (OS.IsIconic (handle)) {
return super.getLocation ();
}
}
RECT rect = new RECT ();
OS.GetWindowRect (handle, rect);
return new Point (rect.left, rect.top);
}
- Button
public class Button extends Control
- Members in Button
Image image, image2, disabledImage;
ImageList imageList;
boolean ignoreMouse, grayed;
static final int MARGIN = 4;
static final int CHECK_WIDTH, CHECK_HEIGHT;
static final int ICON_WIDTH = 128, ICON_HEIGHT = 128;
static /*final*/ boolean COMMAND_LINK = false;
static final int /*long*/ ButtonProc;//WinProc function's adddress
static final TCHAR ButtonClass = new TCHAR (0, "BUTTON", true);
static {
int /*long*/ hBitmap = OS.LoadBitmap (0, OS.OBM_CHECKBOXES);
if (hBitmap == 0) {
CHECK_WIDTH = OS.GetSystemMetrics (OS.IsWinCE ? OS.SM_CXSMICON : OS.SM_CXVSCROLL);
CHECK_HEIGHT = OS.GetSystemMetrics (OS.IsWinCE ? OS.SM_CYSMICON : OS.SM_CYVSCROLL);
} else {
BITMAP bitmap = new BITMAP ();
OS.GetObject (hBitmap, BITMAP.sizeof, bitmap);
OS.DeleteObject (hBitmap);
CHECK_WIDTH = bitmap.bmWidth / 4;
CHECK_HEIGHT = bitmap.bmHeight / 3;
}
WNDCLASS lpWndClass = new WNDCLASS ();
OS.GetClassInfo (0, ButtonClass, lpWndClass);
ButtonProc = lpWndClass.lpfnWndProc;
}- Methods in Button
public Button (Composite parent, int style) {
super (parent, checkStyle (style));
}static int checkStyle (int style) {
style = checkBits (style, SWT.PUSH, SWT.ARROW, SWT.CHECK, SWT.RADIO, SWT.TOGGLE, COMMAND_LINK ? SWT.COMMAND : 0);
if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) {
return checkBits (style, SWT.CENTER, SWT.LEFT, SWT.RIGHT, 0, 0, 0);
}
if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
return checkBits (style, SWT.LEFT, SWT.RIGHT, SWT.CENTER, 0, 0, 0);
}
if ((style & SWT.ARROW) != 0) {
style |= SWT.NO_FOCUS;
return checkBits (style, SWT.UP, SWT.DOWN, SWT.LEFT, SWT.RIGHT, 0, 0);
}
return style;
}void click () {
ignoreMouse = true;
OS.SendMessage (handle, OS.BM_CLICK, 0, 0);
ignoreMouse = false;
}int /*long*/ callWindowProc (int /*long*/ hwnd, int msg, int /*long*/ wParam, int /*long*/ lParam) {
if (handle == 0) return 0;
return OS.CallWindowProc (ButtonProc, hwnd, msg, wParam, lParam);
}public void setSelection (boolean selected) {
checkWidget ();
if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return;
int flags = selected ? OS.BST_CHECKED : OS.BST_UNCHECKED;
if ((style & SWT.CHECK) != 0) {
if (selected && grayed) flags = OS.BST_INDETERMINATE;
}
updateSelection (flags);
}void updateSelection (int flags) {
if (flags != OS.SendMessage (handle, OS.BM_GETCHECK, 0, 0)) {
int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
if ((style & SWT.CHECK) != 0) {
if (flags == OS.BST_INDETERMINATE) {
bits &= ~OS.BS_CHECKBOX;
bits |= OS.BS_3STATE;
} else {
bits |= OS.BS_CHECKBOX;
bits &= ~OS.BS_3STATE;
}
if (bits != OS.GetWindowLong (handle, OS.GWL_STYLE)) {
OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
}
}
OS.SendMessage (handle, OS.BM_SETCHECK, flags, 0);
if (bits != OS.GetWindowLong (handle, OS.GWL_STYLE)) {
OS.SetWindowLong (handle, OS.GWL_STYLE, bits);
}
}
}TCHAR windowClass () {
return ButtonClass;
}
int /*long*/ windowProc () {
return ButtonProc;
}LRESULT WM_LBUTTONDOWN (int /*long*/ wParam, int /*long*/ lParam) {
if (ignoreMouse) return null;
return super.WM_LBUTTONDOWN (wParam, lParam);
}
LRESULT WM_LBUTTONUP (int /*long*/ wParam, int /*long*/ lParam) {
if (ignoreMouse) return null;
return super.WM_LBUTTONUP (wParam, lParam);
}LRESULT wmCommandChild (int /*long*/ wParam, int /*long*/ lParam) {
int code = OS.HIWORD (wParam);
switch (code) {
case OS.BN_CLICKED:
case OS.BN_DOUBLECLICKED:
if ((style & (SWT.CHECK | SWT.TOGGLE)) != 0) {
setSelection (!getSelection ());
} else {
if ((style & SWT.RADIO) != 0) {
if ((parent.getStyle () & SWT.NO_RADIO_GROUP) != 0) {
setSelection (!getSelection ());
} else {
selectRadio ();
}
}
}
sendSelectionEvent (SWT.Selection);
}
return super.wmCommandChild (wParam, lParam);
}
- Create Buttons with windows programming

- Code looks like as following
CtlView.rc
//======================================================================
// Resource file
//
// Written for the book Programming Windows CE
// Copyright (C) 2001 Douglas Boling
//====================================================================== #include "CtlView.h" // Program-specific stuff ID_ICON ICON "CtlView.ico" // Program icon
TEXTICON ICON "btnicon.ico" // Icon used in static window
STATICBMP BITMAP "statbmp.bmp" // Bitmap used in static window CtlView.h //======================================================================
// Header file
//
// Written for the book Programming Windows CE
// Copyright (C) 2001 Douglas Boling
//======================================================================
// Returns number of elements
#define dim(x) (sizeof(x) / sizeof(x[0]))
//----------------------------------------------------------------------
// Generic defines and data types
//
struct decodeUINT { // Structure associates
UINT Code; // messages
// with a function.
LRESULT (*Fxn)(HWND, UINT, WPARAM, LPARAM);
};
struct decodeCMD { // Structure associates
UINT Code; // menu IDs with a
LRESULT (*Fxn)(HWND, WORD, HWND, WORD); // function.
};
//----------------------------------------------------------------------
// Generic defines used by application
#define IDI_BTNICON 20 // Icon used on button
#define ID_ICON 1 // Icon ID
#define IDC_CMDBAR 2 // Command bar ID
#define IDC_RPTLIST 3 // Report window ID // Client window IDs go from 5 through 9.
#define IDC_WNDSEL 5 // Starting client
// window IDs // Radio button IDs go from 10 through 14.
#define IDC_RADIOBTNS 10 // Starting ID of
// radio buttons // Button window defines
#define IDC_PUSHBTN 100
#define IDC_CHKBOX 101
#define IDC_ACHKBOX 102
#define IDC_A3STBOX 103
#define IDC_RADIO1 104
#define IDC_RADIO2 105
#define IDC_OWNRDRAW 106 // Edit window defines
#define IDC_SINGLELINE 100
#define IDC_MULTILINE 101
#define IDC_PASSBOX 102 // List box window defines
#define IDC_COMBOBOX 100
#define IDC_SNGLELIST 101
#define IDC_MULTILIST 102 // Static control window defines
#define IDC_LEFTTEXT 100
#define IDC_RIGHTTEXT 101
#define IDC_CENTERTEXT 102
#define IDC_ICONCTL 103
#define IDC_BITMAPCTL 104
// Scroll bar window defines
#define IDC_LRSCROLL 100
#define IDC_UDSCROLL 101 // User-defined message to add a line to the window
#define MYMSG_ADDLINE (WM_USER + 10) typedef struct {
TCHAR *szClass;
INT nID;
TCHAR *szTitle;
INT x;
INT y;
INT cx;
INT cy;
DWORD lStyle;
} CTLWNDSTRUCT, *PCTLWNDSTRUCT; typedef struct {
WORD wMsg;
INT nID;
WPARAM wParam;
LPARAM lParam;
} CTLMSG, * PCTLMSG; typedef struct {
TCHAR *pszLabel;
WORD wNotification;
} NOTELABELS, *PNOTELABELS; //----------------------------------------------------------------------
// Function prototypes
//
int InitApp (HINSTANCE);
HWND InitInstance (HINSTANCE, LPWSTR, int);
int TermInstance (HINSTANCE, int); // Window procedures
LRESULT CALLBACK FrameWndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ClientWndProc (HWND, UINT, WPARAM, LPARAM); // Message handlers
LRESULT DoCreateFrame (HWND, UINT, WPARAM, LPARAM);
LRESULT DoCommandFrame (HWND, UINT, WPARAM, LPARAM);
LRESULT DoAddLineFrame (HWND, UINT, WPARAM, LPARAM);
LRESULT DoDestroyFrame (HWND, UINT, WPARAM, LPARAM); //----------------------------------------------------------------------
// Window prototypes and defines for BtnWnd
//
#define BTNWND TEXT ("ButtonWnd")
int InitBtnWnd (HINSTANCE); // Window procedures
LRESULT CALLBACK BtnWndProc (HWND, UINT, WPARAM, LPARAM); LRESULT DoCreateBtnWnd (HWND, UINT, WPARAM, LPARAM);
LRESULT DoCtlColorBtnWnd (HWND, UINT, WPARAM, LPARAM);
LRESULT DoCommandBtnWnd (HWND, UINT, WPARAM, LPARAM);
LRESULT DoDrawItemBtnWnd (HWND, UINT, WPARAM, LPARAM);
LRESULT DoMeasureItemBtnWnd (HWND, UINT, WPARAM, LPARAM); //----------------------------------------------------------------------
// Window prototypes and defines for EditWnd
//
#define EDITWND TEXT ("EditWnd")
int InitEditWnd (HINSTANCE); // Window procedures
LRESULT CALLBACK EditWndProc (HWND, UINT, WPARAM, LPARAM); LRESULT DoCreateEditWnd (HWND, UINT, WPARAM, LPARAM);
LRESULT DoCommandEditWnd (HWND, UINT, WPARAM, LPARAM);
LRESULT DoDrawItemEditWnd (HWND, UINT, WPARAM, LPARAM);
LRESULT DoMeasureItemEditWnd (HWND, UINT, WPARAM, LPARAM); //----------------------------------------------------------------------
// Window prototypes and defines for ListWnd
//
#define LISTWND TEXT ("ListWnd")
int InitListWnd (HINSTANCE); // Window procedures
LRESULT CALLBACK ListWndProc (HWND, UINT, WPARAM, LPARAM); LRESULT DoCreateListWnd (HWND, UINT, WPARAM, LPARAM);
LRESULT DoCommandListWnd (HWND, UINT, WPARAM, LPARAM);
LRESULT DoDrawItemListWnd (HWND, UINT, WPARAM, LPARAM);
LRESULT DoMeasureItemListWnd (HWND, UINT, WPARAM, LPARAM); //----------------------------------------------------------------------
// Window prototypes and defines for StatWnd
//
#define STATWND TEXT ("StaticWnd")
int InitStatWnd (HINSTANCE); // Window procedures
LRESULT CALLBACK StatWndProc (HWND, UINT, WPARAM, LPARAM); LRESULT DoCreateStatWnd (HWND, UINT, WPARAM, LPARAM);
LRESULT DoCommandStatWnd (HWND, UINT, WPARAM, LPARAM);
LRESULT DoDrawItemStatWnd (HWND, UINT, WPARAM, LPARAM);
LRESULT DoMeasureItemStatWnd (HWND, UINT, WPARAM, LPARAM); //----------------------------------------------------------------------
// Window prototypes and defines ScrollWnd
//
#define SCROLLWND TEXT ("ScrollWnd")
int InitScrollWnd (HINSTANCE); // Window procedures
LRESULT CALLBACK ScrollWndProc (HWND, UINT, WPARAM, LPARAM); LRESULT DoCreateScrollWnd (HWND, UINT, WPARAM, LPARAM);
LRESULT DoVScrollScrollWnd (HWND, UINT, WPARAM, LPARAM);
LRESULT DoHScrollScrollWnd (HWND, UINT, WPARAM, LPARAM); CtlView.c //======================================================================
// CtlView - Lists the available fonts in the system.
//
// Written for the book Programming Windows CE // Copyright (C) 2001 Douglas Boling
//======================================================================
#include <windows.h> // For all that Windows stuff
#include <commctrl.h> // Command bar includes
#include "CtlView.h" // Program-specific stuff //----------------------------------------------------------------------
// Global data
//
const TCHAR szAppName[] = TEXT ("CtlView");
HINSTANCE hInst; // Program instance handle // Message dispatch table for FrameWindowProc
const struct decodeUINT FrameMessages[] = {
WM_CREATE, DoCreateFrame,
WM_COMMAND, DoCommandFrame,
MYMSG_ADDLINE, DoAddLineFrame,
WM_DESTROY, DoDestroyFrame,
}; typedef struct {
TCHAR *szTitle;
INT nID;
TCHAR *szCtlWnds;
HWND hWndClient;
} RBTNDATA; // Text for main window radio buttons
TCHAR *szBtnTitle[] = {TEXT ("Buttons"), TEXT ("Edit"), TEXT ("List"),
TEXT ("Static"), TEXT ("Scroll")};
// Class names for child windows containing controls
TCHAR *szCtlWnds[] = {BTNWND, EDITWND, LISTWND, STATWND, SCROLLWND}; INT nWndSel = ; //======================================================================
// Program entry point
//
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPWSTR lpCmdLine, int nCmdShow) {
MSG msg;
int rc = ;
HWND hwndFrame; // Initialize application.
rc = InitApp (hInstance);
if (rc) return rc; // Initialize this instance.
hwndFrame = InitInstance (hInstance, lpCmdLine, nCmdShow);
if (hwndFrame == )
return 0x10; // Application message loop
while (GetMessage (&msg, NULL, , )) {
TranslateMessage (&msg);
DispatchMessage (&msg);
}
// Instance cleanup
return TermInstance (hInstance, msg.wParam);
}
//----------------------------------------------------------------------
// InitApp - Application initialization
//
int InitApp (HINSTANCE hInstance) {
WNDCLASS wc; #if defined(WIN32_PLATFORM_PSPC)
// If Pocket PC, allow only one instance of the application
HWND hWnd = FindWindow (szAppName, NULL);
if (hWnd) {
SetForegroundWindow ((HWND)(((DWORD)hWnd) | 0x01));
return -;
}
#endif
// Register application frame window class.
wc.style = ; // Window style
wc.lpfnWndProc = FrameWndProc; // Callback function
wc.cbClsExtra = ; // Extra class data
wc.cbWndExtra = ; // Extra window data
wc.hInstance = hInstance; // Owner handle
wc.hIcon = NULL, // Application icon
wc.hCursor = LoadCursor (NULL, IDC_ARROW);// Default cursor
wc.hbrBackground = (HBRUSH) GetSysColorBrush (COLOR_STATIC);
wc.lpszMenuName = NULL; // Menu name
wc.lpszClassName = szAppName; // Window class name if (RegisterClass (&wc) == ) return ; // Initialize client window classes
if (InitBtnWnd (hInstance) != ) return ;
if (InitEditWnd (hInstance) != ) return ;
if (InitListWnd (hInstance) != ) return ;
if (InitStatWnd (hInstance) != ) return ; if (InitScrollWnd (hInstance) != ) return ;
return ;
}
//----------------------------------------------------------------------
// InitInstance - Instance initialization
//
HWND InitInstance (HINSTANCE hInstance, LPWSTR lpCmdLine, int nCmdShow) {
HWND hWnd; // Save program instance handle in global variable.
hInst = hInstance; // Create frame window.
hWnd = CreateWindow (szAppName, TEXT ("Control View"), WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
// Return fail code if window not created.
if (!IsWindow (hWnd)) return ; // Standard show and update calls
ShowWindow (hWnd, nCmdShow);
UpdateWindow (hWnd); return hWnd;
}
//----------------------------------------------------------------------
// TermInstance - Program cleanup
//
int TermInstance (HINSTANCE hInstance, int nDefRC) { return nDefRC;
}
//======================================================================
// Message handling procedures for FrameWindow
//
//----------------------------------------------------------------------
// FrameWndProc - Callback function for application window
//
LRESULT CALLBACK FrameWndProc (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
INT i;
//
// Search message list to see if we need to handle this
// message. If in list, call procedure.
//
for (i = ; i < dim(FrameMessages); i++) {
if (wMsg == FrameMessages[i].Code) return (*FrameMessages[i].Fxn)(hWnd, wMsg, wParam, lParam);
}
return DefWindowProc (hWnd, wMsg, wParam, lParam);
}
//----------------------------------------------------------------------
// DoCreateFrame - Process WM_CREATE message for window.
//
LRESULT DoCreateFrame (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
LPCREATESTRUCT lpcs;
HWND hwndCB, hwndChild;
INT sHeight, i, x, y, cx, cy;
BOOL bWide = TRUE;
// These arrays are used to adjust between wide and narrow screens.
POINT ptRBtnsN[] = {{,}, {,}, {,}, {,}, {,}};
POINT ptRBtnsW[] = {{,}, {,}, {,}, {,}, {,}};
LPPOINT pptRbtns = ptRBtnsW; // Convert lParam into pointer to create struct.
lpcs = (LPCREATESTRUCT) lParam; // Set currently viewed window
nWndSel = ;
// Create a command bar, and add an exit button.
hwndCB = CommandBar_Create (hInst, hWnd, IDC_CMDBAR);
CommandBar_AddAdornments (hwndCB, , );
sHeight = CommandBar_Height (GetDlgItem (hWnd, IDC_CMDBAR)); // Use different layouts for narrow (Pocket PC) screens.
if (GetSystemMetrics (SM_CXSCREEN) < ) {
pptRbtns = ptRBtnsN;
bWide = FALSE;
}
// Create the radio buttons.
for (i = ; i < dim(szBtnTitle); i++) {
hwndChild = CreateWindow (TEXT ("BUTTON"),
szBtnTitle[i], BS_AUTORADIOBUTTON |
WS_VISIBLE | WS_CHILD, pptRbtns[i].x,
pptRbtns[i].y + sHeight, , , hWnd,
(HMENU)(IDC_RADIOBTNS+i), hInst, NULL); // Destroy frame if window not created.
if (!IsWindow (hwndChild)) {
DestroyWindow (hWnd);
break;
}
} // Create report window. Size it so that it fits either on the right
// or below the control windows, depending on the size of the screen.
x = bWide ? lpcs->cx/ : lpcs->x;
y = bWide ? sHeight + : (lpcs->cy-sHeight)/+sHeight + ;
cx = bWide ? lpcs->cx/ : lpcs->cx;
cy = bWide ? lpcs->cy - sHeight : lpcs->cy - y; hwndChild = CreateWindowEx (WS_EX_CLIENTEDGE, TEXT ("listbox"),
TEXT (""), WS_VISIBLE | WS_CHILD | WS_VSCROLL |
LBS_USETABSTOPS | LBS_NOINTEGRALHEIGHT, x, y,
cx, cy,hWnd, (HMENU)IDC_RPTLIST, hInst, NULL); // Destroy frame if window not created.
if (!IsWindow (hwndChild)) {
DestroyWindow (hWnd);
return ;
}
// Initialize tab stops for display list box.
i = ;
SendMessage (hwndChild, LB_SETTABSTOPS, , (LPARAM)&i); // Create the child windows. Size them so that they fit under
// the command bar and fill the left side of the child area.
x = lpcs->x;
y = bWide ? sHeight + : sHeight + ;
cx = bWide ? lpcs->cx/ : lpcs->cx;
cy = bWide ? lpcs->cy - sHeight : (lpcs->cy-sHeight)/+sHeight+; for (i = ; i < dim(szCtlWnds); i++) {
hwndChild = CreateWindowEx (WS_EX_CLIENTEDGE, szCtlWnds[i],
TEXT (""), WS_CHILD, x, y, cx, cy, hWnd,
(HMENU)(IDC_WNDSEL+i), hInst, NULL); // Destroy frame if client window not created.
if (!IsWindow (hwndChild)) {
DestroyWindow (hWnd);
return ;
}
}
// Check one of the auto radio buttons.
SendDlgItemMessage (hWnd, IDC_RADIOBTNS+nWndSel, BM_SETCHECK, , );
hwndChild = GetDlgItem (hWnd, IDC_WNDSEL+nWndSel);
ShowWindow (hwndChild, SW_SHOW);
return ;
}
//----------------------------------------------------------------------
// DoCommandFrame - Process WM_COMMAND message for window.
// LRESULT DoCommandFrame (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
HWND hwndTemp;
int nBtn;
// Don't look at list box messages.
if (LOWORD (wParam) == IDC_RPTLIST)
return ;
nBtn = LOWORD (wParam) - IDC_RADIOBTNS;
if (nWndSel != nBtn) { // Hide the currently visible window.
hwndTemp = GetDlgItem (hWnd, IDC_WNDSEL+nWndSel);
ShowWindow (hwndTemp, SW_HIDE); // Save the current selection.
nWndSel = nBtn;
// Show the window selected via the radio button.
hwndTemp = GetDlgItem (hWnd, IDC_WNDSEL+nWndSel);
ShowWindow (hwndTemp, SW_SHOW);
}
return ;
}
//----------------------------------------------------------------------
// DoAddLineFrame - Process MYMSG_ADDLINE message for window.
//
LRESULT DoAddLineFrame (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
TCHAR szOut[];
INT i; if (LOWORD (wParam) == 0xffff)
wsprintf (szOut, TEXT (" \t %s"), (LPTSTR)lParam);
else
wsprintf (szOut, TEXT ("id:%3d \t %s"), LOWORD (wParam),
(LPTSTR)lParam); i = SendDlgItemMessage (hWnd, IDC_RPTLIST, LB_ADDSTRING, ,
(LPARAM)(LPCTSTR)szOut); if (i != LB_ERR)
SendDlgItemMessage (hWnd, IDC_RPTLIST, LB_SETTOPINDEX, i,
(LPARAM)(LPCTSTR)szOut);
return ;
} //----------------------------------------------------------------------
// DoDestroyFrame - Process WM_DESTROY message for window.
//
LRESULT DoDestroyFrame (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
PostQuitMessage ();
return ;
} BtnWnd.c //======================================================================
// BtnWnd - Button window code
//
// Written for the book Programming Windows CE
// Copyright (C) 2001 Douglas Boling
//======================================================================
#include <windows.h> // For all that Windows stuff
#include "Ctlview.h" // Program-specific stuff extern HINSTANCE hInst; LRESULT DrawButton (HWND hWnd, LPDRAWITEMSTRUCT pdi);
//----------------------------------------------------------------------
// Global data
// // Message dispatch table for BtnWndWindowProc
const struct decodeUINT BtnWndMessages[] = {
WM_CREATE, DoCreateBtnWnd,
WM_CTLCOLORSTATIC, DoCtlColorBtnWnd,
WM_COMMAND, DoCommandBtnWnd,
WM_DRAWITEM, DoDrawItemBtnWnd,
}; // Structure defining the controls in the window
CTLWNDSTRUCT Btns [] = {
{TEXT ("BUTTON"), IDC_PUSHBTN, TEXT ("Button"),
, , , , BS_PUSHBUTTON | BS_NOTIFY},
{TEXT ("BUTTON"), IDC_CHKBOX, TEXT ("Check box"),
, , , , BS_CHECKBOX},
{TEXT ("BUTTON"), IDC_ACHKBOX, TEXT ("Auto check box"),
, , , , BS_AUTOCHECKBOX},
{TEXT ("BUTTON"), IDC_A3STBOX, TEXT ("Multiline auto 3-state box"),
, , , , BS_AUTO3STATE | BS_MULTILINE},
{TEXT ("BUTTON"), IDC_RADIO1, TEXT ("Auto radio button 1"),
, , , , BS_AUTORADIOBUTTON}, {TEXT ("BUTTON"), IDC_RADIO2, TEXT ("Auto radio button 2"),
, , , , BS_AUTORADIOBUTTON},
{TEXT ("BUTTON"), IDC_OWNRDRAW, TEXT ("OwnerDraw"),
, , , , BS_PUSHBUTTON | BS_OWNERDRAW},
};
// Structure labeling the button control WM_COMMAND notifications
NOTELABELS nlBtn[] = {{TEXT ("BN_CLICKED "), },
{TEXT ("BN_PAINT "), },
{TEXT ("BN_HILITE "), },
{TEXT ("BN_UNHILITE"), },
{TEXT ("BN_DISABLE "), },
{TEXT ("BN_DOUBLECLICKED"), },
{TEXT ("BN_SETFOCUS "), },
{TEXT ("BN_KILLFOCUS"), }
};
// Handle for icon used in owner-draw icon
HICON hIcon = ;
//----------------------------------------------------------------------
// InitBtnWnd - BtnWnd window initialization
//
int InitBtnWnd (HINSTANCE hInstance) {
WNDCLASS wc; // Register application BtnWnd window class.
wc.style = ; // Window style
wc.lpfnWndProc = BtnWndProc; // Callback function
wc.cbClsExtra = ; // Extra class data
wc.cbWndExtra = ; // Extra window data
wc.hInstance = hInstance; // Owner handle
wc.hIcon = NULL, // Application icon
wc.hCursor = LoadCursor (NULL, IDC_ARROW);// Default cursor
wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wc.lpszMenuName = NULL; // Menu name
wc.lpszClassName = BTNWND; // Window class name if (RegisterClass (&wc) == ) return ; return ;
} //======================================================================
// Message handling procedures for BtnWindow
//----------------------------------------------------------------------
// BtnWndWndProc - Callback function for application window
// LRESULT CALLBACK BtnWndProc (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
INT i;
//
// Search message list to see if we need to handle this
// message. If in list, call procedure.
//
for (i = ; i < dim(BtnWndMessages); i++) {
if (wMsg == BtnWndMessages[i].Code)
return (*BtnWndMessages[i].Fxn)(hWnd, wMsg, wParam, lParam);
}
return DefWindowProc (hWnd, wMsg, wParam, lParam);
}
//----------------------------------------------------------------------
// DoCreateBtnWnd - Process WM_CREATE message for window.
//
LRESULT DoCreateBtnWnd (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
INT i; for (i = ; i < dim(Btns); i++) { CreateWindow (Btns[i].szClass, Btns[i].szTitle,
Btns[i].lStyle | WS_VISIBLE | WS_CHILD,
Btns[i].x, Btns[i].y, Btns[i].cx, Btns[i].cy,
hWnd, (HMENU) Btns[i].nID, hInst, NULL);
}
hIcon = LoadIcon (hInst, TEXT ("TEXTICON")); // We need to set the initial state of the radio buttons.
CheckRadioButton (hWnd, IDC_RADIO1, IDC_RADIO2, IDC_RADIO1);
return ;
}
//----------------------------------------------------------------------
// DoCtlColorBtnWnd - process WM_CTLCOLORxx messages for window.
//
LRESULT DoCtlColorBtnWnd (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
return (LRESULT)GetStockObject (WHITE_BRUSH);
}
//----------------------------------------------------------------------
// DoCommandBtnWnd - Process WM_COMMAND message for window.
//
LRESULT DoCommandBtnWnd (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
TCHAR szOut[];
INT i; // Since the Check Box button is not an auto check box, it
// must be set manually.
if ((LOWORD (wParam) == IDC_CHKBOX) &&
(HIWORD (wParam) == BN_CLICKED)) {
// Get the current state, complement, and set.
i = SendDlgItemMessage (hWnd, IDC_CHKBOX, BM_GETCHECK, , );
if (i == )
SendDlgItemMessage (hWnd, IDC_CHKBOX, BM_SETCHECK, , );
else
SendDlgItemMessage (hWnd, IDC_CHKBOX, BM_SETCHECK, , );
} // Report WM_COMMAND messages to main window.
for (i = ; i < dim(nlBtn); i++) {
if (HIWORD (wParam) == nlBtn[i].wNotification) {
lstrcpy (szOut, nlBtn[i].pszLabel);
break;
}
}
if (i == dim(nlBtn))
wsprintf (szOut, TEXT ("notification: %x"), HIWORD (wParam)); SendMessage (GetParent (hWnd), MYMSG_ADDLINE, wParam,
(LPARAM)szOut);
return ;
}
//----------------------------------------------------------------------
// DoDrawItemBtnWnd - Process WM_DRAWITEM message for window.
//
LRESULT DoDrawItemBtnWnd (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) { return DrawButton (hWnd, (LPDRAWITEMSTRUCT)lParam);
} //---------------------------------------------------------------------
// DrawButton - Draws an owner-draw button
//
LRESULT DrawButton (HWND hWnd, LPDRAWITEMSTRUCT pdi) { HPEN hPenShadow, hPenLight, hPenDkShadow, hOldPen; HBRUSH hBr, hOldBr;
LOGPEN lpen;
TCHAR szOut[];
POINT ptOut[], ptIn[]; // Reflect the messages to the report window.
wsprintf (szOut, TEXT ("WM_DRAWITEM Act:%x State:%x"),
pdi->itemAction, pdi->itemState);
SendMessage (GetParent (hWnd), MYMSG_ADDLINE, pdi->CtlID,
(LPARAM)szOut); // Create pens for drawing.
lpen.lopnStyle = PS_SOLID;
lpen.lopnWidth.x = ;
lpen.lopnWidth.y = ;
lpen.lopnColor = GetSysColor (COLOR_3DSHADOW);
hPenShadow = CreatePenIndirect (&lpen); lpen.lopnWidth.x = ;
lpen.lopnWidth.y = ;
lpen.lopnColor = GetSysColor (COLOR_3DLIGHT);
hPenLight = CreatePenIndirect (&lpen); lpen.lopnColor = GetSysColor (COLOR_3DDKSHADOW);
hPenDkShadow = CreatePenIndirect (&lpen); // Create a brush for the face of the button.
hBr = CreateSolidBrush (GetSysColor (COLOR_3DFACE)); // Draw a rectangle with a thick outside border to start the
// frame drawing.
hOldPen = SelectObject (pdi->hDC, hPenShadow);
hOldBr = SelectObject (pdi->hDC, hBr);
Rectangle (pdi->hDC, pdi->rcItem.left, pdi->rcItem.top,
pdi->rcItem.right, pdi->rcItem.bottom); // Draw the upper left inside line.
ptIn[].x = pdi->rcItem.left + ;
ptIn[].y = pdi->rcItem.bottom - ;
ptIn[].x = pdi->rcItem.left + ;
ptIn[].y = pdi->rcItem.top + ;
ptIn[].x = pdi->rcItem.right - ;
ptIn[].y = pdi->rcItem.top + ; // Select a pen to draw shadow or light side of button.
if (pdi->itemState & ODS_SELECTED) {
SelectObject (pdi->hDC, hPenDkShadow);
} else {
SelectObject (pdi->hDC, hPenLight);
}
Polyline (pdi->hDC, ptIn, ); // If selected, also draw a bright line inside the lower
// right corner.
if (pdi->itemState & ODS_SELECTED) {
SelectObject (pdi->hDC, hPenLight);
ptIn[].x = pdi->rcItem.right - ;
ptIn[].y = pdi->rcItem.bottom - ;
Polyline (pdi->hDC, ptIn, );
} // Now draw the black outside line on either the upper left or lower
// right corner.
ptOut[].x = pdi->rcItem.left;
ptOut[].y = pdi->rcItem.bottom - ;
ptOut[].x = pdi->rcItem.right - ;
ptOut[].y = pdi->rcItem.top; SelectObject (pdi->hDC, hPenDkShadow);
if (pdi->itemState & ODS_SELECTED) {
ptOut[].x = pdi->rcItem.left;
ptOut[].y = pdi->rcItem.top;
} else {
ptOut[].x = pdi->rcItem.right - ;
ptOut[].y = pdi->rcItem.bottom - ;
}
Polyline (pdi->hDC, ptOut, ); // Draw the icon.
if (hIcon) {
ptIn[].x = (pdi->rcItem.right - pdi->rcItem.left)/ -
GetSystemMetrics (SM_CXICON)/ - ;
ptIn[].y = (pdi->rcItem.bottom - pdi->rcItem.top)/ -
GetSystemMetrics (SM_CYICON)/ - ;
// If pressed, shift image down one pel to simulate depress.
if (pdi->itemState & ODS_SELECTED) {
ptOut[].x += ;
ptOut[].y += ;
}
DrawIcon (pdi->hDC, ptIn[].x, ptIn[].y, hIcon);
} // If button has the focus, draw the dotted rect inside the button.
if (pdi->itemState & ODS_FOCUS) {
pdi->rcItem.left += ;
pdi->rcItem.top += ;
pdi->rcItem.right -= ;
pdi->rcItem.bottom -= ;
DrawFocusRect (pdi->hDC, &pdi->rcItem);
} // Clean up. First select the original brush and pen into the DC.
SelectObject (pdi->hDC, hOldBr);
SelectObject (pdi->hDC, hOldPen); // Now delete the brushes and pens created.
DeleteObject (hBr);
DeleteObject (hPenShadow);
DeleteObject (hPenDkShadow);
DeleteObject (hPenLight);
return ;
} EditWnd.c //======================================================================
// EditWnd - Edit control window code
//
// Written for the book Programming Windows CE
// Copyright (C) 2001 Douglas Boling
//======================================================================
#include <windows.h> // For all that Windows stuff
#include "Ctlview.h" // Program-specific stuff extern HINSTANCE hInst;
//----------------------------------------------------------------------
// Global data
//
// Message dispatch table for EditWndWindowProc
const struct decodeUINT EditWndMessages[] = {
WM_CREATE, DoCreateEditWnd,
WM_COMMAND, DoCommandEditWnd,
}; // Structure defining the controls in the window
CTLWNDSTRUCT Edits[] = {
{TEXT ("edit"), IDC_SINGLELINE, TEXT ("Single line edit control"),
, , , , ES_AUTOHSCROLL}, {TEXT ("edit"), IDC_MULTILINE, TEXT ("Multiline edit control"),
, , , , ES_MULTILINE | ES_AUTOVSCROLL}, {TEXT ("edit"), IDC_PASSBOX, TEXT (""),
, , , , ES_PASSWORD},
};
// Structure labeling the edit control WM_COMMAND notifications
NOTELABELS nlEdit[] = {{TEXT ("EN_SETFOCUS "), 0x0100},
{TEXT ("EN_KILLFOCUS"), 0x0200},
{TEXT ("EN_CHANGE "), 0x0300}, {TEXT ("EN_UPDATE "), 0x0400},
{TEXT ("EN_ERRSPACE "), 0x0500},
{TEXT ("EN_MAXTEXT "), 0x0501},
{TEXT ("EN_HSCROLL "), 0x0601},
{TEXT ("EN_VSCROLL "), 0x0602},
};
//----------------------------------------------------------------------
// InitEditWnd - EditWnd window initialization
//
int InitEditWnd (HINSTANCE hInstance) {
WNDCLASS wc; // Register application EditWnd window class.
wc.style = ; // Window style
wc.lpfnWndProc = EditWndProc; // Callback function
wc.cbClsExtra = ; // Extra class data
wc.cbWndExtra = ; // Extra window data
wc.hInstance = hInstance; // Owner handle
wc.hIcon = NULL, // Application icon
wc.hCursor = LoadCursor (NULL, IDC_ARROW);// Default cursor
wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wc.lpszMenuName = NULL; // Menu name
wc.lpszClassName = EDITWND; // Window class name if (RegisterClass (&wc) == ) return ; return ;
}
//======================================================================
// Message handling procedures for EditWindow
//----------------------------------------------------------------------
// EditWndWndProc - Callback function for application window
//
LRESULT CALLBACK EditWndProc (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
INT i;
//
// Search message list to see if we need to handle this
// message. If in list, call procedure.
//
for (i = ; i < dim(EditWndMessages); i++) {
if (wMsg == EditWndMessages[i].Code)
return (*EditWndMessages[i].Fxn)(hWnd, wMsg, wParam, lParam);
}
return DefWindowProc (hWnd, wMsg, wParam, lParam);
} //----------------------------------------------------------------------
// DoCreateEditWnd - Process WM_CREATE message for window.
//
LRESULT DoCreateEditWnd (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
INT i; for (i = ; i < dim(Edits); i++) { CreateWindow (Edits[i].szClass, Edits[i].szTitle,
Edits[i].lStyle | WS_VISIBLE | WS_CHILD | WS_BORDER,
Edits[i].x, Edits[i].y, Edits[i].cx, Edits[i].cy,
hWnd, (HMENU) Edits[i].nID, hInst, NULL);
}
return ;
}
//----------------------------------------------------------------------
// DoCommandEditWnd - Process WM_COMMAND message for window.
//
LRESULT DoCommandEditWnd (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
TCHAR szOut[];
INT i; for (i = ; i < dim(nlEdit); i++) {
if (HIWORD (wParam) == nlEdit[i].wNotification) {
lstrcpy (szOut, nlEdit[i].pszLabel);
break;
}
} if (i == dim(nlEdit))
wsprintf (szOut, TEXT ("notification: %x"), HIWORD (wParam)); SendMessage (GetParent (hWnd), MYMSG_ADDLINE, wParam,
(LPARAM)szOut);
return ;
} ListWnd.c //======================================================================
// ListWnd - List box control window code
//
// Written for the book Programming Windows CE
// Copyright (C) 2001 Douglas Boling //======================================================================
#include <windows.h> // For all that Windows stuff
#include "Ctlview.h" // Program-specific stuff extern HINSTANCE hInst;
//----------------------------------------------------------------------
// Global data
//
// Message dispatch table for ListWndWindowProc
const struct decodeUINT ListWndMessages[] = {
WM_CREATE, DoCreateListWnd,
WM_COMMAND, DoCommandListWnd,
}; // Structure defining the controls in the window
CTLWNDSTRUCT Lists[] = {
{TEXT ("combobox"), IDC_COMBOBOX, TEXT (""), , , , ,
WS_VSCROLL}, {TEXT ("Listbox"), IDC_SNGLELIST, TEXT (""), , , , ,
WS_VSCROLL | LBS_NOTIFY}, {TEXT ("Listbox"), IDC_MULTILIST, TEXT (""), , , , ,
WS_VSCROLL | LBS_EXTENDEDSEL | LBS_NOTIFY}
};
// Structure labeling the list box control WM_COMMAND notifications
NOTELABELS nlList[] = {{TEXT ("LBN_ERRSPACE "), (-)},
{TEXT ("LBN_SELCHANGE"), },
{TEXT ("LBN_DBLCLK "), },
{TEXT ("LBN_SELCANCEL"), },
{TEXT ("LBN_SETFOCUS "), },
{TEXT ("LBN_KILLFOCUS"), },
};
// Structure labeling the combo box control WM_COMMAND notifications
NOTELABELS nlCombo[] = {{TEXT ("CBN_ERRSPACE "), (-)},
{TEXT ("CBN_SELCHANGE "), },
{TEXT ("CBN_DBLCLK "), },
{TEXT ("CBN_SETFOCUS "), },
{TEXT ("CBN_KILLFOCUS "), },
{TEXT ("CBN_EDITCHANGE "), },
{TEXT ("CBN_EDITUPDATE "), },
{TEXT ("CBN_DROPDOWN "), },
{TEXT ("CBN_CLOSEUP "), },
{TEXT ("CBN_SELENDOK "), },
{TEXT ("CBN_SELENDCANCEL"), },
}; //----------------------------------------------------------------------
// InitListWnd - ListWnd window initialization
//
int InitListWnd (HINSTANCE hInstance) {
WNDCLASS wc; // Register application ListWnd window class.
wc.style = ; // Window style
wc.lpfnWndProc = ListWndProc; // Callback function
wc.cbClsExtra = ; // Extra class data
wc.cbWndExtra = ; // Extra window data
wc.hInstance = hInstance; // Owner handle
wc.hIcon = NULL, // Application icon
wc.hCursor = LoadCursor (NULL, IDC_ARROW); // Default cursor
wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wc.lpszMenuName = NULL; // Menu name
wc.lpszClassName = LISTWND; // Window class name if (RegisterClass (&wc) == ) return ; return ;
}
//======================================================================
// Message handling procedures for ListWindow
//----------------------------------------------------------------------
// ListWndProc - Callback function for application window
//
LRESULT CALLBACK ListWndProc (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
INT i;
//
// Search message list to see if we need to handle this
// message. If in list, call procedure.
//
for (i = ; i < dim(ListWndMessages); i++) {
if (wMsg == ListWndMessages[i].Code)
return (*ListWndMessages[i].Fxn)(hWnd, wMsg, wParam, lParam);
}
return DefWindowProc (hWnd, wMsg, wParam, lParam);
}
//----------------------------------------------------------------------
// DoCreateListWnd - Process WM_CREATE message for window.
//
LRESULT DoCreateListWnd (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
INT i;
TCHAR szOut[]; for (i = ; i < dim(Lists); i++) { CreateWindow (Lists[i].szClass, Lists[i].szTitle,
Lists[i].lStyle | WS_VISIBLE | WS_CHILD | WS_BORDER,
Lists[i].x, Lists[i].y, Lists[i].cx, Lists[i].cy,
hWnd, (HMENU) Lists[i].nID, hInst, NULL);
}
for (i = ; i < ; i++) {
wsprintf (szOut, TEXT ("Item %d"), i);
SendDlgItemMessage (hWnd, IDC_SNGLELIST, LB_ADDSTRING, ,
(LPARAM)szOut); SendDlgItemMessage (hWnd, IDC_MULTILIST, LB_ADDSTRING, ,
(LPARAM)szOut); SendDlgItemMessage (hWnd, IDC_COMBOBOX, CB_ADDSTRING, ,
(LPARAM)szOut);
}
// Set initial selection.
SendDlgItemMessage (hWnd, IDC_COMBOBOX, CB_SETCURSEL, , );
return ;
}
//----------------------------------------------------------------------
// DoCommandListWnd - Process WM_COMMAND message for window.
//
LRESULT DoCommandListWnd (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
TCHAR szOut[];
INT i; if (LOWORD (wParam) == IDC_COMBOBOX) {
for (i = ; i < dim(nlCombo); i++) {
if (HIWORD (wParam) == nlCombo[i].wNotification) {
lstrcpy (szOut, nlCombo[i].pszLabel);
break;
}
}
if (i == dim(nlList))
wsprintf (szOut, TEXT ("notification: %x"), HIWORD (wParam));
} else {
for (i = ; i < dim(nlList); i++) {
if (HIWORD (wParam) == nlList[i].wNotification) {
lstrcpy (szOut, nlList[i].pszLabel);
break;
}
} if (i == dim(nlList))
wsprintf (szOut, TEXT ("notification: %x"), HIWORD (wParam));
}
SendMessage (GetParent (hWnd), MYMSG_ADDLINE, wParam,
(LPARAM)szOut);
return ;
} StatWnd.c //======================================================================
// StatWnd - Static control window code
//
// Written for the book Programming Windows CE
// Copyright (C) 2001 Douglas Boling
//======================================================================
#include <windows.h> // For all that Windows stuff
#include "Ctlview.h" // Program-specific stuff extern HINSTANCE hInst;
//----------------------------------------------------------------------
// Global data
//
// Message dispatch table for StatWndWindowProc
const struct decodeUINT StatWndMessages[] = {
WM_CREATE, DoCreateStatWnd,
WM_COMMAND, DoCommandStatWnd,
}; // Structure defining the controls in the window
CTLWNDSTRUCT Stats [] = {
{TEXT ("static"), IDC_LEFTTEXT, TEXT ("Left text"),
, , , , SS_LEFT | SS_NOTIFY}, {TEXT ("static"), IDC_RIGHTTEXT, TEXT ("Right text"),
, , , , SS_RIGHT}, {TEXT ("static"), IDC_CENTERTEXT, TEXT ("Center text"),
, , , , SS_CENTER | WS_BORDER}, {TEXT ("static"), IDC_ICONCTL, TEXT ("TEXTICON"),
, , , , SS_ICON}, {TEXT ("static"), IDC_BITMAPCTL, TEXT ("STATICBMP"),
, , , , SS_BITMAP | SS_NOTIFY},
}; // Structure labeling the static control WM_COMMAND notifications
NOTELABELS nlStatic[] = {{TEXT ("STN_CLICKED"), },
{TEXT ("STN_ENABLE "), },
{TEXT ("STN_DISABLE"), },
};
//----------------------------------------------------------------------
// InitStatWnd - StatWnd window initialization
//
int InitStatWnd (HINSTANCE hInstance) {
WNDCLASS wc; // Register application StatWnd window class.
wc.style = ; // Window style
wc.lpfnWndProc = StatWndProc; // Callback function
wc.cbClsExtra = ; // Extra class data
wc.cbWndExtra = ; // Extra window data
wc.hInstance = hInstance; // Owner handle
wc.hIcon = NULL, // Application icon
wc.hCursor = LoadCursor (NULL, IDC_ARROW);// Default cursor
wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wc.lpszMenuName = NULL; // Menu name
wc.lpszClassName = STATWND; // Window class name if (RegisterClass (&wc) == ) return ; return ;
}
//======================================================================
// Message handling procedures for StatWindow
//----------------------------------------------------------------------
// StatWndProc - Callback function for application window
//
LRESULT CALLBACK StatWndProc (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
INT i;
//
// Search message list to see if we need to handle this
// message. If in list, call procedure.
//
for (i = ; i < dim(StatWndMessages); i++) {
if (wMsg == StatWndMessages[i].Code)
return (*StatWndMessages[i].Fxn)(hWnd, wMsg, wParam, lParam);
}
return DefWindowProc (hWnd, wMsg, wParam, lParam);
} //----------------------------------------------------------------------
// DoCreateStatWnd - Process WM_CREATE message for window.
//
LRESULT DoCreateStatWnd (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
INT i; for (i = ; i < dim(Stats); i++) { CreateWindow (Stats[i].szClass, Stats[i].szTitle,
Stats[i].lStyle | WS_VISIBLE | WS_CHILD,
Stats[i].x, Stats[i].y, Stats[i].cx, Stats[i].cy,
hWnd, (HMENU) Stats[i].nID, hInst, NULL);
}
return ;
}
//----------------------------------------------------------------------
// DoCommandStatWnd - Process WM_COMMAND message for window.
//
LRESULT DoCommandStatWnd (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
TCHAR szOut[];
INT i; for (i = ; i < dim(nlStatic); i++) {
if (HIWORD (wParam) == nlStatic[i].wNotification) {
lstrcpy (szOut, nlStatic[i].pszLabel);
break;
}
}
if (i == dim(nlStatic))
wsprintf (szOut, TEXT ("notification: %x"), HIWORD (wParam)); SendMessage (GetParent (hWnd), MYMSG_ADDLINE, wParam,
(LPARAM)szOut);
return ;
} ScrollWnd.c //======================================================================
// ScrollWnd - Scroll bar control window code
//
// Written for the book Programming Windows CE
// Copyright (C) 2001 Douglas Boling
//====================================================================== #include <windows.h> // For all that Windows stuff
#include "Ctlview.h" // Program-specific stuff extern HINSTANCE hInst;
//----------------------------------------------------------------------
// Global data
//
// Message dispatch table for ScrollWndWindowProc
const struct decodeUINT ScrollWndMessages[] = {
WM_CREATE, DoCreateScrollWnd,
WM_HSCROLL, DoVScrollScrollWnd,
WM_VSCROLL, DoVScrollScrollWnd,
}; // Structure defining the controls in the window
CTLWNDSTRUCT Scrolls [] = {
{TEXT ("Scroll bar"), IDC_LRSCROLL, TEXT (""),
, , , , SBS_HORZ}, {TEXT ("Scroll bar"), IDC_UDSCROLL, TEXT (""),
, , , , SBS_VERT},
}; // Structure labeling the scroll bar control scroll codes for WM_VSCROLL
NOTELABELS nlVScroll[] = {{TEXT ("SB_LINEUP "), },
{TEXT ("SB_LINEDOWN "), },
{TEXT ("SB_PAGEUP "), },
{TEXT ("SB_PAGEDOWN "), },
{TEXT ("SB_THUMBPOSITION"), },
{TEXT ("SB_THUMBTRACK "), },
{TEXT ("SB_TOP "), },
{TEXT ("SB_BOTTOM "), },
{TEXT ("SB_ENDSCROLL "), },
};
// Structure labeling the scroll bar control scroll codes for WM_HSCROLL
NOTELABELS nlHScroll[] = {{TEXT ("SB_LINELEFT "), },
{TEXT ("SB_LINERIGHT "), },
{TEXT ("SB_PAGELEFT "), },
{TEXT ("SB_PAGERIGHT "), },
{TEXT ("SB_THUMBPOSITION"), },
{TEXT ("SB_THUMBTRACK "), },
{TEXT ("SB_LEFT "), },
{TEXT ("SB_RIGHT "), },
{TEXT ("SB_ENDSCROLL "), },
}; //----------------------------------------------------------------------
// InitScrollWnd - ScrollWnd window initialization
//
int InitScrollWnd (HINSTANCE hInstance) {
WNDCLASS wc; // Register application ScrollWnd window class.
wc.style = ; // Window style
wc.lpfnWndProc = ScrollWndProc; // Callback function
wc.cbClsExtra = ; // Extra class data
wc.cbWndExtra = ; // Extra window data
wc.hInstance = hInstance; // Owner handle
wc.hIcon = NULL, // Application icon
wc.hCursor = LoadCursor (NULL, IDC_ARROW);// Default cursor
wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wc.lpszMenuName = NULL; // Menu name
wc.lpszClassName = SCROLLWND; // Window class name if (RegisterClass (&wc) == ) return ; return ;
}
//======================================================================
// Message handling procedures for ScrollWindow
//----------------------------------------------------------------------
// ScrollWndProc - Callback function for application window
//
LRESULT CALLBACK ScrollWndProc (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
INT i;
//
// Search message list to see if we need to handle this
// message. If in list, call procedure.
//
for (i = ; i < dim(ScrollWndMessages); i++) {
if (wMsg == ScrollWndMessages[i].Code)
return (*ScrollWndMessages[i].Fxn)(hWnd, wMsg, wParam, lParam);
}
return DefWindowProc (hWnd, wMsg, wParam, lParam);
}
//----------------------------------------------------------------------
// DoCreateScrollWnd - Process WM_CREATE message for window.
//
LRESULT DoCreateScrollWnd (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
INT i; for (i = ; i < dim(Scrolls); i++) {
CreateWindow (Scrolls[i].szClass, Scrolls[i].szTitle,
Scrolls[i].lStyle | WS_VISIBLE | WS_CHILD,
Scrolls[i].x, Scrolls[i].y, Scrolls[i].cx,
Scrolls[i].cy,
hWnd, (HMENU) Scrolls[i].nID, hInst, NULL);
}
return ;
}
//----------------------------------------------------------------------
// DoVScrollScrollWnd - Process WM_VSCROLL message for window.
//
LRESULT DoVScrollScrollWnd (HWND hWnd, UINT wMsg, WPARAM wParam,
LPARAM lParam) {
TCHAR szOut[];
SCROLLINFO si;
INT i, sPos; // Update the report window.
if (GetDlgItem (hWnd, ) == (HWND)lParam) { for (i = ; i < dim(nlVScroll); i++) {
if (LOWORD (wParam) == nlVScroll[i].wNotification) {
lstrcpy (szOut, nlVScroll[i].pszLabel);
break;
}
}
if (i == dim(nlVScroll))
wsprintf (szOut, TEXT ("notification: %x"), HIWORD (wParam));
} else {
for (i = ; i < dim(nlHScroll); i++) {
if (LOWORD (wParam) == nlHScroll[i].wNotification) {
lstrcpy (szOut, nlHScroll[i].pszLabel);
break;
}
}
if (i == dim(nlHScroll))
wsprintf (szOut, TEXT ("notification: %x"), HIWORD (wParam));
}
SendMessage (GetParent (hWnd), MYMSG_ADDLINE, -, (LPARAM)szOut); // Get scroll bar position.
si.cbSize = sizeof (si);
si.fMask = SIF_POS;
GetScrollInfo ((HWND)lParam, SB_CTL, &si);
sPos = si.nPos; // Act on the scroll code.
switch (LOWORD (wParam)) {
case SB_LINEUP: // Also SB_LINELEFT
sPos -= ;
break;
case SB_LINEDOWN: // Also SB_LINERIGHT
sPos += ;
break; case SB_PAGEUP: // Also SB_PAGELEFT
sPos -= ;
break; case SB_PAGEDOWN: // Also SB_PAGERIGHT
sPos += ;
break; case SB_THUMBPOSITION:
sPos = HIWORD (wParam);
break;
}
// Check range.
if (sPos < )
sPos = ;
if (sPos > )
sPos = ; // Update scroll bar position.
si.cbSize = sizeof (si);
si.nPos = sPos;
si.fMask = SIF_POS;
SetScrollInfo ((HWND)lParam, SB_CTL, &si, TRUE);
return ;
}Buttons
- MFC Windows programming


- One simple examples
#include <windows.h>
LONG WINAPI WndProc (HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
WNDCLASS wc;
HWND hwnd;
MSG msg; wc.style = 0; // Class style
wc.lpfnWndProc = (WNDPROC) WndProc; // Window procedure address
wc.cbClsExtra = 0; // Class extra bytes
wc.cbWndExtra = 0; // Window extra bytes
wc.hInstance = hInstance; // Instance handle
wc.hIcon = LoadIcon (NULL, IDI_WINLOGO); // Icon handle
wc.hCursor = LoadCursor (NULL, IDC_ARROW); // Cursor handle
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1); // Background color
wc.lpszMenuName = NULL; // Menu name
wc.lpszClassName = "MyWndClass"; // WNDCLASS name RegisterClass (&wc); hwnd = CreateWindow (
"MyWndClass", // WNDCLASS name
"SDK Application", // Window title
WS_OVERLAPPEDWINDOW, // Window style
CW_USEDEFAULT, // Horizontal position
CW_USEDEFAULT, // Vertical position
CW_USEDEFAULT, // Initial width
CW_USEDEFAULT, // Initial height
HWND_DESKTOP, // Handle of parent window
NULL, // Menu handle
hInstance, // Application's instance handle
NULL // Window-creation data
); ShowWindow (hwnd, nCmdShow);
UpdateWindow (hwnd); while (GetMessage (&msg, NULL, 0, 0)) {
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
} LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc; switch (message) {
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps);
Ellipse (hdc, 0, 0, 200, 100);
EndPaint (hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam);
}

Eclipse SWT的更多相关文章
- Eclipse swt开发环境搭建
原料: eclipse swt.下载链接为: Eclipse 4.6.2 Release Build: 4.6.2 配置说明: Developing SWT applications using Ec ...
- org.eclipse.swt.custom.StyledText.getScrollbarsMode()I
错误: org.eclipse.swt.custom.StyledText.getScrollbarsMode()I 解决方法: 1 卸载,并手工清除myeclipse全部文件 2 重新安装myecl ...
- 报错:org.eclipse.swt.SWTError: No more handles at org.eclipse.swt.SWT.error(SWT.java:4517)
在Mars.Kepler的版本裡,時常會出現以下錯誤導致eclipse無法進行運作 Error.log org.eclipse.swt.SWTError: No more handles at ...
- 解决ubuntu 14.04 下eclipse 3.7.2 不能启动,报Could not detect registered XULRunner to use 或 org.eclipse.swt.SWTError: XPCOM 等问题的处理
对于eclipse 3.7.2在ubuntu 14.04下不能启动,需要在 eclipse/configuration 目录下的config.ini文件内增加一行org.eclipse.swt.bro ...
- org.eclipse.swt.SWTException: Invalid thread access问题解决方法
转自 http://blog.csdn.net/ecjtuxuan/article/details/2125023 怎么解决SWT多线程错误:Caused by: org.eclipse.swt.SW ...
- myeclipse启动错误:org.eclipse.swt.SWTError: No more handles
myeclipse启动错误,生成日志: !SESSION 2014-11-06 09:13:16.296 ----------------------------------------------- ...
- 解决Eclipse异常关闭后重启报 org.eclipse.swt.SWTException: Invalid thread access 的问题
. . . . . 很久没有写博客了,最近实在是太忙,一直想写点干货,但是一直没静下心来学习. 今天又在加班忙碌之中,结果谁知道越忙碌越出问题.先是 weblogic 没有正常启动,凭经验第一反应就是 ...
- eclipse报这个错误org.eclipse.swt.SWTError: No more handles (eclipse 和 TeamViewer 冲突)
错误: org.eclipse.swt.SWTError: No more handles at org.eclipse.swt.SWT.error(SWT.java:4387) a ...
- org.eclipse.e4.core.di.InjectionException:org.eclipse.swt.SWTException: Widget is disposed
org.eclipse.e4.core.di.InjectionException:org.eclipse.swt.SWTException: Widget is disposed 开发环境为ecli ...
随机推荐
- Qt 学习之路 2(51):布尔表达式树模型
Qt 学习之路 2(51):布尔表达式树模型 豆子 2013年5月15日 Qt 学习之路 2 17条评论 本章将会是自定义模型的最后一部分.原本打算结束这部分内容,不过实在不忍心放弃这个示例.来自于 ...
- R语言学习笔记(四)
6. 数据转换 本章主要讲述apply系列函数:apply.lapply.sapply.tapply.mapply,以及姊妹函数by.split.适用于批量处理数据,而不许循环. 6.1 向量分组 用 ...
- C++_标准模板库STL概念介绍5-其他库与总结
C++还提供了其他一些类库,这些类库更加专用. 例如,头文件complex为复数提供了类模板complex,包含用于float.long和long double的具体化. 这个类提供了标准的复数运算以 ...
- BZOJ - 2005 莫比乌斯水题
\(gcd=k+1\)时,每一个的贡献都是\(2k+1\) \(gcd=1\)时,每一个贡献为\(1\) #include<iostream> #include<algorithm& ...
- SQL 每行随机产生数字
Id,Amount) from Customer
- vue点击tab跳转页面,给点击的tab添加样式,且解决刷新以后点击的tab样式消失问题
<ul class="nij"> <li v-for="item in nav" @click="selectNav(item.ti ...
- PIE SDK创建掩膜
1.算法功能简介 图像掩膜(Mask)用选定的图像.图形或物体,对处理的图像(全部或局部)进行遮挡,来控制图像处理的区域或处理过程.掩膜是一种图像滤镜的模板,实用掩膜经常处理的是遥感图像.当提取道 ...
- Docker:网络模式详解
Docker作为目前最火的轻量级容器技术,牛逼的功能,如Docker的镜像管理,不足的地方网络方面. Docker自身的4种网络工作方式,和一些自定义网络模式 安装Docker时,它会自动创建三个网络 ...
- oracle 基础知识(一)
Oracle 用户.权限.角色管理 01.概念 用户:对数据库的访问需要以适当的身份通过验证,这就是用户的作用:每个Oracle用户都有自己的用户名和密码,并且拥有他们所创建的任意表.视图和其他资源, ...
- linux运维配置讲解--sshd-config
文件配置: 1, /etc/ssh/sshd_config ssh配置文件 2, /etc/shadow 密码文件 3, /etc/sudoers 授权用户管理文件 4, /etc/issue 系统信 ...