Hello everyone,
I have posted quite a few of these questions lately, but here goes anyway. The title pretty much explains the question. This is what happens when my program executes: Builds fine(no errors or warnings), then runs it but there is no window at all. When I press ctrl + alt + delete, my program shows up in the client area. The code is made up of a header file with everything in it to make the window and print text in the center of the screen. Then the source file just calls the function. It is below.
The header file:
#pragma once
int InitClass(char WindowName[]);
LRESULT CALLBACK MsgHandler(HWND, UINT, WPARAM, LPARAM);
// Globals.....I know
RECT WindowRect = {100, 100, 400, 400};
HINSTANCE hInstance;
int iCmdShow;
InitClass(char WindowName[])
{
MSG msg;
HWND hwnd;
WNDCLASSEX wndclass;
// Class Properties
wndclass.cbSize = sizeof(wndclass);
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = MsgHandler;
wndclass.lpszClassName = "Reusable Window";
wndclass.style = CS_HREDRAW | CS_VREDRAW;
// Visual properties
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&wndclass);
hwnd=CreateWindow("Reusable Window", WindowName, WS_OVERLAPPEDWINDOW || WS_VISIBLE,
WindowRect.left, WindowRect.top, WindowRect.right, WindowRect.bottom,
NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK MsgHandler(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
static TEXTMETRIC TextInfo;
static int Length;
PAINTSTRUCT PaintStruct;
HDC hdc=NULL;
int x, y;
char Message[]="cmoWindow Test";
switch(iMsg)
{
case WM_CREATE:
hdc=GetWindowDC(hwnd);
GetTextMetrics(hdc, &TextInfo);
Length=strlen(Message);
ReleaseDC(hwnd, hdc);
break;
case WM_SIZE:
GetWindowRect(hwnd, &WindowRect);
break;
case WM_PAINT:
hdc=BeginPaint(hwnd, &PaintStruct);
SetTextColor(hdc, RGB(0, 0, 255));
x=(WindowRect.right-WindowRect.left)/2;
x=x-(Length*TextInfo.tmAveCharWidth)/2;
y=(WindowRect.bottom-WindowRect.top)/2;
y=y-(TextInfo.tmHeight)/2;
TextOut(hdc, x, y, Message, Length);
EndPaint(hwnd, &PaintStruct);
break;
case WM_DESTROY:
PostQuitMessage(NULL);
break;
}
return DefWindowProc (hwnd, iMsg, wParam, lParam);
}
And the source:
#include <windows.h>
#include "cmoWindow.h"
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
InitClass("Hello World");
return 0;
}
[edited by - Tigra7 on July 23, 2002 1:50:19 PM]
[edited by - Tigra7 on July 23, 2002 1:51:24 PM]