主题:[原创]编制一个简单的WINDOWS程序
//文件wnd2.cpp
#include "wnd2.h"
char szTitle[]="简单的Hello程序";
char szWindowClass[]="W32";
char szMenuName[]="NULL";
int APIENTRY WinMain(HINSTANCE hInstance ,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
MSG msg;
InitApplication(hInstance);
if(!InitInstance(hInstance,nCmdShow))return false ;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
ATOM InitApplication(HINSTANCE hInstance)
{
WNDCLASS wc;
wc.style=CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc=(WNDPROC)WndProc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=hInstance;
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName=szMenuName;
wc.lpszClassName=szWindowClass;
return RegisterClass(&wc);
}
BOOL InitInstance(HINSTANCE hInstance,int nCmdShow)
{
HWND hWnd;
hWnd=CreateWindow(
szWindowClass,
szTitle,
WS_OVERLAPPEDWINDOW|WS_VSCROLL|WS_HSCROLL,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
if(!hWnd)return false;
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
return true;
}
//文件wnd21.cpp
#include "wnd2.h"
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
char szHello[]="Hello";
switch(message)
{
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
TextOut(hdc,80,150,szHello,strlen(szHello));
EndPaint(hWnd,&ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,message,wParam,lParam);
}
return 0;
}
//文件wnd2.h
#include <windows.h>
extern char szTitle[];
extern char szWindowClass[];
ATOM InitApplication(HINSTANCE );
BOOL InitInstance(HINSTANCE ,int );
LRESULT CALLBACK WndProc (HWND ,UINT ,WPARAM ,LPARAM);
int APIENTRY WinMain(HINSTANCE ,HINSTANCE ,LPSTR ,int );
无法通过编译,请各位大侠帮帮忙?
#include "wnd2.h"
char szTitle[]="简单的Hello程序";
char szWindowClass[]="W32";
char szMenuName[]="NULL";
int APIENTRY WinMain(HINSTANCE hInstance ,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
MSG msg;
InitApplication(hInstance);
if(!InitInstance(hInstance,nCmdShow))return false ;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
ATOM InitApplication(HINSTANCE hInstance)
{
WNDCLASS wc;
wc.style=CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc=(WNDPROC)WndProc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=hInstance;
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName=szMenuName;
wc.lpszClassName=szWindowClass;
return RegisterClass(&wc);
}
BOOL InitInstance(HINSTANCE hInstance,int nCmdShow)
{
HWND hWnd;
hWnd=CreateWindow(
szWindowClass,
szTitle,
WS_OVERLAPPEDWINDOW|WS_VSCROLL|WS_HSCROLL,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
if(!hWnd)return false;
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
return true;
}
//文件wnd21.cpp
#include "wnd2.h"
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
char szHello[]="Hello";
switch(message)
{
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
TextOut(hdc,80,150,szHello,strlen(szHello));
EndPaint(hWnd,&ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,message,wParam,lParam);
}
return 0;
}
//文件wnd2.h
#include <windows.h>
extern char szTitle[];
extern char szWindowClass[];
ATOM InitApplication(HINSTANCE );
BOOL InitInstance(HINSTANCE ,int );
LRESULT CALLBACK WndProc (HWND ,UINT ,WPARAM ,LPARAM);
int APIENTRY WinMain(HINSTANCE ,HINSTANCE ,LPSTR ,int );
无法通过编译,请各位大侠帮帮忙?