Click here to Skip to main content
15,894,720 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Need help to pan client area of a window using win32 api / mfc Pin
Richard MacCutchan20-Aug-12 22:34
mveRichard MacCutchan20-Aug-12 22:34 
GeneralRe: Need help to pan client area of a window using win32 api / mfc Pin
Richard MacCutchan20-Aug-12 22:36
mveRichard MacCutchan20-Aug-12 22:36 
AnswerRe: Need help to pan client area of a window using win32 api / mfc Pin
Sunil P V20-Aug-12 22:38
Sunil P V20-Aug-12 22:38 
GeneralRe: Need help to pan client area of a window using win32 api / mfc Pin
Richard MacCutchan21-Aug-12 0:37
mveRichard MacCutchan21-Aug-12 0:37 
GeneralRe: Need help to pan client area of a window using win32 api / mfc Pin
Sunil P V24-Aug-12 1:29
Sunil P V24-Aug-12 1:29 
GeneralRe: Need help to pan client area of a window using win32 api / mfc Pin
Member 935377622-Aug-12 21:55
Member 935377622-Aug-12 21:55 
GeneralRe: Need help to pan client area of a window using win32 api / mfc Pin
Sunil P V24-Aug-12 1:31
Sunil P V24-Aug-12 1:31 
AnswerRe: Need help to pan client area of a window using win32 api / mfc Pin
pasztorpisti21-Aug-12 4:59
pasztorpisti21-Aug-12 4:59 
This question is a duplicate of this: http://www.codeproject.com/Messages/4336758/How-to-pan-client-area-of-a-window-using-Cplusplus.aspx[^]
My detailed answer to it: http://www.codeproject.com/Messages/4337474/Re-How-to-pan-a-window-using-Cplusplus-VCplusplus-.aspx[^]
I recommended this minimal program to modify to implement your panning: Using SetCapture() and ReleaseCapture() correctly (usually during a drag n' drop operation).[^]

And here is the modified version of the recommended source:

main.cpp:
C++
#include <windows.h>
HINSTANCE g_hInstance = (HINSTANCE)GetModuleHandle(NULL);
HWND g_hMainWnd = NULL;
bool g_MovingMainWnd = false;
POINT g_OrigCursorPos;
POINT g_PanStartIconPos;
HICON g_Icon = LoadIcon(NULL, IDI_EXCLAMATION);
POINT g_IconPos = { 0, 0 };
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
	{
	case WM_LBUTTONDOWN:
		// here you can add extra check and decide whether to start
		// the window move or not
		if (GetCursorPos(&g_OrigCursorPos))
		{
			RECT rt;
			GetWindowRect(hWnd, &rt);
			g_PanStartIconPos.x = g_IconPos.x;
			g_PanStartIconPos.y = g_IconPos.y;
			g_MovingMainWnd = true;
			SetCapture(hWnd);
			SetCursor(LoadCursor(NULL, IDC_SIZEALL));
		}
		return 0;
	case WM_LBUTTONUP:
		ReleaseCapture();
		return 0;
	case WM_CAPTURECHANGED:
		g_MovingMainWnd = (HWND)lParam == hWnd;
		return 0;
	case WM_MOUSEMOVE:
		if (g_MovingMainWnd)
		{
			POINT pt;
			if (GetCursorPos(&pt))
			{
				g_IconPos.x = g_PanStartIconPos.x + (pt.x - g_OrigCursorPos.x);
				g_IconPos.y = g_PanStartIconPos.y + (pt.y - g_OrigCursorPos.y);
				// forcing a WM_PAINT
				InvalidateRect(hWnd, NULL, TRUE);
			}
		}
		return 0;
	case WM_PAINT:
		{
			PAINTSTRUCT ps;
			if (HDC dc = BeginPaint(hWnd, &ps))
			{
				DrawIcon(dc, g_IconPos.x, g_IconPos.y, g_Icon);
				EndPaint(hWnd, &ps);
			}
		}
		return 0;
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	}
	return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
bool CreateMainWnd()
{
	static const char CLASS_NAME[] = "MainWndClass";
	WNDCLASS wc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wc.hInstance = g_hInstance;
	wc.lpfnWndProc = &MainWndProc;
	wc.lpszClassName = CLASS_NAME;
	wc.lpszMenuName = NULL;
	wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
	if (!RegisterClass(&wc))
		return false;
	g_hMainWnd = CreateWindowEx(
		0,
		CLASS_NAME,
		"Main Window",
		WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
		CW_USEDEFAULT, CW_USEDEFAULT, 300, 200,
		NULL,
		NULL,
		g_hInstance,
		NULL
		);
	return true;
}
int main()
{
	if (!CreateMainWnd())
		return -1;
	ShowWindow(g_hMainWnd, SW_SHOW);
	UpdateWindow(g_hMainWnd);
	MSG msg;
	while (GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return (int)msg.wParam;
}

GeneralRe: Need help to pan client area of a window using win32 api / mfc Pin
Member 935377622-Aug-12 22:48
Member 935377622-Aug-12 22:48 
GeneralRe: Need help to pan client area of a window using win32 api / mfc Pin
pasztorpisti22-Aug-12 23:07
pasztorpisti22-Aug-12 23:07 
QuestionTrying not to display the "description" part of a tooltip. (MFC) Pin
Maximilien20-Aug-12 5:03
Maximilien20-Aug-12 5:03 
QuestionCan not catch OnKeyup on CListCtrl Pin
_Flaviu20-Aug-12 5:03
_Flaviu20-Aug-12 5:03 
AnswerRe: Can not catch OnKeyup on CListCtrl Pin
Software_Developer20-Aug-12 9:15
Software_Developer20-Aug-12 9:15 
QuestionBITMAPINFOHEADER working in Debug but not in Release Pin
002comp19-Aug-12 21:15
002comp19-Aug-12 21:15 
AnswerRe: BITMAPINFOHEADER working in Debug but not in Release Pin
Endurion_19-Aug-12 22:39
Endurion_19-Aug-12 22:39 
GeneralRe: BITMAPINFOHEADER working in Debug but not in Release Pin
002comp19-Aug-12 22:43
002comp19-Aug-12 22:43 
GeneralRe: BITMAPINFOHEADER working in Debug but not in Release Pin
Endurion_20-Aug-12 5:01
Endurion_20-Aug-12 5:01 
AnswerRe: BITMAPINFOHEADER working in Debug but not in Release [Solved] but need one Suggestion Pin
002comp19-Aug-12 22:41
002comp19-Aug-12 22:41 
AnswerRe: BITMAPINFOHEADER working in Debug but not in Release Pin
CPallini19-Aug-12 23:00
mveCPallini19-Aug-12 23:00 
QuestionModeless Dialog box using win32 API only Pin
csrss19-Aug-12 7:14
csrss19-Aug-12 7:14 
AnswerRe: Modeless Dialog box using win32 API only Pin
pasztorpisti19-Aug-12 12:49
pasztorpisti19-Aug-12 12:49 
GeneralRe: Modeless Dialog box using win32 API only Pin
csrss19-Aug-12 21:03
csrss19-Aug-12 21:03 
GeneralRe: Modeless Dialog box using win32 API only Pin
pasztorpisti20-Aug-12 1:49
pasztorpisti20-Aug-12 1:49 
Generaljust want to find a friend Pin
cnmqy19-Aug-12 0:56
cnmqy19-Aug-12 0:56 
GeneralRe: just want to find a friend Pin
Richard MacCutchan19-Aug-12 2:37
mveRichard MacCutchan19-Aug-12 2:37 

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.