windows编程过程

来源:互联网 发布:水利水电计价软件 编辑:程序博客网 时间:2024/06/16 09:51

//孙鑫视频1整理

#include<windows.h>

#include<stdio.h>


LRESULT CALLBACK Function(
  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 ws;
ws.cbClsExtra=0;
ws.cbWndExtra=0;
ws.hbrBackground=(HBRUSH)GetStockObject(DKGRAY_BRUSH);
ws.hCursor=LoadCursor(NULL,IDC_APPSTARTING);
ws.hIcon=LoadIcon(NULL,IDI_EXCLAMATION);
ws.hInstance=hInstance;
ws.lpfnWndProc=Function;
ws.lpszClassName="Kitus";
ws.lpszMenuName=NULL;
ws.style=CS_VREDRAW|CS_HREDRAW;


RegisterClass(&ws);


HWND hwnd;
//hwnd=CreateWindow("Kitus","Kitus window",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
// NULL,NULL,hInstance,NULL);
hwnd=CreateWindow("Kitus","窗口名称",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
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 Function(
  HWND hwnd,      // handle to window
  UINT uMsg,      // message identifier
  WPARAM wParam,  // first message parameter
  LPARAM lParam   // second message parameter
)
{
PAINTSTRUCT ps;
HDC hdc;
switch(uMsg)
{
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,0,0,"Kitus Kitus Kitus Kitus",strlen("Kitus Kitus Kitus Kitus"));
EndPaint(hwnd,&ps);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"Left Button Down!","Information",MB_OK);
hdc=GetDC(hwnd);
TextOut(hdc,0,50,"Left Button Down!",strlen("Left Button Down!"));
ReleaseDC(hwnd,hdc);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"Do you want to close the window?","Warning",MB_YESNO))
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0); 
break;
default: 
return DefWindowProc(hwnd, uMsg, wParam, lParam);    //此处必须有return返回默认消息处理,否则无法实现消息正常显示
}
return 0;
}



0 0