Win32 CreateWindow GdiPlus

#include "stdafx.h"
#include "TestGidPlus.h"

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	GdiplusStartupInput gdiplusStartupInput;
	ULONG_PTR           gdiplusToken;
	// Initialize GDI+.
	GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

	WNDCLASSEX wcApp;
	wcApp.lpszClassName			= TEXT("Test_Window");
	wcApp.cbSize				= sizeof(wcApp);
	wcApp.style					= CS_HREDRAW | CS_VREDRAW;
	wcApp.hInstance				= hInstance;
	wcApp.cbWndExtra			= 0;
	wcApp.cbClsExtra			= 0;
	wcApp.hCursor				= LoadCursor(NULL,IDC_ARROW);
	wcApp.hIcon					= LoadIcon(NULL,IDI_APPLICATION);
	wcApp.lpfnWndProc			= WndProc;
	wcApp.hCursor				= LoadCursor(NULL,IDC_ARROW);
	wcApp.hbrBackground			= (HBRUSH)(COLOR_WINDOW);
	wcApp.lpszMenuName			= NULL;
	wcApp.hIconSm				= NULL;
	RegisterClassExW(&wcApp);

	HWND hwnd = CreateWindowExW (NULL, TEXT("Test_Window"), TEXT(""), WS_OVERLAPPEDWINDOW, 100, 100, 600, 400, NULL, NULL, hInstance, NULL);
	ShowWindow(hwnd,SW_NORMAL);
	UpdateWindow(hwnd);
	MSG msg;
	while (GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	GdiplusShutdown(gdiplusToken);
	return msg.lParam;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	LRESULT b;
	PAINTSTRUCT ps;
	HDC hdc;
	switch (message)
	{
	case WM_CREATE:
		//SendMessage(hwnd,WM_PAINT,0,0);
		break;
	case WM_PAINT:
		{
			///////////////////Gdiplus与Gdi混合实现双缓冲////////////////////
			//HDC hMemDC = CreateCompatibleDC(m_hDC);
			//HBITMAP hMemBitmap = CreateCompatibleBitmap(m_hDC, DEFAULT_STATUS_WIDTH, DEFAULT_STATUS_HEIGHT);
			//SelectObject(hMemDC, hMemBitmap);
			//Graphics *memGraphics = new Graphics(hMemDC);
			//Pen pen(Color(192, 192, 192));
			//SolidBrush brush(Color(255, 255, 255));
			//memGraphics->FillRectangle(&brush, xPos, yPos, DEFAULT_STATUS_WIDTH, DEFAULT_STATUS_HEIGHT);
			//memGraphics->DrawRectangle(&pen, xPos, yPos, DEFAULT_STATUS_WIDTH, DEFAULT_STATUS_HEIGHT);
			//for (int i = 0; i < SMALL_IMAGE_COUNT; i++)
			//{
			//	DrawImageFromId(memGraphics, imgID[i], imgXPos[i], imgYPos[i]);
			//}
			//DeleteObject(hMemBitmap);
			//BitBlt(m_hDC, xPos, yPos, DEFAULT_STATUS_WIDTH, DEFAULT_STATUS_HEIGHT, hMemDC, 0, 0, SRCCOPY);
			//DeleteDC(hMemDC);
			//delete memGraphics;

			hdc = BeginPaint(hwnd, &ps);
			Graphics graphics(hdc);
			Pen pen(Color(255, 0, 0));
			graphics.DrawLine(&pen, 0, 0, 0, 500);
			EndPaint(hwnd, &ps);
			break;
		}
	case WM_NCHITTEST:
		{
			POINT pt;
			pt.x = GET_X_LPARAM(lParam);
			pt.y = GET_Y_LPARAM(lParam);

			RECT rcClient;
			GetClientRect(hwnd, &rcClient);

			b = DefWindowProc(hwnd,message,wParam,lParam);
			switch(b)
			{
			case HTCLIENT:
				SetWindowText(hwnd,TEXT("点击的是客户区"));
				return b;
			case HTCAPTION:
				SetWindowText(hwnd,TEXT("点击的是标题栏"));
				return b;
			case HTBOTTOM:
				SetWindowText(hwnd,TEXT("点击的是下边框"));
				return b;
			case HTBOTTOMLEFT:
				SetWindowText(hwnd,TEXT("点击的是左下边框"));
				return b;
				return b;
			case HTCLOSE:
				SetWindowText(hwnd,TEXT("点击的是关闭按钮"));
				return b;
			case HTLEFT:
				SetWindowText(hwnd,TEXT("点击的是左边框"));
				return b;
			case HTMAXBUTTON:
				SetWindowText(hwnd,TEXT("点击的是最大化按钮"));
				return b;
			case HTMINBUTTON:
				SetWindowText(hwnd,TEXT("点击的是最小化按钮"));
				return b;
			case HTRIGHT:
				SetWindowText(hwnd,TEXT("点击的是右边框"));
				return b;
			case HTSYSMENU:
				SetWindowText(hwnd,TEXT("点击的是系统菜单"));
				return b;
			case HTTOP:
				SetWindowText(hwnd,TEXT("点击的是上边框"));
				return b;
			case HTBOTTOMRIGHT:
				SetWindowText(hwnd,TEXT("点击的是右下边框"));
				return b;
			case HTTOPRIGHT:
				SetWindowText(hwnd,TEXT("点击的是右上边框"));
				return b;
			case HTTOPLEFT:
				SetWindowText(hwnd,TEXT("点击的是左上边框"));
				return b;
			default:
				return b;
			}
		}
	case WM_DESTROY:
		PostQuitMessage (0) ;
		return 0 ;
	}
	return DefWindowProc (hwnd, message, wParam, lParam) ;
}

  

