Ejemplo n.º 1
0
//
//   FUNCTION: InitInstance(HANDLE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;
	 int xStart, yStart, xClient, yClient;

   hInst = hInstance; // Store instance handle in our global variable

   SizeTheWindow(&xStart, &yStart, &xClient, &yClient);
/*   
	 hWnd = CreateWindow(szWindowClass, szAppName,
		 WS_POPUP | WS_DLGFRAME | WS_SYSMENU,
		 xStart, yStart,
		 xClient, yClient,
		 NULL, NULL, hInstance, NULL);
*/


    hWnd = CreateWindow(szWindowClass, szAppName, WS_OVERLAPPEDWINDOW,
                        CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }
   
	 if(!SetTimer(hWnd, ID_TIMER, 100, NULL))
	 {
		 MessageBox(hWnd, "Too many clocks or timers!", szAppName, MB_ICONEXCLAMATION | MB_OK);
		 return FALSE;
	 }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}
Ejemplo n.º 2
0
int PASCAL WinMain ( HANDLE hInstance, 
                     HANDLE hPrevInstance,
                     LPSTR lpszCmdParam,
                     int nCmdShow)
   {
   static char szAppName[] = "Digital Clock";
   HWND        hwnd;
   MSG         msg;
   short       xStart,
               yStart,
               xClient,
               yClient;
   WNDCLASS    wndclass;

   // save off the command line parameters so that we can 
   // display them a little later!


//   kills our present instantiation if another already exists!   
   if (hPrevInstance != 0)
      return 0;
   
   if(!hPrevInstance)
      {
      wndclass.style          = CS_HREDRAW | CS_VREDRAW;
      wndclass.lpfnWndProc    = WndProc;
      wndclass.cbClsExtra     = 0;
      wndclass.cbWndExtra     = 0;      
      wndclass.hInstance      = hInstance;      
      wndclass.hIcon          = NULL;                       // NONE DEFINED
      wndclass.hCursor        = LoadCursor(NULL,IDC_ARROW);      
      wndclass.hbrBackground  = GetStockObject (WHITE_BRUSH);      
      wndclass.lpszMenuName   = NULL;      
      wndclass.lpszClassName  = szAppName;      

      RegisterClass(&wndclass);

      
      }

//   SetCursor(LoadCursor(NULL,IDC_ARROW));
   SizeTheWindow(&xStart,&yStart,&xClient,&yClient);
   
   hwnd = CreateWindow (szAppName,                          //name of this program
                        szAppName,                          //Window heading string
                        WS_POPUP | WS_DLGFRAME | WS_SYSMENU,//Window Style
                        xStart,                             //initial x pos
                        yStart,                             //initial y pos
                        xClient,                            //initial x size
                        yClient,                            //initial y size
                        NULL,                      //parent window handle
                        NULL,                      //window menu handle
                        hInstance,                 //program instance handle (!)
                        NULL);                     //creation params

                        
                        
   if (!SetTimer (hwnd, ID_TIMER, TIMER_MSECS ,NULL))
      {
      MessageBox(hwnd,
                 "Too many clocks or timers!",
                 szAppName,
                 MB_ICONEXCLAMATION | MB_OK);
      return FALSE;                          
                                
      }
                        
   // show it in its current state but DON'T switch to it.                        
   ShowWindow(hwnd, SW_SHOWNOACTIVATE);
   UpdateWindow(hwnd);

   // loop until WM_QUIT (which causes GetMessage to return 0!) 
   while (GetMessage (  &msg, 
                        NULL, 
                        0,
                        0     ))
      {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
      } 
        
   return msg.wParam;
   }