|
Creating a Combo-box Toolbar
Following are the window procedure for the toolbar and the subclass procedure
for the two combo boxes.
#define WM_TAB (WM_USER)
#define WM_ESC (WM_USER + 1)
#define WM_ENTER (WM_USER + 2)
HWND hwndMain;
HWND hwndEdit;
WNDPROC lpfnEditWndProc; /* original window procedure for */
/* the combo box edit windows */
int cyToolbar; /* toolbar window height */
/********************************************************
FUNCTION: ToolbarWindowProc
PURPOSE: Window procedure for the toolbar window
- *******************************************************/
LRESULT CALLBACK ToolbarWindowProc(hwnd, msg, wParam, lParam)
HWND hwnd;
UINT msg;
WPARAM wParam;
LPARAM lParam;
{
static HWND hwndEdit1;
static HWND hwndEdit2;
static HWND hwndCombo1;
static HWND hwndCombo2;
.
.
.
POINT pt;
DWORD dwBaseUnits;
HWND hwndCombo;
DWORD dwIndex;
switch (msg) {
case WM_CREATE:
/* Create two combo box child windows. */
dwBaseUnits = GetDialogBaseUnits();
hwndCombo1 = CreateWindow("COMBOBOX", "",
CBS_DROPDOWN | WS_CHILD | WS_VISIBLE,
(6 * LOWORD(dwBaseUnits)) / 4,
(2 * HIWORD(dwBaseUnits)) / 8,
(100 * LOWORD(dwBaseUnits)) / 4,
(50 * HIWORD(dwBaseUnits)) / 8,
hwnd, NULL, hinst, NULL);
hwndCombo2 = CreateWindow("COMBOBOX", "",
CBS_DROPDOWN | WS_CHILD | WS_VISIBLE,
(112 * LOWORD(dwBaseUnits)) / 4,
(2 * HIWORD(dwBaseUnits)) / 8,
(100 * LOWORD(dwBaseUnits)) / 4,
(50 * HIWORD(dwBaseUnits)) / 8,
hwnd, NULL, hinst, NULL);
/* Get the edit window handle for each combo box. */
pt.x = 1;
pt.y = 1;
hwndEdit1 = ChildWindowFromPoint(hwndCombo1, pt);
hwndEdit2 = ChildWindowFromPoint(hwndCombo2, pt);
/*
* Change the window procedure for both edit windows
* to the subclass procedure.
*/
lpfnEditWndProc = (WNDPROC) SetWindowLong(hwndEdit1,
GWL_WNDPROC, (DWORD) SubClassProc);
SetWindowLong(hwndEdit2, GWL_WNDPROC,
(DWORD) SubClassProc);
break;
case WM_SETFOCUS:
SetFocus(hwndCombo1);
break;
case WM_TAB:
if (GetFocus() == hwndEdit1)
SetFocus(hwndCombo2);
else
SetFocus(hwndCombo1);
break;
case WM_ESC:
hwndCombo = GetFocus() == hwndEdit1 ?
hwndCombo1 : hwndCombo2;
/* Clear the current selection. */
SendMessage(hwndCombo, CB_SETCURSEL,
(WPARAM) (-1), 0);
/* Set the focus to the main window. */
SetFocus(hwndMain);
break;
case WM_ENTER:
hwndCombo = GetFocus() == hwndEdit1 ?
hwndCombo1 : hwndCombo2;
SetFocus(hwndMain);
/* If there is no current selection, set one. */
if (SendMessage(hwndCombo, CB_GETCURSEL, 0, 0)
== CB_ERR) {
if (SendMessage(hwndCombo, WM_GETTEXT,
sizeof(achTemp), (LPARAM) achTemp) == 0)
break; /* empty selection field */
dwIndex = SendMessage(hwndCombo,
CB_FINDSTRINGEXACT, (WPARAM) (-1),
(LPARAM) achTemp);
/* Add the string, if necessary, and select it. */
if (dwIndex == CB_ERR)
dwIndex = SendMessage(hwndCombo, CB_ADDSTRING,
0, (LPARAM) achTemp);
if (dwIndex != CB_ERR)
SendMessage(hwndCombo, CB_SETCURSEL,
dwIndex, 0);
}
break;
.
. /* Process additional messages. */
.
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
/********************************************************
FUNCTION: SubClassProc
PURPOSE: Process TAB and ESCAPE keys, and pass all
other messages to the class window
procedure.
- *******************************************************/
LRESULT CALLBACK SubClassProc(hwnd, msg, wParam, lParam)
HWND hwnd;
UINT msg;
WPARAM wParam;
LPARAM lParam;
{
switch (msg) {
case WM_KEYDOWN:
switch (wParam) {
case VK_TAB:
SendMessage(hwndToolbar, WM_TAB, 0, 0);
return 0;
case VK_ESCAPE:
SendMessage(hwndToolbar, WM_ESC, 0, 0);
return 0;
case VK_RETURN:
SendMessage(hwndToolbar, WM_ENTER, 0, 0);
return 0;
}
break;
case WM_KEYUP:
case WM_CHAR:
switch (wParam) {
case VK_TAB:
case VK_ESCAPE:
case VK_RETURN:
return 0;
}
}
/*
* Call the original window procedure for default
* processing.
*/
return CallWindowProc(lpfnEditWndProc, hwnd,
msg, wParam, lParam);
}
| Last news from Greatis Software |
 |
|
Nostalgia .Net |
|
.Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes. More » |
| Recommended software for developers |
 |
|
Ultimate Pack |
|
Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price. More » |
 |
|
Form Designer .Net |
|
Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro! More » |
 |
|
Print Suite .Net |
|
Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available More » |
 |
|
Gradient Controls .Net |
|
Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available More » |
 |
|
Greatis iGrid |
|
iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors. More » |
All the contacts and projectsDmitry Vasiliev (just.dmitry)
Related LinksSoftware for Visual Studio .NET developers Software for Delphi and C++ Builder developers Software for Visual Basic 6 developers Delphi Tips&Tricks MegaDetailed.NET More Online Helps Win32 Programmer's Reference Win32 Multimedia Programmer's Reference OLE Programmer's Reference Microsoft Windows Pen API Programmer's Reference Microsoft Windows Sockets 2 Reference Microsoft Windows Telephony API (TAPI) Programmer's Reference Unix Manual Pages
|