• WindowsAPI小程序


    #include<windows.h>
    #include<tchar.h>
    LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
    
    INT WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszCmdParam,INT nCmdShow)
    {
    	HWND hMainWnd;
    	MSG msg;
    	WNDCLASS myWC;
    	if(!hPrevInstance)
    	{
    		myWC.style=CS_VREDRAW|CS_HREDRAW;
    		myWC.lpfnWndProc=WndProc;
    		myWC.cbClsExtra=0;
    		myWC.cbWndExtra=0;
    		myWC.hInstance=hInstance;
    		myWC.hIcon=LoadIcon(NULL,IDI_APPLICATION);
    		myWC.hCursor=LoadCursor(NULL,IDC_ARROW);
    		myWC.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
    		myWC.lpszMenuName=NULL;
    		myWC.lpszClassName=_T("MyWindowClass");
    		RegisterClass(&myWC);
    	}
    	hMainWnd=CreateWindow(_T("MyWindowClass"),_T("MyWindowAPItitle"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
    		NULL,NULL,hInstance,NULL);
    	ShowWindow(hMainWnd,SW_SHOWMAXIMIZED);
    	UpdateWindow(hMainWnd);
    	while(GetMessage(&msg,NULL,0,0))
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    	return msg.wParam;
    }
    LRESULT CALLBACK WndProc(HWND hMainwnd,UINT message,WPARAM wParam,LPARAM lParam)
    {
    	char messageleft[]="the left button have been pushed";
    	char messageright[]="the right button have pushed";
    	switch(message)
    	{
    	case WM_RBUTTONDOWN:
    		{
    			MessageBox(GetFocus(),_T("messageright"),_T("RButtonPushDown"),MB_OK|MB_ICONINFORMATION);
    			break;
    		}
    	case WM_LBUTTONDOWN:
    		{
    			MessageBox(GetFocus(),_T("messageleft"),_T("LButtonPushDown"),MB_OK|MB_ICONINFORMATION);
    			break;
    		}
    	case WM_DESTROY:
    		{
    			PostQuitMessage(0);
    			return 0;
    		}
    	default:break;
    	}
    	return DefWindowProc(hMainwnd,message,wParam,lParam);
    }

    1.注册窗口类

    2.创建窗口

    3.消息循环

    4.编写窗口消息处理函数


  • 相关阅读:
    数据库
    Activity组件
    view,视图组件
    360导航板式
    service音乐播放
    service
    音乐播放器组件
    获取时间字符串
    JDK服务器存储
    数据库_黑名单练习_完善服务广播
  • 原文地址:https://www.cnblogs.com/javafly/p/6037208.html
Copyright © 2020-2023  润新知