论坛: 编程破解 标题: 哪位帮忙看看下面代码出了什么问题SDK->ListView 复制本贴地址    
作者: battle [battle]    论坛用户   登录
#include <windows.h>
#include <commctrl.h>
#pragma comment(lib, "comctl32.lib")

#define ID_LISTVIEW  2000
HWND hwndListViewswq;
char frameclass[] = "Frame";

LRESULT CALLBACK FrameProc(HWND hWnd,UINT Message,WPARAM wParam,LPARAM lParam);

HWND CreateHotelListView(HWND hWnd);

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstnace,LPSTR lpCmdLine,int iCmdShow)
{
WNDCLASS Wndclass;
MSG msg;
HWND hWndFrame;
HACCEL hAccel;

Wndclass.style = CS_HREDRAW | CS_VREDRAW;
Wndclass.cbClsExtra = 0;
Wndclass.cbWndExtra = 0;
Wndclass.hInstance = hInstance;
Wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
Wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
Wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
Wndclass.lpszMenuName = NULL;
Wndclass.lpszClassName = frameclass;
Wndclass.lpfnWndProc = FrameProc;

if(!RegisterClass(&Wndclass))
return 0;
hWndFrame = CreateWindow(frameclass,
frameclass,
WS_OVERLAPPEDWINDOW,
0,0,
650,
500,
NULL,
NULL,
hInstance,
NULL);

ShowWindow(hWndFrame,iCmdShow);
UpdateWindow(hWndFrame);

hAccel = LoadAccelerators(hInstance,frameclass);

while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}

LRESULT CALLBACK FrameProc(HWND hWnd,UINT Message,WPARAM wParam,LPARAM lParam)
{
switch(Message)
{
case WM_CREATE:
hwndListViewswq = CreateHotelListView(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd,Message,wParam,lParam);
}


HWND CreateHotelListView(HWND hWnd)
{
hwndListViewswq = CreateWindowEx(WS_EX_CLIENTEDGE,
  WC_LISTVIEW,
  "",
  WS_TABSTOP |
WS_CHILD |
WS_VISIBLE |
LVS_REPORT |
LVS_OWNERDATA|
LVS_NOSORTHEADER|
LVS_SORTASCENDING,
  0,0,300,200,
  hWnd,
  (HMENU)ID_LISTVIEW,
  (HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE),
  NULL);
LV_COLUMN  lvColumn;
int        i;
TCHAR      szString[3][20] = {"用户名","编号", "网速"};

ListView_DeleteAllItems(hwndListViewswq);

lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvColumn.fmt = LVCFMT_LEFT;
lvColumn.cx = 70;
for(i = 0; i < 3; i++)
{
  lvColumn.pszText = szString[i];
  ListView_InsertColumn(hwndListViewswq, i, &lvColumn);
}
return hwndListViewswq;
}


运行成功..为什么看不到listview视图...郁闷啊..

地主 发表时间: 05-04-25 17:58

回复: battle [battle]   论坛用户   登录
上面的问题已经解决...顺便把代码贴出来分享下
#include <windows.h>
#include <commctrl.h>
#pragma comment(lib, "comctl32.lib")

#define ID_LISTVIEW  2000
HWND hwndListViewswq;
char frameclass[] = "Frame";

LRESULT CALLBACK FrameProc(HWND hWnd,UINT Message,WPARAM wParam,LPARAM lParam);

HWND CreateHotelListView(HWND hWnd);

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstnace,LPSTR lpCmdLine,int iCmdShow)
{
WNDCLASS Wndclass;
MSG msg;
HWND hWndFrame;
HACCEL hAccel;

Wndclass.style = CS_HREDRAW | CS_VREDRAW;
Wndclass.cbClsExtra = 0;
Wndclass.cbWndExtra = 0;
Wndclass.hInstance = hInstance;
Wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
Wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
Wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
Wndclass.lpszMenuName = NULL;
Wndclass.lpszClassName = frameclass;
Wndclass.lpfnWndProc = FrameProc;

if(!RegisterClass(&Wndclass))
return 0;
hWndFrame = CreateWindow(frameclass,
frameclass,
WS_OVERLAPPEDWINDOW,
0,0,
650,
500,
NULL,
NULL,
hInstance,
NULL);

ShowWindow(hWndFrame,iCmdShow);
UpdateWindow(hWndFrame);
InitCommonControls();  //必须先初始化 控件吧

hAccel = LoadAccelerators(hInstance,frameclass);

while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}

LRESULT CALLBACK FrameProc(HWND hWnd,UINT Message,WPARAM wParam,LPARAM lParam)
{
switch(Message)
{
case WM_CREATE:
hwndListViewswq = CreateHotelListView(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd,Message,wParam,lParam);
}


HWND CreateHotelListView(HWND hWnd)
{
hwndListViewswq = CreateWindowEx(WS_EX_CLIENTEDGE, //创建的lisview视图   WC_LISTVIEW,   "",
      WS_TABSTOP |
WS_CHILD |
WS_VISIBLE |
LVS_REPORT,
  0,0,300,200,
  hWnd,
  NULL,
  (HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE),
  NULL);
ListView_SetExtendedListViewStyle(hwndListViewswq,LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);//设置样式

LV_COLUMN  lvcol;
          lvcol.mask =LVCF_TEXT;
          //  ;
            lvcol.pszText = "Resource Name"; //这个是列名
            ListView_InsertColumn(hwndListViewswq, 0, &lvcol); //添加列
            ListView_SetColumnWidth(hwndListViewswq, 0, 100); //设置列宽度

            lvcol.mask =LVCF_TEXT;
            lvcol.pszText = "Resource Type";
            ListView_InsertColumn(hwndListViewswq, 1, &lvcol);
            ListView_SetColumnWidth(hwndListViewswq, 1, 110);


        LVITEM lvi;
        lvi.mask = LVIF_TEXT;
        lvi.state = LVIS_SELECTED ;
        lvi.stateMask = 0;
        lvi.iItem = 0;
        lvi.iSubItem = 0;
        lvi.pszText = "";

char *name = "trojan";
int i = ListView_InsertItem(hwndListViewswq,&lvi); //这个是添加数据
            ListView_SetItemText(hwndListViewswq, i, 0, name);//第一列
            ListView_SetItemText(hwndListViewswq, i, 1, name);//第二列

return hwndListViewswq;
}

B1层 发表时间: 05-04-26 01:59

回复: 286 [unique]   版主   登录
你要是能把排错过程,想法,错误原因分析都写出来,你的贴子就完美了。

B2层 发表时间: 05-04-26 09:10

回复: jhkdiy [jhkdiy]   版主   登录
恩, InitCommonControls(); 这个函数很害人。


[此贴被 jhkdiy(jhkdiy) 在 04月26日14时02分 编辑过]

B3层 发表时间: 05-04-26 14:01

回复: battle [battle]   论坛用户   登录
我就是在MSDN里面找资料,,问别人....在自己试...这么多函数没事的时候就自己试阿..

我还有个问题..
用SDK创建的框..怎么设置它的字体样式大小....??

B4层 发表时间: 05-04-26 23:38

回复: jhkdiy [jhkdiy]   版主   登录
我在MSDN里找过,但一时找不到如何设置列表框的字体。期待高手解答。

B5层 发表时间: 05-04-27 14:04

论坛: 编程破解

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号