编写的windows小程序运行后一闪而过,帮忙解决一下
写了一个小程序,可是运行时居然一闪而过,大家帮忙解决一下。
EditBoxDemo.c:
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "EditBoxDemo.h "
HWND hEditItem,hEditResult,
hButtonAdd,hButtonReset,hButtonCancel,
hStatic1,hStatic2;
HINSTANCE hInst;
char lpszAddItem[] = " ";
char lpszResult[] = " ";
char *stop;
long nAddItem,nResult;
int nMax;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInst,
LPSTR lpszCmdLine,
int nCmdShow
)
{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
char lpszClassName[] = "编辑框 ";
char lpszTitle[] = "编辑框示例-加法器 ";
wndclass.style = 0;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = lpszClassName;
if(!RegisterClass(&wndclass))
{
MessageBeep(0);
return 0;
}
hwnd = CreateWindow(
lpszClassName,
lpszTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg,NULL,0,0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
LRESULT CALLBACK WndProc(
HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam
)
{
switch(message)
{
case WM_CREATE:
hStatic1 = CreateWindow
( "STATIC ",
"加数: ",
WS_CHILD|WS_VISIBLE,
40,20,
50,20,
hwnd,
(HMENU)IDS_1,
hInst,
NULL);
hStatic2 = CreateWindow
( "STATIC ",
"结果: ",
WS_CHILD|WS_VISIBLE,
40,70,
50,20,
hwnd,
(HMENU)IDS_2,
hInst,
NULL);
hEditItem = CreateWindow
( "EDIT ",
NULL,
WS_CHILD|WS_VISIBLE|ES_LEFT|WS_BORDER,
130,20,
80,20,
hwnd,
(HMENU)IDE_ADDITEM,
hInst,
NULL);
hEditResult= CreateWindow
( "EDIT ",
NULL,
WS_CHILD|WS_VISIBLE|ES_LEFT|WS_BORDER|ES_READONLY,
130,70,
80,20,
hwnd,
(HMENU)IDE_RESULT,