<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[popupmenu ohne fenster]]></title><description><![CDATA[<p>hi, ich möchte eine minianwendung schreiben, die ein menu öffnet ohne ein fester offen zu haben.<br />
Das ist an sich nicht so schwer.</p>
<p>Das menu öffne ich mit TrackPopupMenu.<br />
Das Problem ist, dass die funktion blockert und scheinbar nur durch einen klick auf eins der menuitems beendet werden kann.</p>
<p>gibt es eine möglichkeit (oder andere Art und Weise ein Menu zu öffnen) sich in die messageprocedur des Menus zu klinken, um zb. Tastaturevents zu verarbeiten?</p>
<pre><code class="language-cpp">#include &quot;stdafx.h&quot;
#include &quot;resource.h&quot;

#include &quot;stdio.h&quot;

// Global Variables:
HINSTANCE hInst;								// current instance
TCHAR* szTitle = TEXT(&quot;test&quot;);					// The title bar text

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

HMENU s_hmenu;
const int s_count = 10;
char  s_items[s_count][10];
static const int IDBASE = 5236;
HWND  s_hwnd;

void createFileMenu()
{
   s_hmenu = CreatePopupMenu();

   for(int i=0; i&lt;s_count; ++i)
   {
     sprintf(s_items[i], &quot;item %d&quot;, i);
     AppendMenu(s_hmenu, MF_STRING, IDBASE+i, s_items[i]);
   }
}

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

	MSG msg;

	// Initialize global strings
	MyRegisterClass(hInstance);

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

  createFileMenu();

  POINT curCurPos;
  GetCursorPos(&amp;curCurPos);
  TrackPopupMenu(s_hmenu, TPM_LEFTALIGN	|TPM_LEFTBUTTON, curCurPos.x, curCurPos.y, 0, s_hwnd, NULL);

	// Main message loop:
	while (GetMessage(&amp;msg, NULL, 0, 0))
	{
			TranslateMessage(&amp;msg);
			DispatchMessage(&amp;msg);
	}

	return (int) msg.wParam;
}

ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX);

	wcex.style			  = 0;
	wcex.lpfnWndProc	= WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= 0;
	wcex.hCursor		= 0;
	wcex.hbrBackground	= 0;
	wcex.lpszMenuName	= 0;
	wcex.lpszClassName	= szTitle;
	wcex.hIconSm		= 0;

	return RegisterClassEx(&amp;wcex);
}

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{

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

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

   if (!s_hwnd)
   {
      return FALSE;
   }

   return TRUE;
}

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:
    if(    (wmId &gt;= IDBASE)
        &amp;&amp; (wmId &lt;= s_count + IDBASE) )
    {
      int id = wmId-IDBASE;
      MessageBox(s_hwnd, s_items[id], &quot;item&quot;, 0);
      ExitProcess(0);
    }
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/229380/popupmenu-ohne-fenster</link><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Apr 2026 05:37:21 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/229380.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 10 Dec 2008 22:05:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to popupmenu ohne fenster on Wed, 10 Dec 2008 22:11:10 GMT]]></title><description><![CDATA[<p>hi, ich möchte eine minianwendung schreiben, die ein menu öffnet ohne ein fester offen zu haben.<br />
Das ist an sich nicht so schwer.</p>
<p>Das menu öffne ich mit TrackPopupMenu.<br />
Das Problem ist, dass die funktion blockert und scheinbar nur durch einen klick auf eins der menuitems beendet werden kann.</p>
<p>gibt es eine möglichkeit (oder andere Art und Weise ein Menu zu öffnen) sich in die messageprocedur des Menus zu klinken, um zb. Tastaturevents zu verarbeiten?</p>
<pre><code class="language-cpp">#include &quot;stdafx.h&quot;
#include &quot;resource.h&quot;

#include &quot;stdio.h&quot;

// Global Variables:
HINSTANCE hInst;								// current instance
TCHAR* szTitle = TEXT(&quot;test&quot;);					// The title bar text

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

HMENU s_hmenu;
const int s_count = 10;
char  s_items[s_count][10];
static const int IDBASE = 5236;
HWND  s_hwnd;

void createFileMenu()
{
   s_hmenu = CreatePopupMenu();

   for(int i=0; i&lt;s_count; ++i)
   {
     sprintf(s_items[i], &quot;item %d&quot;, i);
     AppendMenu(s_hmenu, MF_STRING, IDBASE+i, s_items[i]);
   }
}

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

	MSG msg;

	// Initialize global strings
	MyRegisterClass(hInstance);

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

  createFileMenu();

  POINT curCurPos;
  GetCursorPos(&amp;curCurPos);
  TrackPopupMenu(s_hmenu, TPM_LEFTALIGN	|TPM_LEFTBUTTON, curCurPos.x, curCurPos.y, 0, s_hwnd, NULL);

	// Main message loop:
	while (GetMessage(&amp;msg, NULL, 0, 0))
	{
			TranslateMessage(&amp;msg);
			DispatchMessage(&amp;msg);
	}

	return (int) msg.wParam;
}

ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX);

	wcex.style			  = 0;
	wcex.lpfnWndProc	= WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= 0;
	wcex.hCursor		= 0;
	wcex.hbrBackground	= 0;
	wcex.lpszMenuName	= 0;
	wcex.lpszClassName	= szTitle;
	wcex.hIconSm		= 0;

	return RegisterClassEx(&amp;wcex);
}

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{

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

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

   if (!s_hwnd)
   {
      return FALSE;
   }

   return TRUE;
}

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:
    if(    (wmId &gt;= IDBASE)
        &amp;&amp; (wmId &lt;= s_count + IDBASE) )
    {
      int id = wmId-IDBASE;
      MessageBox(s_hwnd, s_items[id], &quot;item&quot;, 0);
      ExitProcess(0);
    }
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1628519</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1628519</guid><dc:creator><![CDATA[vlad_tepesch]]></dc:creator><pubDate>Wed, 10 Dec 2008 22:11:10 GMT</pubDate></item></channel></rss>