// test the listbox creation and selection
// modified from BCX generated C code for Dev-C++
// a Dev-C++ tested Windows Application by vegaseat 04nov2004
#include <windows.h>
static HINSTANCE BCX_hInstance;
static int BCX_ScaleX;
static int BCX_ScaleY;
static char BCX_ClassName[2048]; // default size
static char text[2048];
static HWND Form1;
static HWND List1;
#define Show(Window) RedrawWindow(Window,0,0,0);ShowWindow(Window,SW_SHOW);
HWND BCX_Form(char*,int=0,int=0,int=250,int=150,int=0,int=0);
HWND BCX_Listbox(char*,HWND,int,int,int,int,int,int=0,int=-1);
void Center (HWND,HWND=0,HWND=0);
char* BCX_TmpStr(size_t);
void FormLoad (void);
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
void addLB (HWND, char *);
char * getLB (HWND);
// sample data for the list box
static char names[7][10]=
{
"Heidi", "Bertha", "Samantha", "Rubin",
"Frank", "Sandy", "Sunny"
};
// this is the standard windows main() function
int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrev,LPSTR CmdLine,int CmdShow)
{
WNDCLASS Wc;
MSG Msg;
// *****************************
strcpy(BCX_ClassName,"ListBox1");
// ***************************************
// Programmer has selected to use pixels
// ***************************************
BCX_ScaleX = 1; // for generic scaling
BCX_ScaleY = 1;
BCX_hInstance = hInst;
// ******************************************************
Wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
Wc.lpfnWndProc = WndProc;
Wc.cbClsExtra = 0;
Wc.cbWndExtra = 0;
Wc.hInstance = hInst;
Wc.hIcon = LoadIcon(NULL,IDI_WINLOGO);
Wc.hCursor = LoadCursor(NULL,IDC_ARROW);
Wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
Wc.lpszMenuName = NULL;
Wc.lpszClassName = BCX_ClassName;
RegisterClass(&Wc);
FormLoad();
// the event message loop
while(GetMessage(&Msg,NULL,0,0))
{
HWND hActiveWindow = GetActiveWindow();
if (!IsWindow(hActiveWindow) || !IsDialogMessage(hActiveWindow,&Msg))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
return Msg.wParam;
}
// circular storage for strings
char *BCX_TmpStr (size_t Bites)
{
static int StrCnt;
static char *StrFunc[2048];
StrCnt=(StrCnt + 1) & 2047;
if(StrFunc[StrCnt]) free (StrFunc[StrCnt]);
return StrFunc[StrCnt]=(char*)calloc(Bites+128,sizeof(char));
}
// center the form in the screen (really optional, for looks)
void Center (HWND hwnd, HWND Xhwnd, HWND Yhwnd)
{
RECT rect, rectP;
int x, y, width, height;
int screenwidth, screenheight;
if(Xhwnd==0)
{
RECT DesktopArea;
RECT rc;
SystemParametersInfo(SPI_GETWORKAREA,0,&DesktopArea,0);
GetWindowRect(hwnd,&rc);
SetWindowPos(hwnd,HWND_TOP,
((DesktopArea.right-DesktopArea.left)-(rc.right-rc.left))/2+
DesktopArea.left,((DesktopArea.bottom-DesktopArea.top)-
(rc.bottom-rc.top))/2 + DesktopArea.top,0,0,SWP_NOSIZE);
return;
}
GetWindowRect (hwnd,&rect);
GetWindowRect (Xhwnd,&rectP);
width = rect.right-rect.left;
x = ((rectP.right-rectP.left)-width)/2 + rectP.left;
if(Yhwnd==NULL)
{
height = rect.bottom-rect.top;
y = ((rectP.bottom-rectP.top)-height)/2 + rectP.top;
}
else
{
GetWindowRect(Yhwnd,&rectP);
height = rect.bottom-rect.top;
y = ((rectP.bottom-rectP.top)-height)/2+rectP.top;
}
screenwidth = GetSystemMetrics(SM_CXSCREEN);
screenheight = GetSystemMetrics(SM_CYSCREEN);
if ((x<0)) x=0;
if ((y<0)) y=0;
if ((x+width>screenwidth)) x = screenwidth-width;
if ((y+height>screenheight)) y = screenheight-height;
MoveWindow (hwnd, x, y, width, height, FALSE);
}
// create the windows form
HWND BCX_Form(char *Caption, int X, int Y, int W, int H, int Style, int Exstyle)
{
HWND A;
// assign a default style
if (!Style)
{
Style= WS_MINIMIZEBOX |
WS_SIZEBOX |
WS_CAPTION |
WS_MAXIMIZEBOX |
WS_POPUP |
WS_SYSMENU;
}
A = CreateWindowEx(Exstyle,BCX_ClassName,Caption,
Style,
X*BCX_ScaleX,
Y*BCX_ScaleY,
(4+W)*BCX_ScaleX,
(12+H)*BCX_ScaleY,
NULL,(HMENU)NULL,BCX_hInstance,NULL);
SendMessage(A,(UINT)WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT),
(LPARAM)MAKELPARAM(FALSE,0));
return A;
}
// create the list box with desired styles
HWND BCX_Listbox
(char* Text,HWND hWnd,int id,int X,int Y,int W,int H,int Style,int Exstyle)
{
HWND A;
// assign a default style if needed
if (!Style)
{
Style=LBS_STANDARD | WS_CHILD | WS_VISIBLE |
LBS_SORT | WS_VSCROLL | WS_TABSTOP;
}
if (Exstyle == -1)
{
Exstyle=WS_EX_CLIENTEDGE;
}
A = CreateWindowEx(Exstyle,"Listbox",NULL,Style,
X*BCX_ScaleX, Y*BCX_ScaleY, W*BCX_ScaleX, H*BCX_ScaleY,
hWnd,(HMENU)id,BCX_hInstance,NULL);
SendMessage(A,(UINT)WM_SETFONT,(WPARAM)GetStockObject
(DEFAULT_GUI_FONT),(LPARAM)MAKELPARAM(FALSE,0));
return A;
}
// the details for Form1 and List1 (corner,width,height)
void FormLoad (void)
{
static char A[2048];
memset(&A,0,sizeof(A));
static int k;
memset(&k,0,sizeof(k));
Form1=BCX_Form("Click on a name ...",0,0,260,200);
List1=BCX_Listbox("",Form1,1009,10,15,100,150);
for(k=0; k<=6; k+=1)
{
strcpy(A,(char*)names[k]);
addLB(List1,A);
}
Center(Form1); // optional
Show(Form1);
}
// standard windows message handling
LRESULT CALLBACK WndProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
while(1)
{
if (Msg==WM_COMMAND)
{
// list box item clicked (selected)
if (LOWORD(wParam)==1009)
{
if (HIWORD(wParam)==LBN_SELCHANGE)
{
strcpy(text,(char*)getLB(List1));
// just for test
Beep(400,500);
// selected item to form title
SetWindowText(Form1,text);
}
}
}
break;
}
// exit from the window form
if (Msg==WM_DESTROY)
{
UnregisterClass(BCX_ClassName,BCX_hInstance);
PostQuitMessage(0);
}
return DefWindowProc(hWnd,Msg,wParam,lParam);
}
// add a string to the listbox
void addLB (HWND idnr, char *ltext)
{
SendMessage(idnr,(UINT)LB_ADDSTRING,(WPARAM)0,(LPARAM)ltext);
}
// return selected listbox string
char * getLB (HWND idnr)
{
static int index;
memset(&index,0,sizeof(index));
static char buf[2048];
memset(&buf,0,sizeof(buf));
char *BCX_RetStr={0};
index=SendMessage(idnr,(UINT)LB_GETCURSEL,(WPARAM)0,(LPARAM)0);
SendMessage(idnr,(UINT)LB_GETTEXT,(WPARAM)index,(LPARAM)buf);
BCX_RetStr=BCX_TmpStr(strlen(buf));
strcpy(BCX_RetStr,buf);
return BCX_RetStr;
}
// *************************************************************
// Created with BCX -- The BASIC To C Translator (ver 5.02)
// BCX (c) 1999, 2000, 2001, 2002, 2003, 2004 by Kevin Diggins
// *
分享到:
相关推荐
Multiselect DropDown ListBox control for Web Applications。
ListBox的处理消息整理 基于MSDN的ListBoxD 处理消息
但一直没能实现,众里寻她千百度也没结果,现在应该差不多了,终于花了2、3天时间,给memo控件与listbox控件加上了背景图片,并自绘了他们的滚动条、光标、所选内容,同时,在memo中输入c++语言关键字,如int,char等...
ListBox中的使用示例,演示了在LisbBox中单选框的实现
打印预览列表框的程序
(C++)此代码在Windows Mobile平台下VS2005调试通过,实现了Listbox的简单功能。
该工程实现了可以显示多行内容的ToolTip的ListBox,继承CWnd实现了一个自定义的ToolTip类,再继承CListBox实现了一个自定义的ListBox类
WPF listBox 漂亮的listBOX
本程序为基于MFC对话框程序,使用VC6.0开发 程序功能如下: ...2、对listbox列表数据进行修改删除 3、利用基于赏罚的感知器算法训练判别函数 4、对已知样本进行分类 重点在于读取txt以及对listbox的操作部分
列表控件可以看作是功能增强的ListBox,它提供了四种风格,而且可以同时显示一列的多中属性值。MFC中使用CListCtrl类来封装列表控件的各种操作。
IntegralUI ListBox for .NET WinForms
一个在linux下开发的listBOX插件,可以实现类似于C#中LISTBOX的功能,调用方法和C#相似度高达90%+,源码可以自由修正,如果发现BUG请邮woairbxl@163.com
这个程序重写ListBox,可以改变列表的宽度、高度、颜色、字体大小等功能
vs2013下Listbox控件水平智能拉框
采用客户端绑定ListBox控件的数据源,进行客户端多选,用于选择数据记录操作多选操作的控件,客户端选择操作,简单方便。
Listbox的运用
1)添加一个listbox control 2)设置此控件属性:Has Strings : true owner draw : fix or variable selection : single 其他的属性随意。 3)为此控件添加变量,变量类型为类CColorListBox 4)接下来用...
WPF ListBox控件拖动Demo,利用鼠标拖动ListBox实现多选!
windows下的C++、win32实现listbox列表框自绘样例代码,代码简洁易懂。
c# Listbox自动滚动