Fatboy
August 18th, 2004, 01:27 PM
Hey y'all! I programmed this:
#include <windows.h>
#include "Resource.h"
LRESULT CALLBACK WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
MSG msg;
static TCHAR szAppName[] = TEXT("Test program!!!!!");
WNDCLASSEX wndclass;
HWND hWindow;
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TEST));
wndclass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TEST_SM));
wndclass.hCursor = LoadCursor(0, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndclass.lpszMenuName = 0;
wndclass.lpszClassName = szAppName;
if (!RegisterClassEx(&wndclass))
return 0;
hWindow = CreateWindow(szAppName, szAppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640 + GetSystemMetrics(SM_CXFIXEDFRAME) * 2, 480 + GetSystemMetrics(SM_CYFIXEDFRAME) * 2 + GetSystemMetrics(SM_CYCAPTION), 0, 0, hInstance, 0);
ShowWindow(hWindow, iCmdShow);
UpdateWindow(hWindow);
HDC hDC;
PAINTSTRUCT ps;
HPEN hPen = CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
SelectObject(hDC, hPen);
hDC = BeginPaint(hWindow, &ps);
Rectangle(hDC, 32, 32, 128, 128);
DeleteObject(hPen);
EndPaint(hWindow, &ps);
while(GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWindow, msg, wParam, lParam);
}
I'm sorry for throwing all this code at you, but please have a look. What do you expect to happen when this is compiled? The reason why I wrote this was to try drawing outside the WndProc function switch statement, i.e. in the WinMain itself. I'm probably making a silly mistake, but.............it compiles fine, and runs fine. Well not really, because I was expecting the window to show a rectangle, but it shows nothing! As if I didn't write the painting code. Why?
#include <windows.h>
#include "Resource.h"
LRESULT CALLBACK WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
MSG msg;
static TCHAR szAppName[] = TEXT("Test program!!!!!");
WNDCLASSEX wndclass;
HWND hWindow;
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TEST));
wndclass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TEST_SM));
wndclass.hCursor = LoadCursor(0, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndclass.lpszMenuName = 0;
wndclass.lpszClassName = szAppName;
if (!RegisterClassEx(&wndclass))
return 0;
hWindow = CreateWindow(szAppName, szAppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640 + GetSystemMetrics(SM_CXFIXEDFRAME) * 2, 480 + GetSystemMetrics(SM_CYFIXEDFRAME) * 2 + GetSystemMetrics(SM_CYCAPTION), 0, 0, hInstance, 0);
ShowWindow(hWindow, iCmdShow);
UpdateWindow(hWindow);
HDC hDC;
PAINTSTRUCT ps;
HPEN hPen = CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
SelectObject(hDC, hPen);
hDC = BeginPaint(hWindow, &ps);
Rectangle(hDC, 32, 32, 128, 128);
DeleteObject(hPen);
EndPaint(hWindow, &ps);
while(GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWindow, msg, wParam, lParam);
}
I'm sorry for throwing all this code at you, but please have a look. What do you expect to happen when this is compiled? The reason why I wrote this was to try drawing outside the WndProc function switch statement, i.e. in the WinMain itself. I'm probably making a silly mistake, but.............it compiles fine, and runs fine. Well not really, because I was expecting the window to show a rectangle, but it shows nothing! As if I didn't write the painting code. Why?