| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 531 人关注过本帖
标题:一个多窗口的问题
只看楼主 加入收藏
安普留香
Rank: 2
等 级:论坛游民
帖 子:77
专家分:62
注 册:2010-5-17
结帖率:75%
收藏
已结贴  问题点数:20 回复次数:2 
一个多窗口的问题
程序代码:
#include <windows.h>
LRESULT CALLBACK WndPr(HWND,UINT,WPARAM,LPARAM);
BOOL Application(HINSTANCE hinstance);
BOOL Initinstance(HINSTANCE hinstance,int nCmdShow);
HWND hwnd,s_hwnd;
MSG msg,s_msg;
static TCHAR szAppName[] = TEXT ("HelloWin") ;
int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hPrevInstance,LPSTR szCmdLine,int nCmdShow)
{

Application(hinstance);
Initinstance(hinstance,nCmdShow);
while (GetMessage (&msg,NULL, 0, 0))
       
    {
       
            TranslateMessage (&msg) ;
       
          DispatchMessage (&msg) ;
       
    }

return msg.wParam;

}
BOOL Application(HINSTANCE hinstance)
{


    WNDCLASS wndclass ;
        

   wndclass.style        = CS_HREDRAW | CS_VREDRAW ;
       
   wndclass.lpfnWndProc  = WndPr ;
       
    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= szAppName ;


 if (!RegisterClass (&wndclass))
       
    {
       
            MessageBox (  NULL, TEXT ("This program requires Windows NT!"),
       
                                  szAppName, MB_ICONERROR) ;
       
            return FALSE ;
       
    }
return TRUE;
}
BOOL Initinstance(HINSTANCE hinstance,int nCmdShow)
{
  hwnd = CreateWindow( szAppName,      // window class name
       
                   TEXT ("The Hello Program"),   // window caption
       
                   WS_OVERLAPPEDWINDOW,  // window style
       
                   CW_USEDEFAULT,// initial x position
       
                   CW_USEDEFAULT,// initial y position
       
                   CW_USEDEFAULT,// initial x size
       
                   CW_USEDEFAULT,// initial y size
       
                   NULL,                 // parent window handle
       
               NULL,            // window menu handle
       
               hinstance,   // program instance handle
       
               NULL) ;      // creation parameters
       
  
      if(!hwnd)
          return FALSE;
    ShowWindow (hwnd, nCmdShow) ;
       
    UpdateWindow (hwnd) ;
s_hwnd = CreateWindow( szAppName,      // window class name
       
                   TEXT ("Hello Mr.chen"),   // window caption
       
                   WS_OVERLAPPEDWINDOW,  // window style
       
                   CW_USEDEFAULT,// initial x position
       
                   CW_USEDEFAULT,// initial y position
       
                   CW_USEDEFAULT,// initial x size
       
                   CW_USEDEFAULT,// initial y size
       
                   NULL,                 // parent window handle
       
               NULL,            // window menu handle
       
               hinstance,   // program instance handle
       
               NULL) ;      // creation parameters
       
  
      if(!s_hwnd)
          return FALSE;
    ShowWindow (s_hwnd, nCmdShow) ;
       
    //UpdateWindow (s_hwnd) ;
    return TRUE;
        

}
LRESULT CALLBACK WndPr (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
       
{
       
    HDC                   hdc ;
       
    PAINTSTRUCT ps ;
       
    RECT          rect ;
       
   /*if(hwnd==hwnd)
      MessageBox(NULL,"Oh!NO!","Dialog",MB_YESNO|MB_ICONHAND);
  
  PostQuitMessage (0) ;*/
  
    switch (message)
       
    {
   

    case   WM_PAINT:
        if(hwnd==hwnd){
            hdc = BeginPaint (hwnd, &ps) ;
       
       
       
            GetClientRect (hwnd, &rect) ;
       
       
       
            DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect,
       
                   DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
       
                 EndPaint (hwnd, &ps) ;
        }
         else if(s_hwnd==hwnd){
            hdc = BeginPaint (hwnd, &ps) ;
       
       
       
            GetClientRect (hwnd, &rect) ;
       
       
       
            DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect,
       
                   DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
       
                 EndPaint (hwnd, &ps) ;
        };
                   return 0 ;
       
       
       
    case   WM_DESTROY:
       
            PostQuitMessage (0) ;
       
            return 0 ;
       
    }
       
  return DefWindowProc (hwnd, message, wParam, lParam) ;
       
}
  
我想利用同一个窗口类,建立多个窗口并显示出来
为什么对于最大化和最小化窗口,两个窗口是独立的,互不影响。但是点击关闭一个窗口后,两个窗口都关闭了。
这是什么原因???我想显示完全独立的2个窗口
搜索更多相关主题的帖子: 窗口 
2010-12-04 13:35
迷失的木桶
Rank: 4
等 级:业余侠客
帖 子:52
专家分:230
注 册:2010-5-29
收藏
得分:20 
应该是这里问题
case   WM_DESTROY:
      
            PostQuitMessage (0) ;
      
            return 0 ;

任何一个窗口被销毁,都会发生WM_DESTROY消息吧。因此只要有一个窗口被关闭,即PostQuitMessage,导致消息循环中断程序退出。

windows编程我不是很熟悉,你试试吧
2010-12-04 14:35
安普留香
Rank: 2
等 级:论坛游民
帖 子:77
专家分:62
注 册:2010-5-17
收藏
得分:0 
的确是这里的问题
2010-12-04 15:13
快速回复:一个多窗口的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016083 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved