免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2549 | 回复: 0
打印 上一主题 下一主题

API 线程不能关闭 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-07-31 11:46 |只看该作者 |倒序浏览
初次学API,出了个问题,我新建一个Dialog作为主界面,在循环消息处理中以DestroyWindow(hWnd);DestroyWindow(GetParent(hWnd));   来退出程序,但是每次退出后,我的任务管理器中照样存在线程。现在我把代码贴出来,请高手指点!


代码:
//   Test002.cpp   :   Defines   the   entry   point   for   the   application.
//
#include   <stdafx.h>
#include   "resource.h "
#include   "Login.h "
#include   <stdio.h>
#include   <stdlib.h>
#include   <stdarg.h>
#include   <stddef.h>
#define   MAX_LOADSTRING   100

//   Global   Variables:
HINSTANCE   hInst; //   current   instance
TCHAR   szTitle[MAX_LOADSTRING]; //   The   title   bar   text
TCHAR   szWindowClass[MAX_LOADSTRING]; //   The   title   bar   text

//   Foward   declarations   of   functions   included   in   this   code   module:
ATOM MyRegisterClass(HINSTANCE   hInstance);
BOOL                                 DialogRegisterClass(HINSTANCE   hInstance);
BOOL InitInstance(HINSTANCE,   int);
LRESULT   CALLBACK WndProc(HWND,   UINT,   WPARAM,   LPARAM);
LRESULT   CALLBACK About(HWND,   UINT,   WPARAM,   LPARAM);
LRESULT       CALLBACK     DlgProc(HWND,   UINT,   WPARAM,   LPARAM);

int   APIENTRY   WinMain(HINSTANCE   hInstance,
                                          HINSTANCE   hPrevInstance,
                                          LPSTR           lpCmdLine,
                                          int               nCmdShow)
{
  //   TODO:   Place   code   here.
MSG   msg;
HACCEL   hAccelTable;

//   Initialize   global   strings
LoadString(hInstance,   IDS_APP_TITLE,   szTitle,   MAX_LOADSTRING);
LoadString(hInstance,   IDC_TEST002,   szWindowClass,   MAX_LOADSTRING);
MyRegisterClass(hInstance);
//DialogRegisterClass(hInstance)
HWND   hWnd_Main;
//(WNDPROC)WndProc   Param   ,0L   (DLGPROC)   (DLGPROC)DlgProc
hWnd_Main   =   CreateDialog(hInstance,   MAKEINTRESOURCE(IDD_LOGIN),NULL,(DLGPROC)DlgProc);

ShowWindow(hWnd_Main,   nCmdShow);
UpdateWindow(hWnd_Main);
hAccelTable   =   LoadAccelerators(hInstance,   (LPCTSTR)IDC_TEST002);

//   Main   message   loop:
while   (GetMessage(&msg,   NULL,   0,   0))   
{
if   (!TranslateAccelerator(msg.hwnd,   hAccelTable,   &msg))   
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return   msg.wParam;
}
//
//     FUNCTION:   MyRegisterClass()
//
//     PURPOSE:   Registers   the   window   class.
//
//     COMMENTS:
//
//         This   function   and   its   usage   is   only   necessary   if   you   want   this   code
//         to   be   compatible   with   Win32   systems   prior   to   the   'RegisterClassEx '
//         function   that   was   added   to   Windows   95.   It   is   important   to   call   this   function
//         so   that   the   application   will   get   'well   formed '   small   icons   associated
//         with   it.
//
ATOM   MyRegisterClass(HINSTANCE   hInstance)
{
WNDCLASSEX   wcex;

wcex.cbSize   =   sizeof(WNDCLASSEX);   
//(WNDPROC)WndProc
wcex.style =   CS_HREDRAW   |   CS_VREDRAW;
wcex.lpfnWndProc =   (WNDPROC)WndProc;
wcex.cbClsExtra =   0;
wcex.cbWndExtra =   0;
wcex.hInstance =   hInstance;
wcex.hIcon =   LoadIcon(hInstance,   (LPCTSTR)IDI_TEST002);
wcex.hCursor =   LoadCursor(NULL,   IDC_ARROW);
wcex.hbrBackground =   (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName =   (LPCSTR)IDC_TEST002;
wcex.lpszClassName =   szWindowClass;
wcex.hIconSm =   NULL;

return   RegisterClassEx(&wcex);
}

//
//     FUNCTION:   WndProc(HWND,   unsigned,   WORD,   LONG)
//
//     PURPOSE:     Processes   messages   for   the   main   window.
//
//     WM_COMMAND -   process   the   application   menu
//     WM_PAINT -   Paint   the   main   window
//     WM_DESTROY -   post   a   quit   message   and   return
//
//
LRESULT   CALLBACK   WndProc(HWND   hWnd,   UINT   message,   WPARAM   wParam,   LPARAM   lParam)
{

switch   (message)
{
case   WM_COMMAND:
if   (LOWORD(wParam)   ==   IDOK   ||   LOWORD(wParam)   ==   IDCANCEL)   
{
DestroyWindow(hWnd);
return   TRUE;
}
break;
default:
return   DlgProc(hWnd,message,wParam,lParam);
}
return   false;
}


LRESULT       CALLBACK       DlgProc(HWND   hWnd,   UINT   message,   WPARAM   wParam,   LPARAM   lParam)
{
//int   wmId,   wmEvent;
switch   (message)
          {
          case   WM_INITDIALOG   :
return   TRUE   ; //
                    
          case   WM_COMMAND   :
switch   (LOWORD   (wParam))
{
case   IDOK   :
case   IDCANCEL   :
DestroyWindow(hWnd);   
DestroyWindow(GetParent(hWnd));   
EndDialog(hWnd,   0)   ; //
break   ;   //
}
case   WM_CLOSE:
DestroyWindow(hWnd);   
DestroyWindow(GetParent(hWnd));   ;
break;     
          }
          return   FALSE   ;   //
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP