程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Win32 CreateWindow GdiPlus

Win32 CreateWindow GdiPlus

編輯:C++入門知識

#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) ;
}

  

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved