关于一个list的问题

bigwolf23 bigwolf23 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include <windows.h>

#define ID_LIST 1

#define ID_TEXT 2


LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;


int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,

PSTR szCmdLine, int iCmdShow)

{

static TCHAR szAppName[] = TEXT ("Environ") ;

HWND hwnd ;

MSG msg ;

WNDCLASS wndclass ;



wndclass.style = CS_HREDRAW | CS_VREDRAW ;

wndclass.lpfnWndProc = WndProc ;

wndclass.cbClsExtra = 0 ;

wndclass.cbWndExtra = 0 ;

wndclass.hInstance = hInstance ;

wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;

wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;

wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1) ;

wndclass.lpszMenuName = NULL ;

wndclass.lpszClassName = szAppName ;



if (!RegisterClass (&wndclass))

{

MessageBox ( NULL, TEXT ("This program requires Windows NT!"),

szAppName, MB_ICONERROR) ;

return 0 ;

}



hwnd = CreateWindow (szAppName, TEXT ("Environment List Box"),

WS_OVERLAPPEDWINDOW,

CW_USEDEFAULT, CW_USEDEFAULT,

CW_USEDEFAULT, CW_USEDEFAULT,

NULL, NULL, hInstance, NULL) ;



ShowWindow (hwnd, iCmdShow) ;

UpdateWindow (hwnd) ;



while (GetMessage (&msg, NULL, 0, 0))

{

TranslateMessage (&msg) ;

DispatchMessage (&msg) ;

}

return msg.wParam ;

}


void FillListBox (HWND hwndList)

{

int iLength ;

TCHAR * pVarBlock, * pVarBeg, * pVarEnd, * pVarName ;


pVarBlock = GetEnvironmentStrings () ; // Get pointer to environment block


//pingyb
SendMessage(hwndList, LB_SETITEMHEIGHT , 0, 20);//¸Ä±ä¼ä¾à


while (*pVarBlock)

{

if (*pVarBlock != '=') // Skip variable names beginning with '='

{

pVarBeg = pVarBlock ; // Beginning of variable name

while (*pVarBlock++ != '=') ; // Scan until '='

pVarEnd = pVarBlock - 1 ; // Points to '=' sign

iLength = pVarEnd - pVarBeg ; // Length of variable name


// Allocate memory for the variable name and terminating

// zero. Copy the variable name and append a zero.


pVarName = calloc (iLength + 1, sizeof (TCHAR)) ;

CopyMemory (pVarName, pVarBeg, iLength * sizeof (TCHAR)) ;

pVarName[iLength] = '\0' ;


// Put the variable name in the list box and free memory.

SendMessage (hwndList, LB_ADDSTRING, 0, (LPARAM) pVarName) ;

free (pVarName) ;

}

while (*pVarBlock++ != '\0') ; // Scan until terminating zero

}

FreeEnvironmentStrings (pVarBlock) ;

}


LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,LPARAM lParam)

{

static HWND hwndList, hwndText ;

int iIndex, iLength, cxChar, cyChar ;

TCHAR * pVarName, * pVarValue ;


switch (message)

{

case WM_CREATE :

cxChar = LOWORD (GetDialogBaseUnits ()) ;

cyChar = HIWORD (GetDialogBaseUnits ()) ;

// Create listbox and static text windows.


hwndList = CreateWindow (TEXT ("listbox"), NULL,

WS_CHILD | WS_VISIBLE | LBS_DISABLENOSCROLL ,

cxChar, cyChar * 3,

cxChar * 16 + GetSystemMetrics (SM_CXVSCROLL),

cyChar * 10,

hwnd, (HMENU) ID_LIST,

(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE),

NULL) ;



hwndText = CreateWindow (TEXT ("static"), NULL,

WS_CHILD | WS_VISIBLE | SS_LEFT,

cxChar, cyChar,

GetSystemMetrics (SM_CXSCREEN), cyChar,

hwnd, (HMENU) ID_TEXT,

(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE),

NULL) ;


FillListBox (hwndList) ;

return 0 ;



case WM_SETFOCUS :

SetFocus (hwndList) ;

return 0 ;

case WM_COMMAND :

if (LOWORD (wParam) == ID_LIST && HIWORD (wParam) == LBN_SELCHANGE)
//ID_LISTû¿´³ö×÷ÓÃÀ´
{// Get current selection.

iIndex = SendMessage (hwndList, LB_GETCURSEL, 0, 0) ;

iLength = SendMessage (hwndList, LB_GETTEXTLEN, iIndex, 0) + 1 ;

pVarName = calloc (iLength, sizeof (TCHAR)) ;

SendMessage (hwndList, LB_GETTEXT, iIndex, (LPARAM) pVarName) ;


// Get environment string.


iLength = GetEnvironmentVariable (pVarName, NULL, 0) ;

pVarValue = calloc (iLength, sizeof (TCHAR)) ;

GetEnvironmentVariable (pVarName, pVarValue, iLength) ;


// Show it in window.

SetWindowText (hwndText, pVarValue) ;

free (pVarName) ;

free (pVarValue) ;

}

return 0 ;


case WM_DESTROY :

PostQuitMessage (0) ;

return 0 ;

}

return DefWindowProc (hwnd, message, wParam, lParam) ;

}

这个程序是一个显示List的东西,用windows32和c语言编的,我会加按钮,但我想实现一个功能就是把选择的内容向下移动,请问如何做到
...全文

相关推荐

linked_list:一个星期的问题

对于这个"linked_list:一个星期的问题",可能涵盖了一些常见链表问题的解决方案,例如:- 链表的反转- 删除链表的倒数第N个节点- 检查链表中是否有环- 合并两个排序的链表- 判断链表的长度-

香港键师傅

使用Volley来写一个List列表(解决中文乱码问题)

在处理包含中文内容的网络请求时,可能会遇到乱码问题,这通常是因为编码设置不正确导致的。本篇文章将详细介绍如何使用Volley来创建一个显示中文内容的List列表,并解决中文乱码的问题。

移动爱好者

RecyclerviewLoadLists:一个Recyclerview加载多个list数据。多布局呈现,完美解决多层嵌套list数据的问题

本项目“RecyclerviewLoadLists”专注于解决在RecyclerView中加载多个列表数据以及处理多层嵌套list数据的问题,提供了一种优雅的解决方案。1.

PeterLee龍羿學長

list-change-and-binding-issues:在此存储库中,您将找到一个简单的应用程序(带有GUI),该应用程序可可视化有关绑定和列表属性更改的问题

列表更改和绑定问题在此存储库中,您将找到一个简单的应用程序(带有GUI),该应用程序可视化有关绑定和列表属性更改的问题。 在list_bindings包中,您将找到一个启动列表绑定应用程序的AppSt

仰光的瑞哥

解决JAVA遍历List集合,删除数据时出现的问题

例如,在遍历List集合时,我们删除了第一个元素,那么第二个元素就会移动到第一个位置,但是如果我们继续执行迭代操作,那么第二个元素就不会被处理。

weixin_38717843
评论
收藏 已收藏
分享
返回顶部
bigwolf23
C语言 70,040 成员 243,237 内容