Win32 CreateWindow GdiPlus,布布扣,bubuko.com

时间: 2024-10-14 08:11:09

Win32 CreateWindow GdiPlus的相关文章

对话框

模式对话框 创建 Win32:DialogBox() MFC:DoMoal() 销毁:EndDialog() 非模式  自己手动销毁 创建: Win32: CreateWindow() MFC: Create()   ShowWindow UpdateWindow 销毁:DestroyWindow() //颜色对话框 CColorDialog colDlg; if (IDOK == colDlg.DoModal()) { CString str("123"); CClientDC dc

win32窗口机制之CreateWindow

CreateWindow 函数功能:该函数创建一个重叠式窗口.弹出式窗口或子窗口.它指定窗口类,窗口标题,窗口 风格,以及窗口的初始位置及大小(可选的).该函数也指定该窗口的父窗口或所属窗口(如果存在 的话),及窗口的菜单.若要使用除CreateWindow函数支持的风格外的扩展风格,则使用 CreateWindowEx函数代替CreateWindow函数. 函数原型:HWND CreateWindow(LPCTSTR lpClassName,LPCTSTR lpWindowName,DWORD

win32用GDI+加载png图片作为背景图

#include <windows.h> #include <gdiplus.h> /* GDI+ startup token */ ULONG_PTR gdiplusStartupToken; /* Declare Windows procedure */ LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); // UpdateLayeredWindow Defination typedef BOOL(*UP

纯win32实现PNG图片透明窗体

#include <windows.h> #include <gdiplus.h> /*  GDI+ startup token */ ULONG_PTR gdiplusStartupToken; /*  Declare Windows procedure  */ LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); // UpdateLayeredWindow Defination typedef BOOL(

Win32中安全的子类化(翻译)

关于子类化的话题虽然有些旧,但它至今仍然不失为一种开发Windows的强有力技术,在MFC的内核.甚至.NET的内核中都离不开它,希望本连载能对Windows开发的爱好者有所帮助. 原文标题:Safe Subclassing in Win32作者:Kyle MarshMSDN技术组 点击此处查看原文 摘要 本文描述了Win32环境下的子类化,描述了它是如何工作的以及实现安全的子类化必须要遵循的规则.本文涵盖了实例子类化和全局子类化.而超类化则作为一个全局子类化的可选替代方案被介绍.从Win16到

游戏开发(三)——WIN32 黑白棋(三)——游戏画面的现实

整个游戏分3部分介绍. 1.棋局的现实 2.AI的现实 3.游戏画面的现实 提供一下完整项目下载 这是第三部分:画面的显示 这部分其实就比较简单的,说白了就是api的堆砌. 主要了解下windows的消息机制,以及怎么画图 主要是分别封装了下对棋盘,棋子,以及当前轮到谁,当前比分是多少,就是游戏画面上不同的部分的绘制. void DrawReversiBoard(); void DrawReversiPieces(EnumReversiPiecesType type, int row_y, in

win32汇编--第一个窗体程序

窗口创建过程     GetModuleHandle->RtlZeroMemory->LoadCursor->RegisterClassEx->CreateWindowsEx->ShowWindow->UpdateWindow 获得模块句柄->结构体初始化(填0)->加载光标->注册窗体类->创建窗体->显示窗体->更新客户区 win32API函数定义 GetModuleHandle,lpModuleName 参数:lpModuleN

win32 摄像头捕获系统vfw

[html] view plaincopy //win32 摄像头捕获系统vfw [html] view plaincopy //  VideoRecord.h ///  用于定义一些资源ID [html] view plaincopy #include "resource.h" //#define EXIT  104 #define HELP  105 #define MINIMIZE 106 //#define DISPLAY  107 #define BUTTONSIZE  15

win32 sdk绘制ListBox控件

1>产生: [html] view plaincopy // HWND CreateLB(HWND parentWnd) { HWND hListBox=0; hListBox = CreateWindow("LISTBOX", NULL, WS_CHILD|WS_VSCROLL | WS_TABSTOP | LBS_STANDARD | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS, 230, 20, 60, 80, parentWnd, (HMENU