偶是新手,照着例子写了此程序,通过了编译,链接,但不出现窗口,请各位高手指教;
#include "stdafx.h"
#include "windows.h"
#include "stdio.h"
LRESULT CALLBACK longProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam );
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
WNDCLASS cls;
cls.cbClsExtra=0;
cls.cbWndExtra=0;
cls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
cls.hCursor=LoadCursor(NULL,IDC_CROSS);
cls.hIcon=LoadIcon(NULL,IDI_ERROR);
cls.hInstance=hInstance;
cls.lpfnWndProc=longProc;
cls.lpszClassName="longming";
cls.lpszMenuName=NULL;
cls.style=CS_HREDRAW|CS_VREDRAW;
HWND hwnd;
RegisterClass(&cls);
hwnd=CreateWindow("longming","myfirstwin32",WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL);
::ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,hwnd,NULL,NULL))
{TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK longProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam )
{ switch(uMsg)
{case WM_PAINT:
HDC hdc;
PAINTSTRUCT ps;
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,300,300,"l want to surpass you",strlen("l want to marry you"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
MessageBox(hwnd,"do you want to close the window","close the window",MB_YESNO);
DestroyWindow(hwnd);
break;
case WM_CHAR:
char sz[12];
sprintf(sz,"you input char is %c",wParam);
MessageBox(hwnd,sz,"you have input the char",MB_OKCANCEL);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_LBUTTONDOWN:
HDC dc;
dc=GetDC(hwnd);
if(IDOK==MessageBox(hwnd,"You have cllicked the window ","Mouse",MB_OKCANCEL))
TextOut(dc,234,234,"you clicked the window",0);
break;
default: DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}