调用api函数做了一个图形界面,可是打开exe文件后没有反应啊,但进程中的确打开了
#include<windows.h>#include<stdio.h>
LRESULT CALLBACK WinXrProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow ) // show state)
{
WNDCLASS wnd;
wnd.cbClsExtra=0;
wnd.cbWndExtra=0;
wnd.hbrBackground=(HBRUSH)GetStockObject(DKGRAY_BRUSH);
wnd.hCursor=LoadCursor(NULL,IDC_CROSS);
wnd.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wnd.hInstance=hInstance;
wnd.lpfnWndProc=WinXrProc;
wnd.lpszClassName="XiangRong";
wnd.lpszMenuName=NULL;
wnd.style=CS_HREDRAW|CS_VREDRAW;
RegisterClass(&wnd);
HWND hwnd;
hwnd=CreateWindow("XiangRong","第一个程序",WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinXrProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam) // second message parameter
{
HDC Hdc;
PAINTSTRUCT ps;
switch(uMsg)
{
case WM_CHAR:
char sz[20];
sprintf(sz,"char is %d",wParam);
MessageBox(hwnd,sz,"提示",MB_OK);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse is clicked","提示",0);
HDC HDc;
HDc=GetDC(hwnd);
TextOut(HDc,0,50,"简单的窗口建立",strlen("简单的窗口建立"));
ReleaseDC(hwnd,HDc);
break;
case WM_PAINT:
Hdc=BeginPaint(hwnd,&ps);
TextOut(Hdc,0,100,"真他妈的难",strlen("真他妈的难"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的要退出","提示",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}