2012年7月5日星期四

dialog.cpp


本人写对话框的三种创建的途径。
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
模态的对话框:
#include <Windows.h> 

#pragma comment(linker, "/ENTRY:Entry") 
#pragma comment(linker, "/subsystem:windows")

LRESULT CALLBACK DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 
  switch (uMsg) 
  { 
  case WM_CLOSE:
EndDialog(hwnd, 0);
  default: 
    return 0; 
  } 
  return 1; 

void Entry() 
{  
  DialogBoxParam(GetModuleHandle(0),(LPCSTR)1,0,(DLGPROC)DialogProc,0);
  ExitProcess(0);
//made at 2011.11.08
资源文件如下:
1 DIALOGEX 0, 0, 316, 185
CAPTION "made by correy"
BEGIN
END
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////非模态对话框之一:
#include <Windows.h> 

#pragma comment(linker, "/ENTRY:Entry") 
#pragma comment(linker, "/subsystem:windows")

LRESULT CALLBACK DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 
  switch (uMsg) 
  { 
  case WM_CLOSE: 
    PostQuitMessage(0);
    return TRUE; 
  default: 
    return 0; 
  } 
  return 1; 

void Entry() 
{  
  HWND hmodeless_dialog  = CreateDialogParam(GetModuleHandle(0),(LPCSTR)1,0,(DLGPROC)DialogProc,0);
  ShowWindow(hmodeless_dialog,1);

  MSG msg; 
  while (GetMessage(&msg, NULL, 0, 0)) 
  { 
    if(!IsDialogMessage(hmodeless_dialog,&msg))
    {
      DispatchMessage(&msg);
    }
  } 

  ExitProcess(0);
//made at 2011.11.09
资源文件如下:
1 DIALOGEX 0, 0, 316, 185
CAPTION "made by correy"
BEGIN
END
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////非模态对话框之二:
#include <Windows.h> 

#pragma comment(linker, "/ENTRY:Entry") 
#pragma comment(linker, "/subsystem:windows")

LRESULT CALLBACK DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 
  switch (uMsg) 
  { 
  case WM_CLOSE: 
    PostQuitMessage(0);
    return TRUE; 
  default: 
    return DefWindowProc(hwnd, uMsg, wParam, lParam ); 
  } 
  return 1; 

void Entry() 
{  
  WNDCLASSEX sWndClassEx = {48,3,DialogProc,0,DLGWINDOWEXTRA,GetModuleHandle(0),0,LoadCursor(0,IDC_ARROW),(HBRUSH)6,0,"correy",0}; 
  ATOM a = RegisterClassEx(&sWndClassEx); 
  HWND hmodeless_dialog  = CreateDialogParam(GetModuleHandle(0),"correy",0,0,0);
  ShowWindow(hmodeless_dialog,1);

  MSG msg; 
  while (GetMessage(&msg, NULL, 0, 0)) 
  { 
    if(!IsDialogMessage(hmodeless_dialog,&msg))
    {
      DispatchMessage(&msg);
    }
  } 

  ExitProcess(0);
//made at 2011.11.10
资源文件如下:
correy DIALOGEX 0, 0, 316, 185
CAPTION "made by correy"
CLASS "correy" 
BEGIN
END
版权所有,违者必究。

没有评论:

发表评论