⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ltwtdlg.cpp

📁 Window Wrapper for WinCE Win32 dialog a
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//***************************************************************************
//  LtWtDlg.cpp
//
//  This is a dialog based application based on a window created with a call
//  to CreateDialogParam.  
//
//  Requirements:
//    1. create a dialog app
//    2. Create the main window using a call to CreateDialog or a variant
//    3. Create a simple base class that allows the use of objects
//    4. Allow child windows to inherit from the base class
//  Secondary Goals:
//    1. Create the app without a menu bar and make the dialog use the entire
//       screen.  This assumes no data input from the screen because there
//       is no way to get to the input panel.  There will be no menu and no
//       accelerators.
//
//  Known Problems:
//    None.
//***************************************************************************

#include "stdafx.h"
#include "LtWtDlg.h"
#include <commctrl.h>

#define MAX_LOADSTRING 100

static SHACTIVATEINFO s_sai;

CDialogWindow DialogWindow;


//***************************************************************************
//  FUNCTION: WinMain
//
//  PURPOSE:  Entry point and Main Message Loop.
//
//  COMMENTS:
//***************************************************************************
int WINAPI WinMain( HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPTSTR    lpCmdLine,
                    int       nCmdShow )
{
   MSG msg;

   // Perform application initialization
   if ( !DialogWindow.InitInstance( hInstance, nCmdShow ) )
   {
      return FALSE;
   }

   // Main message loop
   int status;
   while ( ( status = GetMessage( &msg, NULL, 0, 0 ) ) != 0 )
   {
      if ( status == -1 )
         return -1;
      if ( !IsDialogMessage( DialogWindow.hWnd, &msg ) )
      {
         TranslateMessage( &msg );
         DispatchMessage( &msg );
      }
   }

   return msg.wParam;
}   /*   WinMain   */


//***************************************************************************
//  FUNCTION: InitInstance(HANDLE, int)
//
//  PURPOSE:  Saves instance handle and creates main window
//
//  COMMENTS:
//    In this function, we save the instance handle.  Load the app string
//    for title.  Switch to an already loaded instance of this app if
//    one is already found running.  Create and display the main dialog.
//    The InitDialog message of the main window will create the dialog, so
//    just activate the dialog box window.
//***************************************************************************
BOOL CDialogWindow::InitInstance( HINSTANCE hInstance, int nCmdShow )
{
   BOOL  AlreadyRunning;
   HWND  hWnd = NULL;
   TCHAR szTitle[MAX_LOADSTRING];            // The title bar text


   hwndCB = 0;
   hInst = hInstance;         // Store instance handle in our object variable

   // Initialize global strings
   LoadString( hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING );

   // This Mutex is used to find out if this is the first instance of the program.
   // The creation will fail if this is not the first instance
   HANDLE hMutexOneInstance = ::CreateMutex( NULL, FALSE, _T("LtWtDlg-{A17001C2-2614-4406-82CE-0691BB605948}") );
   AlreadyRunning = ( ::GetLastError() == ERROR_ALREADY_EXISTS ||
                      ::GetLastError() == ERROR_ACCESS_DENIED  );
   if ( AlreadyRunning )
   {
      // Already running so broadcast a message to all top level windows. When
      // the other instance sees this, it will come to the top of the Z-order.
      BOOL bresult = PostMessage( HWND_BROADCAST, UWM_ARE_YOU_ME, 0, 0 );
      return FALSE;
   }

   // I don't register a class because the Create Dialog call creates its own class.

   // create the dialog window
   hWnd = CreateDialogParam( hInstance, MAKEINTRESOURCE( IDI_LT_WT_DLG ), 0, (DLGPROC)BaseWndProc, (long)this );
   if ( !hWnd )
   {  
      return FALSE;
   }

   // taskbar apps like WISbar like to have a title even if it is not shown.  Create it here
   // or it can be set in the dialog resource.
   SetWindowText( hWnd, szTitle );

   // show the window and make it update
   ShowWindow( hWnd, nCmdShow );
   UpdateWindow( hWnd );

   return TRUE;
}   /*   InitInstance   */


