|
|
// youyici.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
HINSTANCE hInst;
LRESULT CALLBACK MainWndProc(HWND ,UINT ,WPARAM ,LPARAM );
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
char szClassName[] = "MainWclass";
WNDCLASSEX wc;
wc.cbSize =sizeof(WNDCLASSEX);
wc.style =CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc =(WNDPROC)MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = : oadIcon(NULL,IDI_APPLICATION);
wc.hCursor =::LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground =(HBRUSH)::GetStockObject(WHITE_BRUSH);
wc.lpszMenuName =NULL;
wc.lpszClassName =szClassName;
wc.hIconSm =NULL;
if(::RegisterClassEx(&wc) == NULL)
{
::MessageBox(NULL,"","error1",MB_OK);
return -1;
}
hInst = hInstance;
HWND hwnd = ::CreateWindowEx(
0,
szClassName,
"My First Window!",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
if(hwnd = NULL)
{
::MessageBox(NULL,"","error2",MB_OK);
return -1;
}
::ShowWindow(hwnd,nCmdShow);
::UpdateWindow(hwnd);
MSG msg;
while(::GetMessage(&msg,NULL,0,0))
{
::TranslateMessage(&msg);
: ispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK MainWndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch( message )
{
case WM_PAINT: //在后台窗口模式时
{
PAINTSTRUCT ps;
HDC hdc;
hdc=::BeginPaint(hwnd,&ps);
::TextOut(hdc,10,10,"mother",strlen("mother"));
::EndPaint(hwnd,&ps);
return 0;
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
} |
|