#include "stdafx.h"
#include <windows.h>
#include"resource.h"
#include "stdafx.h"#include <commctrl.h>
#include <aygshell.h>
#include <sipapi.h>
#include <commdlg.h>
#include <gx.h>
#include <pm.h>
#include <pimstore.h>
#include <windowsx.h>#include <connmgr.h>
#include <ras.h>
#include <connmgr_proxy.h>#include <cfgmgrapi.h> //shiqw addLRESULT CALLBACK WndProc     (HWND, UINT, WPARAM, LPARAM) ;
BOOL    CALLBACK DlgProc (HWND, UINT, WPARAM, LPARAM) ;
 
extern"C" int __declspec(dllexport) ShowDialog(HWND mhwnd,HINSTANCE hInstance)
{
     static TCHAR szAppName[] = TEXT ("Modeless_Dialog") ;
     HWND         hwnd ;
     MSG          msg ;
     WNDCLASS     wc ;
     
      HWND hDialog;
 
    
  wc.style         = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  wc.lpfnWndProc              = (WNDPROC) WndProc;
  wc.cbClsExtra      = 0;
  wc.cbWndExtra      = 0;
  wc.hIcon= LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_RICHMEDIA));
  wc.hCursor         = 0;
  wc.hbrBackground            = (HBRUSH) GetStockObject(HOLLOW_BRUSH);
  wc.lpszMenuName      = 0;
  wc.lpszClassName   = L"szAppClassName";
  wc.hInstance           =  GetModuleHandle(NULL) ;
  RegisterClass(&wc);   HINSTANCE ff;
  ff=GetModuleHandle(NULL);   HWND hwndtemp;
  //hwndtemp = CreateWindow( L"szAppClassName", 0, WS_BORDER,
  //0, 0, 0, 0, mhwnd, NULL,ff, NULL);
  hwndtemp = CreateWindowEx(0x00000004, L"szAppClassName", 0, WS_CLIPSIBLINGS ,
  0, 0, 0, 0, mhwnd, NULL,hInstance, NULL);
 ShowWindow (hwnd, SW_SHOW) ;       //并不在这里显示主窗口
  // UpdateWindow (hwnd) ;     hDialog = CreateDialog (hInstance, MAKEINTRESOURCE(IDD_DIALOG1), hwnd, DlgProc) ;   while (GetMessage (&msg, NULL, 0, 0))
     {
          if(hDialog==0||!IsDialogMessage(hDialog,&msg)) 
          {
          TranslateMessage (&msg) ;
          DispatchMessage (&msg) ;
          }
     }
     return msg.wParam ;
 
}
BOOL CALLBACK DlgProc (HWND hDlg, UINT message, 
                           WPARAM wParam, LPARAM lParam)
{
     switch(message)
     {
         case WM_INITDIALOG :
              return true;
         case WM_COMMAND:
              switch(wParam)
              {
              case(IDOK):
                   MessageBox(NULL, L"这是一个modeless对话框的例子",L"提示",MB_OK);
                   DestroyWindow(hDlg);
                   PostQuitMessage (0) ;
                   return TRUE;
              }
     }
     return FALSE;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{    
     switch (message)
     { 
     case WM_DESTROY:
          PostQuitMessage (0) ;
          return 0 ;
     }
     return DefWindowProc (hwnd, message, wParam, lParam) ;
}

解决方案 »

  1.   

    windows的机制就是消息循环,除非你不用windows
      

  2.   

    if(hDialog==0||!IsDialogMessage(hDialog,&msg)) 
              { 
              TranslateMessage (&msg) ; 
              DispatchMessage (&msg) ; 
              } 
    这里,你的意思是只有当对话框句柄为NULL里才会处理消息,所以你的消息循环处理不了消息
      

  3.   

    if(hDialog !=0 || !IsDialogMessage(hDialog,&msg)) 
    ..............
      

  4.   

    对话框不用写消息循环
    只有SDK窗体才写但是我只用过模式对话框,没用过非版的,如果不对,请拍砖
      

  5.   

    把GetMessage改成PeekMessage也许会好一点