zoukankan      html  css  js  c++  java
  • 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.编写窗口消息处理函数


  • 相关阅读:
    googleMapReduce
    leveldb0
    大端模式和小端模式
    信号
    js中判断对象类型的几种方法
    js DOM之基础详解
    JavaScript作用域与闭包总结
    SCRIPT438: 对象不支持“trim”属性或方法
    JS合并多个数组去重算法
    js的 break 和 continue 计算问题
  • 原文地址:https://www.cnblogs.com/javafly/p/6037208.html
Copyright © 2011-2022 走看看