Make your own free website on Tripod.com

(Best in 1152 x 864 resolution or higher)

On Windows Programming

On Windows Programming (Page 2)

 

/*

BlackScreen Revisited

VisualStudio.NET 2002 version

June 8th, 2006

One cpp file can do it, but an *.h file is also used usually

*/

 

// *.h file stuff usually

#pragma once

 

//Exclude rarely used stuff

#define WIN32_LEAN_AND_MEAN

//Windows Header File

#include <windows.h>

#include <windowsx.h>

#include <cstring>

using namespace std;  // all global or nothing or name part to use globally like std:strings

                      // in global scope and Deep C++ Glossary

// C RunTime Header Files

#include <stdlib.h> // included usually

#include <malloc.h>

#include <memory.h>

#include <tchar.h>

// end of *.h file stuff

// #include "stuff.h" file as first line then.

 

// Global Variables:

HINSTANCE hInst;

PAINTSTRUCT ps;

HDC hdc;

LPCSTR szTitle = "BlackScreen";         // The title bar text

LPCSTR szWindowClass = "MainWindowEx";  // the main window class name

int xWidth = 0;

int yHeight = 0;

 

// Forward declarations of functions included in this code module:

BOOL InitInstance(HINSTANCE, int);

LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);

GetxWidthFullScreen();

GetyHeightFullScreen();

//

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)

{

    WNDCLASSEX wcex;

 

    wcex.cbSize = sizeof(WNDCLASSEX);

 

    wcex.style          = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;

    wcex.lpfnWndProc    = (WNDPROC)MainWndProc;

    wcex.cbClsExtra     = 0;

    wcex.cbWndExtra     = 0;

    wcex.hInstance      = hInstance;

    wcex.hIcon          = LoadIcon(NULL, IDI_WINLOGO);

    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);

    wcex.hbrBackground  = (HBRUSH)GetStockObject(BLACK_BRUSH);

    wcex.lpszMenuName   = "";

    wcex.lpszClassName  = szWindowClass;

    wcex.hIconSm        = LoadIcon(NULL, IDI_WINLOGO);

 

    if (!RegisterClassEx(&wcex))

        return FALSE;

 

    MSG msg;

    HACCEL hAccelTable;

    // Perform application initialization:

    if (!InitInstance (hInstance, nCmdShow))

    {

        return FALSE;

    }

    hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDI_APPLICATION);

    // Main message loop:

    while (GetMessage(&msg, NULL, 0, 0))

    {

        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))

        {

            TranslateMessage(&msg);

            DispatchMessage(&msg);

        }

    }

    return (int) msg.wParam;

}

//   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;

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

   hWnd = CreateWindowEx(WS_EX_CONTROLPARENT,

                         szWindowClass,

                         szTitle,

                         WS_POPUPWINDOW | WS_VISIBLE,

                         CW_USEDEFAULT,

                         CW_USEDEFAULT,

                         GetxWidthFullScreen(),

                         GetyHeightFullScreen(),

                         NULL,

                         NULL,

                         hInstance,

                         NULL);

   if (!hWnd)

   {

      return FALSE;

   }

   ShowWindow(hWnd, nCmdShow);

   UpdateWindow(hWnd);

   return TRUE;

//  FUNCTION: MainWndProc(HWND, unsigned, WORD, LONG)

//  PURPOSE:  Processes messages for the main window.

LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

{

    switch (message)

    {

        case WM_PAINT:

            hdc = BeginPaint(hWnd, &ps);

            // Drawing code?

            EndPaint(hWnd, &ps);

            break;

        case WM_KEYDOWN: // VK_ precedes all key presses-for alphabet or numbers use case 'A'

            switch ( wParam )

            {

                case 0x1B: //VK_ESCAPE-Escape key closes down program-any key works as of now

                    DestroyWindow ( hWnd );

                    return 0;

                    break;

            }

        case WM_DESTROY:

            PostQuitMessage(0);

            break;

        default:

            return (DefWindowProc(hWnd, message, wParam, lParam));

    }

    return 0;

}

 

int GetxWidthFullScreen()

{

    xWidth = GetSystemMetrics(SM_CXSCREEN);

            return (int) xWidth;

}

 

int GetyHeightFullScreen()

{

    yHeight = GetSystemMetrics(SM_CYSCREEN);

        return (int) yHeight;

}

 

 

 

 

 

 

 

 

June 8th, 2006