Click here to Skip to main content
15,878,871 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionC-Style Exports Pin
Richard Andrew x6424-Nov-13 15:15
professionalRichard Andrew x6424-Nov-13 15:15 
AnswerRe: C-Style Exports Pin
Joe Woodbury24-Nov-13 16:45
professionalJoe Woodbury24-Nov-13 16:45 
GeneralRe: C-Style Exports Pin
Richard Andrew x6424-Nov-13 16:51
professionalRichard Andrew x6424-Nov-13 16:51 
GeneralRe: C-Style Exports Pin
Richard Andrew x6424-Nov-13 16:53
professionalRichard Andrew x6424-Nov-13 16:53 
AnswerRe: C-Style Exports Pin
«_Superman_»24-Nov-13 18:52
professional«_Superman_»24-Nov-13 18:52 
GeneralRe: C-Style Exports Pin
Richard Andrew x6425-Nov-13 6:19
professionalRichard Andrew x6425-Nov-13 6:19 
GeneralRe: C-Style Exports Pin
«_Superman_»25-Nov-13 19:26
professional«_Superman_»25-Nov-13 19:26 
QuestionHow to draw lines in a translucent window Pin
chengmingma22-Nov-13 16:42
chengmingma22-Nov-13 16:42 
C++
// DemoTest.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "DemoTest.h"

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst;								// current instance
TCHAR szTitle[MAX_LOADSTRING];					// The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];			// the main window class name


GdiplusStartupInput m_gdiplusStartupInput;
ULONG_PTR m_pGdiToken;
HWND g_hWnd = 0;
Image *g_pImageBack=0;
BLENDFUNCTION g_Blend;
int g_BakWidth, g_BakHeight;
bool isMouseDown=false;
POINT mousePos;


// Forward declarations of functions included in this code module:
ATOM				MyRegisterClass(HINSTANCE hInstance);
BOOL				InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK	About(HWND, UINT, WPARAM, LPARAM);
void Update();


int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	GdiplusStartup(&m_pGdiToken,&m_gdiplusStartupInput,NULL); 

	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;

	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_DEMOTEST, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_DEMOTEST));

	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0))
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	GdiplusShutdown(m_pGdiToken);
	return (int) msg.wParam;
}



//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
//    This function and its usage are only necessary if you want this code
//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get 'well formed' small icons associated
//    with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX);

	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_DEMOTEST));
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= MAKEINTRESOURCE(IDC_DEMOTEST);
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

	return RegisterClassEx(&wcex);
}

//
//   FUNCTION: InitInstance(HINSTANCE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   g_Blend.SourceConstantAlpha = int(0 * 2.55);//1~255
   g_Blend.BlendOp=0; //theonlyBlendOpdefinedinWindows2000
   g_Blend.BlendFlags=0; //nothingelseisspecial...
   g_Blend.AlphaFormat=1; //...
   g_Blend.SourceConstantAlpha=255;//AC_SRC_ALPHA
   DWORD dwExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
   SetWindowLong(hWnd, GWL_STYLE, dwExStyle ^ WS_EX_TOOLWINDOW);
   dwExStyle = ::GetWindowLong(hWnd, GWL_EXSTYLE);
   g_pImageBack = Image::FromFile(_T("C:\\Users\\Cmma\\Desktop\\2.png"));
   ImageType t = g_pImageBack->GetType();
   //bkImg.FromFile();
   g_BakWidth = g_pImageBack->GetWidth();
   g_BakHeight = g_pImageBack->GetHeight();
   g_hWnd=hWnd;



   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);
   Update();
   return TRUE;
}

//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;

	switch (message)
	{
	case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// Parse the menu selections:
		switch (wmId)
		{
		case IDM_ABOUT:
			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
			break;
		case IDM_EXIT:
			DestroyWindow(hWnd);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		break;
	case WM_LBUTTONDOWN:
		isMouseDown=true;
		GetCursorPos(&mousePos);
		ScreenToClient(hWnd,&mousePos);
		break;
	case WM_MOUSEMOVE:
		if(isMouseDown)
		{

			hdc=::GetDC(hWnd);
			Graphics g(hdc);
			Pen pen(RGB(255,0,0),3);
			g.DrawLine(&pen,0,0,100,100);
			::ReleaseDC(hWnd,hdc);
			SendMessage(hWnd,WM_PAINT,0,0);
		}
		break;
	case WM_LBUTTONUP:
		isMouseDown=false;
		break;
	case WM_PAINT:
		hdc = BeginPaint(hWnd, &ps);
		// TODO: Add any drawing code here...
		Update();
		EndPaint(hWnd, &ps);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}

// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	UNREFERENCED_PARAMETER(lParam);
	switch (message)
	{
	case WM_INITDIALOG:
		return (INT_PTR)TRUE;

	case WM_COMMAND:
		if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
		{
			EndDialog(hDlg, LOWORD(wParam));
			return (INT_PTR)TRUE;
		}
		break;
	}
	return (INT_PTR)FALSE;
}


