WindowsTip

VBS) PostMessage or SendMessage to external program

by 디케 posted Sep 21, 2013
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄

VBS) PostMessage or SendMessage to external program

 

  vbscript code

  const WM_CUSTOMMSG = 1024

      retval = System.SendMessage(hdl,WM_CUSTOMMSG)  
   or 
      retval = System.PostMessage(hdl,WM_CUSTOMMSG)

 

 

 

 

I wrote a little test program using Visual Studio 2003 in C++ unmanage code (SimpleApp.cpp source supplied below) and tried it against ArcPad to test the SendMessage (test script supplied below too). 
 
// Code fragment 1: SimpleApp.cpp
// (contains a single icon resource IDI_SIMPLEAPP)

#include "stdafx.h"
#include "Resource.h"

const TCHAR szTitle[] = TEXT("SimpleApp");
const TCHAR szWindowClass[] = TEXT("SimpleApp");

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

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR	lpCmdLine, int nCmdShow)
{
	WNDCLASSEX wcex;
	wcex.cbSize = sizeof(WNDCLASSEX); 
	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= (WNDPROC)WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, (LPCTSTR)IDI_SIMPLEAPP);
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= NULL;
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SIMPLEAPP);
	RegisterClassEx(&wcex);
	HWND hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
	if (!hWnd)
		return FALSE;
	ShowWindow(hWnd, nCmdShow);
	UpdateWindow(hWnd);
	MSG msg;
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return (int) msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hdc;
	switch (message) 
	{
	case WM_PAINT:
		hdc = BeginPaint(hWnd, &ps);
		EndPaint(hWnd, &ps);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	case 1024:
		MessageBox(hWnd, TEXT("1024 received"), TEXT("debug"), MB_OK);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}

--------------------------------------------------

REM Code fragment 2: test script

Dim w
w = System.FindWindow("SimpleApp", "SimpleApp")
Call System.SendMessage(w, 1024, 0, 0)

 

 

 

 


Articles

1 2 3 4 5