//***************************************************************************
//  FUNCTION: BaseWndProc
//
//  PURPOSE:  Pass the callback message on to the window owner.
//
//  COMMENTS:
//    All Windows Message Loops can be inherited from this.  When it gets
//    a message the pointer to the owning object is retrieved and the
//    message is sent to the Window Procedure for that object.
//
//    On entry the object pointers are saved as the windows are created
//    along with win handle and the instance.
//
//    Upon exit it is decided if a call needs to be made to the Default
//    Window Procedure (DefWindowProc).  This way all of the WndProcs can
//    be the same coding style regardless of window type (window vs dialog).
//    Don't forget to set the DlgFlag for the object if the window is a
//    dialog box.
//***************************************************************************
LRESULT CALLBACK CBaseWindow::BaseWndProc( HWND hwnd, UINT msg,
                                           WPARAM wParam, LPARAM lParam )
{
   // check to see if a copy of the 'this' pointer needs to be saved
   if ( msg == WM_CREATE )
   {
      CBaseWindow *pObj = reinterpret_cast<CBaseWindow *>((long)((LPCREATESTRUCT)lParam)->lpCreateParams);
      ::SetWindowLong( hwnd, GWL_USERDATA, (LONG)((LPCREATESTRUCT)lParam)->lpCreateParams );
      pObj->hWnd = hwnd;
      pObj->DlgFlag = FALSE;
      if ( pObj->hInst == 0 )
         pObj->hInst = DialogWindow.hInst;
   }
   if ( msg == WM_INITDIALOG )
   {
      CBaseWindow *pObj = reinterpret_cast<CBaseWindow *>(lParam);
      ::SetWindowLong( hwnd, GWL_USERDATA, lParam );
      pObj->hWnd = hwnd;
      pObj->DlgFlag = TRUE;
      pObj->hInst = DialogWindow.hInst;
   }

   BOOL bProcessed = FALSE;
   LRESULT lResult;
    
   // Retrieve the pointer
   CBaseWindow *pObj = WinGetLong<CBaseWindow *>( hwnd, GWL_USERDATA );

   // Filter message through child classes
   if ( pObj )
      lResult = pObj->WndProc( hwnd, msg, wParam, lParam, &bProcessed );
   else
      return ( pObj->DlgFlag ? FALSE : TRUE ); // message not processed

   if ( pObj->DlgFlag )
      return bProcessed;     // processing a dialog message return TRUE if processed
   else
      if ( !bProcessed )
         // If message was unprocessed and not a dialog, send it back to Windows.
         lResult = DefWindowProc( hwnd, msg, wParam, lParam );

   return lResult;           // processing a window message return FALSE if processed
}   /*   BaseWndProc   */


//***************************************************************************
//  FUNCTION: WndProc
//
//  PURPOSE:  Processes messages for the main window.
//
//  COMMENTS:                                   
//***************************************************************************
LRESULT CDialogWindow::WndProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam, PBOOL pbProcessed )
{
   int wmId, wmEvent;


   // call the base class first
   LRESULT lResult = CBaseWindow::WndProc( hDlg, message, wParam, lParam, pbProcessed );
   BOOL bWasProcessed = *pbProcessed;
   *pbProcessed = TRUE;

   switch ( message )
   {
      case WM_COMMAND:
         wmId    = LOWORD(wParam); 
         wmEvent = HIWORD(wParam); 

         // Handle the buttons on the main dialog box
         switch ( wmId )
         {  
            case IDM_HELP_ABOUT:
            case IDC_ABOUT_BTN:
               {
                  CAboutWindow *pAboutWindow = new( CAboutWindow );
                  DialogBoxParam( GetInstance(), (LPCTSTR)IDD_ABOUTBOX, hDlg,
                                  (DLGPROC)pAboutWindow->BaseWndProc, (long)pAboutWindow );
                  delete pAboutWindow;
               }
               break;
            case IDOK:
               SendMessage( hDlg, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), (LPARAM)hWnd );
               SendMessage ( hDlg, WM_CLOSE, 0, 0 );
               break;
            default:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -