src/dialog.cpp

Go to the documentation of this file.
00001 /*
00002 * Copyright (c) 2006 by Kirill Kolodyazhniy.
00003 * See the file "license.terms" for information on usage and redistribution
00004 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
00005 */
00006 
00007 #include "stdinc.h"
00008 #include "icon.h"
00009 #include "eventhandler.h"
00010 #include "widgets.h"
00011 #include "menu.h"
00012 #include "widget.h"
00013 #include "dialog.h"
00014 #include "exception.h"
00015 namespace MWidgets
00016 {
00017         /*******************************************************************************/
00018         Dialog::Dialog():Widget()
00019         {
00020                 m_iResult=IDCLOSE;
00021                 m_bShow=true;
00022         };
00023         /*******************************************************************************/
00024         void Dialog::Create(int w,int h,string caption)
00025         {
00026                 Widget::Create(0,0,w,h,caption,"MicroWidget",WS_SYSMENU|WS_CAPTION|WS_POPUP|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,NULL,WS_EX_TOOLWINDOW);
00027                 m_iResult=IDCLOSE;
00028                 m_bShow=true;
00029         };
00030         /*******************************************************************************/
00031         LRESULT Dialog::OnMessage (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
00032         {
00033                 if(message==WM_CLOSE)
00034                 {
00035                         m_iResult=IDCLOSE;
00036                         m_bShow=false;
00037                         return 0;
00038                 }
00039                 else
00040                         return Widget::OnMessage(hWnd, message, wParam, lParam);
00041         };
00042         /*******************************************************************************/
00043         int Dialog::DoModal(Widget* parent)
00044         {
00045                 RECT r;
00046                 HWND m_hParentHwnd=parent->GetHwnd();
00047                 GetClientRect(m_hParentHwnd,&r);
00048                 EnableWindow(m_hParentHwnd,FALSE);
00049                 SetWindowPos(m_hWnd,HWND_TOP,(r.right-r.left)/2,(r.bottom-r.top)/2,0,0,SWP_NOSIZE|SWP_NOZORDER|SWP_SHOWWINDOW);
00050                 Show();
00051                 MSG msg;
00052                 // Dialog Main message loop:
00053                 m_bShow=true;
00054                 while(m_bShow)
00055                 {
00056                         if(PeekMessage( &msg, NULL, 0, 0,PM_REMOVE))
00057                         {
00058                                 SetActiveWindow(m_hWnd);
00059                                 if(!IsDialogMessage(m_hWnd,&msg)&&msg.message!=WM_HOTKEY)
00060                                 {
00061                                         TranslateMessage(&msg);
00062                                         DispatchMessage(&msg);
00063                                 }
00064                         }
00065                 }
00066                 SetActiveWindow(m_hParentHwnd);
00067                 Hide();
00068                 EnableWindow(m_hParentHwnd,TRUE);
00069                 return m_iResult;
00070         };
00071         /*******************************************************************************/
00072         void Dialog::EndDlg(int val)
00073         {
00074                 m_bShow=false;
00075                 m_iResult=val;
00076         };
00077         /*******************************************************************************/
00078         WIDGET_TYPE Dialog::GetType()
00079         {
00080                 return DIALOG;
00081         };
00082         /*******************************************************************************/
00083 };

Generated on Thu Oct 26 13:47:45 2006 for MWidgets by  doxygen 1.4.7