0% found this document useful (0 votes)
288 views3 pages

Basic Windows 2000 Skeleton

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 3

1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24:

25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81:

/* The herewritten code is copied (word to word) from (except Comments & Documentation): "Windows 2000 Programming from Ground Up" By "Herbert Schildt" */

#include<windows.h> // Must include this file, it contains API function prototypes, Macros, & definitions LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM,LPARAM); /* A simple Window Function CALLBACK: Will be called by Windows to communicate with program */ char szWinName[]="My First Window"; // The Name for Window class (one of the field in WNDCLASSEX structure).

int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst, LPSTR lpszArgs, int nWinMode) /* The main() function for windows: -> hThisInst: Handle to current Instance -> hPrevInst: Handle to previous Running Instance of this program (currently NULL) -> lpszArgs: Command Line Arguments, same as arguments for main() in simple C program -> nWinMode: Value that determines How Window will be displayed */ { HWND hwnd; // Handle for new window, will be created after. MSG msg; // msg will store windows messages /* MSG Structure: { HWND hwnd; UINT message; WPARAM wParam; LPARAM lParam; DWORD time; POINT pt; // POINT Structure: { LONG x,y; } } */ WNDCLASSEX wcl; // Used to define Window Class /* WNDCLASSEX Structure { HINSTANCE hInstance; UINT cbSize; UINT style; WNDPROC lpfnWndProc; HICON hIcon; HICON hIconSm; HCURSOR hCursor; HBRUSH hbrBackground; LPCSTR lpszMenuName; LPCSTR lpszClassName; int cbClsExtra; int cbWndExtra; } */

wcl.cbSize = sizeof(WNDCLASSEX); // cbSize (UINT): Stores size of WNDCLASSEX structure wcl.style = 0; // style (UINT): Default Style wcl.lpfnWndProc = WindowFunc; // lpfnWndProc (WNDPROC): Long Function Pointer to Window Function wcl.cbClsExtra = 0; // cbClsExtra (int): Extra Memory Size for class if needed wcl.cbWndExtra = 0; // cbWndExtra (int): Extra Memory Size for Window if needed wcl.hInstance = hThisInst; // hInstance (HINSTANCE): Handle for This (Current) instance wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION); // hIcon (HICON): Handle for large icon (32x32 or bigger) /* LoadIcon(): Use to load Large Icon "HICON LoadIcon (HINSTANCE hInst, LPCSTR lpszName)" hInst: Handle of module that contains Icon

lpszName: Name of ICON >> To use built-in ICON << >> Use NULL for hInst >> Use one of the following for lpszName :: IDI_APPLICATION :: IDI_ERROR :: IDI_QUESTION :: IDI_INFORMATION :: IDI_WARNING

82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: // 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: }

:: IDI_WINLOGO */ wcl.hIconSm = NULL;

(Not Working on My system)

// hIconSm (HICON): Handle for small icon (16x16) /* >> NULL: no small icon >> Specify Nothing: Small icon is searched for in large icon's resource file, if not found large icon is shrunk >> LoadImage(): Used to load icon of any size */

wcl.hCursor = LoadCursor(NULL, IDC_ARROW); // hCursor (HCURSOR): Handle for Cursor style/type /* LoadCursor(): Use to load mouse cursor "HICON LoadIcon (HINSTANCE hInst, LPCSTR lpszName)" hInst: Handle of module that contains mouse cursor

lpszName: Name of Cursor >> To use built-in CURSOR << >> Use NULL for hInst >> Use one of the following for lpszName :: IDC_ARROW :: IDC_CROSS :: IDC_HAND :: IDC_IBEAM :: IDC_WAIT */ wcl.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcl.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); /* hbrBackground (HBRUSH): paints the window background (Not working on My system) */ wcl.lpszMenuName = NULL; // lpszMenuName (LPCSTR): No class Menu required wcl.lpszClassName = szWinName; // lpszClassName (LPCSTR): Window Class name if(!RegisterClassEx(&wcl)) return 0; hwnd = CreateWindow( // Registering the Window Class

// Create Window szWinName, // Name of Window Class "Windows 2000 Base", // Title of window WS_OVERLAPPEDWINDOW, // Window style - Normal CW_USEDEFAULT, // X-Coordinate (Default) CW_USEDEFAULT, // Y-Coordinate (Default) CW_USEDEFAULT, // Width (Defult) CW_USEDEFAULT, // Height (Default) NULL, // No parent Window NULL, // No Menu hThisInst, // Instance Hnadle NULL // No additional arguments ); // Display Window in mode defined by nWinMode /* Not necessary, however it tells Windows 2000 to send a message to the application that main window needs to be updated */

ShowWindow(hwnd,nWinMode); UpdateWindow(hwnd);

while(GetMessage(&msg, NULL, 0 , 0)) /* GetMessage():Receives the messages, returns 0 on program termination, -1 on unexpected error, else non-zero "BOOL GetMessage(LPMSG msg, HWND hwnd, UINT min, UINT max)" msg: pointer to MSG structure hwnd: handle to intended window min & max: range of messages to be received, 0 for all messages */ { TranslateMessage(&msg); /* Not necessary here, however it translates Virtual Key Codes into character messages */ /* Dispatches messages back to Windows 2000 Windows 2000 then holds these messages until they are passed to Windows Function ("WindowFunc"). */

DispatchMessage(&msg);

} return msg.wParam; // contains return code generated by the program.

162: 163: LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 164: // The Windows Procedure, will be called by Windows (CALLBACK) 165: { 166: switch(message) 167: { 168: case WM_DESTROY: 169: PostQuitMessage(0); // Argument to this function is returned in msg.wParam in WinMain() 170: // This function causes a "WM_QUIT" message to be sent to the 171: // application which causes GetMessage() to return false. 172: break; 173: 174: default: 175: return DefWindowProc(hwnd, message, wParam, lParam); 176: // Process required messages and let the rest messages 177: // be processed in the default windows way 178: } 179: return 0; 180: } 181:

You might also like