看下我这个怎么销毁不了控件?

jiaerboy 2010-01-10 11:20:19
class control{
HINSTANCE hInst;
HWND hMainHwnd;



HWND hMenu;

HWND hListView_User;
HWND hStatusBar_User;
HWND hToolbar_User;
HWND hComboboxProvince_User;
HWND hComboboxCity_User;
HWND hComboboxDistrict_User;

public:
control(HWND hwndParent);
~control();
void DestroyCtr();
BOOL CreateMenu();
BOOL CreateUserCtr();
BOOL CreateGameCtr();
};
void control::DestroyCtr(){
DestroyWindow(hToolbar_User);
}
调用DestroyCtr销毁不了hToolbar_User
...全文
88 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiaerboy 2010-01-17
  • 打赏
  • 举报
回复
#include <commctrl.h>
#pragma comment(lib,"comctl32.lib")

#define IDM_USER 2000
#define IDM_GAME 2001
#define IDM_SET 2002

#define IDM_FIND 3000
#define IDM_DEL 3001
#define IDM_DIS 3002
#define IDM_END 3003

class control{
private:
HINSTANCE hInst;
HWND hMainHwnd;

HWND hMenu;

HWND hListView_User;
HWND hStatusBar_User;
HWND hToolbar_User;
HWND hComboboxProvince_User;
HWND hComboboxCity_User;
HWND hComboboxDistrict_User;

public:
control(HWND hwndParent);
~control();
void DestroyCtr();
BOOL CreateMenu();
BOOL CreateUserCtr();
BOOL CreateGameCtr();
};
#include "stdafx.h"
#include "resource.h"
#include "control.h"

control::control(HWND hwndParent){
hInst=GetModuleHandle(NULL);
hMainHwnd=hwndParent;
InitCommonControls();
}
control::~control(){
//
}
void control::DestroyCtr(){
DestroyWindow(hToolbar_User);
}
BOOL control::CreateMenu(){
const int numButtons = 3;
const int numImage = 3;
//创建toolbar
hMenu = CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
WS_CHILD | WS_VISIBLE | TBSTYLE_LIST ,
0, 0, 0, 0,
hMainHwnd,NULL,hInst, NULL);
if (hMenu == NULL)
{
return FALSE;
}
//创建toolbar图像列表
HIMAGELIST hImageList = ImageList_Create(
16, 16,
ILC_COLOR16 | ILC_MASK,
1, 1);
if (hImageList == NULL)
{
return FALSE;
}
for(int index=0; index<numImage ; index++)
{
HICON hicon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_USER + index));
ImageList_AddIcon(hImageList, hicon);
DestroyIcon(hicon);
}
SendMessage(hMenu, TB_SETIMAGELIST, (WPARAM)numImage,(LPARAM)hImageList);

//创建按钮
TBBUTTON tbButtons[numButtons] =
{
{ 0, IDM_USER, TBSTATE_ENABLED,TBSTYLE_BUTTON , {0}, 0, (INT_PTR)TEXT("用户管理") },
{ 1, IDM_GAME, TBSTATE_ENABLED,TBSTYLE_BUTTON , {0}, 0, (INT_PTR)TEXT("游戏管理")},
{ 2, IDM_SET, TBSTATE_ENABLED, TBSTYLE_BUTTON , {0}, 0, (INT_PTR)TEXT("系统设置")}
};
SendMessage(hMenu, TB_BUTTONSTRUCTSIZE,(WPARAM)sizeof(TBBUTTON), 0);
SendMessage(hMenu, TB_ADDBUTTONS, (WPARAM)numButtons,(LPARAM)&tbButtons);
SendMessage(hMenu, TB_AUTOSIZE, 0, 0);
return TRUE;
}

BOOL control::CreateUserCtr(){
RECT rect;
GetClientRect (hMainHwnd, &rect);
hListView_User = CreateWindow(WC_LISTVIEW,
"",
WS_CHILD | WS_VISIBLE | WS_BORDER | LVS_REPORT,
0,
60,
rect.right-rect.left,
rect.bottom-80,
hMainHwnd,
NULL,
hInst,
NULL);
if (hListView_User == NULL)
{
return FALSE;
}
hStatusBar_User = CreateWindow(STATUSCLASSNAME,
"",
WS_CHILD | WS_VISIBLE | CCS_BOTTOM ,
0,0,0,0,
hMainHwnd,
NULL,
hInst,
NULL);
if (hStatusBar_User == NULL)
{
return FALSE;
}
hToolbar_User = CreateWindow(TOOLBARCLASSNAME,
"",
WS_CHILD | WS_VISIBLE | CCS_NORESIZE | TBSTYLE_LIST ,
0,0,0,0,
hMainHwnd,
NULL,
hInst,
NULL);
if (hToolbar_User == NULL)
{
return FALSE;
}
#define numButton 5
TBBUTTON tbButtons[numButton] =
{
{ 300 , 0, TBSTATE_ENABLED,TBSTYLE_SEP , {0}, 0, -1 },
{ -2 , IDM_FIND, TBSTATE_ENABLED,TBSTYLE_AUTOSIZE , {0}, 0,(INT_PTR)TEXT("查找")},
{ -2 , IDM_DEL, TBSTATE_ENABLED, TBSTYLE_AUTOSIZE , {0}, 0,(INT_PTR)TEXT("删除")},
{ -2 , IDM_DIS, TBSTATE_ENABLED,TBSTYLE_AUTOSIZE , {0}, 0,(INT_PTR)TEXT("禁用")},
{ -2 , IDM_END, TBSTATE_ENABLED, TBSTYLE_AUTOSIZE , {0}, 0,(INT_PTR)TEXT("启用")}
};
SendMessage(hToolbar_User, TB_BUTTONSTRUCTSIZE,(WPARAM)sizeof(TBBUTTON), 0);
SendMessage(hToolbar_User, TB_ADDBUTTONS, (WPARAM)numButton,(LPARAM)&tbButtons);
MoveWindow(hToolbar_User,0,30,800,30,TRUE);
hComboboxProvince_User = CreateWindow("ComboBox",
"",
WS_CHILD | WS_VISIBLE | WS_VSCROLL |
CBS_DROPDOWNLIST | CBS_DISABLENOSCROLL,
0,0,0,0,
hToolbar_User,
NULL,
hInst,
NULL);
if (hComboboxProvince_User == NULL)
{
return FALSE;
}
MoveWindow(hComboboxProvince_User,0,2,100,300,TRUE);
hComboboxCity_User = CreateWindow("ComboBox",
"",
WS_CHILD | WS_VISIBLE | WS_VSCROLL |
CBS_DROPDOWNLIST | CBS_DISABLENOSCROLL,
0,0,0,0,
hToolbar_User,
NULL,
hInst,
NULL);
if (hComboboxCity_User == NULL)
{
return FALSE;
}
MoveWindow(hComboboxCity_User,100,2,100,300,TRUE);
hComboboxDistrict_User = CreateWindow("ComboBox",
"",
WS_CHILD | WS_VISIBLE | WS_VSCROLL |
CBS_DROPDOWNLIST | CBS_DISABLENOSCROLL,
0,0,0,0,
hToolbar_User,
NULL,
hInst,
NULL);
if (hComboboxDistrict_User == NULL)
{
return FALSE;
}
MoveWindow(hComboboxDistrict_User,200,2,100,300,TRUE);

return TRUE;
}
BOOL control::CreateGameCtr(){

return TRUE;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
control CreateCtr(hwnd);
switch(message)
{
case WM_CREATE:
{
CreateCtr.CreateMenu();
}
return 0;

case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDM_USER:
{
CreateCtr.CreateUserCtr();
}
break;
case IDM_GAME:
{
CreateCtr.DestroyCtr();这里这样调用可是消毁不了对应的窗口,各位提个意见啊
}
break;
case IDM_SET:
{
//
}
break;
}
}
return 0;

case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
xueer8835 2010-01-11
  • 打赏
  • 举报
回复
class control{
private:
HINSTANCE hInst;
HWND hMainHwnd;



HWND hMenu;

HWND hListView_User;
HWND hStatusBar_User;
HWND hToolbar_User;
HWND hComboboxProvince_User;
HWND hComboboxCity_User;
HWND hComboboxDistrict_User;

public:
control(HWND hwndParent);
~control();
void DestroyCtr();
BOOL CreateMenu();
BOOL CreateUserCtr();
BOOL CreateGameCtr();
};
an_bachelor 2010-01-11
  • 打赏
  • 举报
回复
那个 是不是个模式化窗口?

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