I have this simple example taken from the Windows programming book form Pretzold:
Code:
#include <windows.h>
// Windows procedure function prototype - deals with
// messages
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hINstance, HINSTANCE hPrevInstance,
LPSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT("HelloWin");
HWND hwnd; // handle to the main window
MSG msg; // messages received
WNDCLASS wndclass; // main window class
wndclass.style = CS_HREDRAW | CS_LREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
// Register new window class
if(!RegisterClass(&wndclass) {
MessageBox(NULL, TEXT("This program requires Windows NT"), szAppName,
MB_ICONERROR);
return 0;
}
// Create new window (handle)
hwnd = CreateWindow(szAppName, // window class name
TEXT("Window"), // window title
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL); // creation parameters
// Window is now created. Show it
ShowWindow(hwnd, iCmdShow);
// Update
UpdateWindow(hwnd);
// Message loop
while(GetMessage(&msg, NULL, 0, 0) {
TranslateMessage(&msg);
DispatchMessage(&msg); // dispatches to WinProc function
}
return msg.wParam; // return 0
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc; // device context
PAINTSTRUCT pt;
RECT rect;
// select an aption accoding to the message received
switch(message) {
case WM_CREATE:
PlaySound(TEXT("hello.wav"), NULL, SND_FILENAME | SND_ASYNC);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &pt);
GetClientRect(hwnd, &rect);
DrawText(hdc, TEXT("Hello Windows"), -1, &rect, DT_SINGLELINE |
DT_CENTER | DT_VCENTER);
EndPaint(hwnd, &pt);
return 0;
case WM_DESTROY:
// PostQuitMessage return 0 which makes the message loop end
PostQuitMessage(0);
return 0;
}
// windows automatically deals with messages that for some
// reason were not interpreted by the program
return DefWindowProc(wnd, msg, wParam, lParam);
}
How come this only works under Windows NT and not Windows 98?
Thanks.