void Update()
{
	HDC hdcTemp= ::GetDC(g_hWnd);
	HDC hdcMemory=CreateCompatibleDC(hdcTemp);
	HBITMAP hBitMap=CreateCompatibleBitmap(hdcTemp, g_BakWidth, g_BakHeight);
	SelectObject(hdcMemory, hBitMap);
	HDC hdcScreen=::GetDC (g_hWnd);
	RECT rct;
	::GetWindowRect(g_hWnd, &rct);
	POINT ptWinPos={rct.left,rct.top};
	Graphics graph(hdcMemory);
	Point points[] = { Point(0, 0),
		Point(g_BakWidth, 0),
		Point(0, g_BakHeight)
	};
	graph.DrawImage(g_pImageBack, points, 3);
	POINT ptDst;
	ptDst.x = rct.left;
	ptDst.y = rct.top;
	SIZE size={g_BakWidth, g_BakHeight};
	POINT pt;
	pt.x = 0;
	pt.y = 0;
	DWORD dwExStyle = GetWindowLong(g_hWnd,GWL_EXSTYLE);
	if((dwExStyle & WS_EX_LAYERED) != WS_EX_LAYERED)
	{//WS_EX_LAYERED is 0x00080000
		SetWindowLong(g_hWnd, GWL_EXSTYLE,dwExStyle^WS_EX_LAYERED);
	}


	if (!UpdateLayeredWindow( g_hWnd, hdcScreen, &ptWinPos,
		&size, hdcMemory, &pt, 0, &g_Blend, 2))
	{
		DWORD dwError = ::GetLastError();
		printf("failed");
	}

	graph.ReleaseHDC(hdcMemory);
	::DeleteObject(hBitMap);
	::DeleteDC(hdcMemory);;
	::ReleaseDC(g_hWnd, hdcTemp);
	::ReleaseDC(g_hWnd, hdcScreen);
}

AnswerRe: How to draw lines in a translucent window Pin
enhzflep22-Nov-13 18:50
enhzflep22-Nov-13 18:50 
Question[SOLVED] What is the x64 #define? Pin
Richard Andrew x6422-Nov-13 11:34
professionalRichard Andrew x6422-Nov-13 11:34 
SuggestionRe: [SOLVED] What is the x64 #define? Pin
Randor 22-Nov-13 12:51
professional Randor 22-Nov-13 12:51 
GeneralRe: [SOLVED] What is the x64 #define? Pin
Richard Andrew x6422-Nov-13 12:54
professionalRichard Andrew x6422-Nov-13 12:54 
GeneralRe: [SOLVED] What is the x64 #define? Pin
Randor 22-Nov-13 13:13
professional Randor 22-Nov-13 13:13 
QuestionTransparent TreeView Control in MFC CPP Pin
kalyani.homkar20-Nov-13 23:59
kalyani.homkar20-Nov-13 23:59 
AnswerRe: Transparent TreeView Control in MFC CPP Pin
kalyani.homkar21-Nov-13 0:05
kalyani.homkar21-Nov-13 0:05 
QuestionSSL CONNECTION Pin
Member 1041375220-Nov-13 20:44
Member 1041375220-Nov-13 20:44 
QuestionRe: SSL CONNECTION Pin
David Crow22-Nov-13 5:58
David Crow22-Nov-13 5:58 
QuestionCDhtmlDialog : With JavaScript calling C++ Pin
Don Guy20-Nov-13 16:02
Don Guy20-Nov-13 16:02 
QuestionStatic Analysis code reqired for C++ Pin
GauranG Shah20-Nov-13 0:59
GauranG Shah20-Nov-13 0:59 
AnswerRe: Static Analysis code reqired for C++ Pin
Chris Losinger20-Nov-13 1:43
professionalChris Losinger20-Nov-13 1:43 
GeneralRe: Static Analysis code reqired for C++ Pin
GauranG Shah20-Nov-13 4:45
GauranG Shah20-Nov-13 4:45 
AnswerRe: Static Analysis code reqired for C++ Pin
Marco Bertschi20-Nov-13 10:13
protectorMarco Bertschi20-Nov-13 10:13 
AnswerRe: Static Analysis code reqired for C++ Pin
Joe Woodbury22-Nov-13 5:37
professionalJoe Woodbury22-Nov-13 5:37 
GeneralRe: Static Analysis code reqired for C++ Pin
Stefan_Lang26-Nov-13 22:51
Stefan_Lang26-Nov-13 22:51 
GeneralRe: Static Analysis code reqired for C++ Pin
Joe Woodbury27-Nov-13 4:19
professionalJoe Woodbury27-Nov-13 4:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.