message-loop

How can a new Form be run on a different thread in C#?

▼魔方 西西 提交于 2019-12-30 03:32:08
问题 I'm just trying to run a new thread each time a button click even occurs which should create a new form. I tried this in the button click event in the MainForm: private void button1_Click(object sender, EventArgs e) { worker1 = new Thread(new ThreadStart(thread1)); worker2 = new Thread(new ThreadStart(thread2)); worker1.Start(); worker2.Start(); } private void thread1() { SubForm s = new SubForm(); s.Show(); } private void thread2() { SubForm s = new SubForm(); s.Show(); } The code in the

Low Level Keyboard Hook called intermittently, GetMessage never returns

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 02:49:36
问题 I set up a low level keyboard hook in a worker thread that also runs a message loop. About 1/3 of my key strokes trigger the hook function and none release the GetMessage function in my message loop. Because of something related to the latter, messages aren't queued either (I just started working with Windows' message loop). What would cause only some keystroke to trigger a hook? And is there some setting/function call I'm missing to have the GetMessage to work correctly (according to this I

Create child window in WM_CREATE, relevance of same thread?

限于喜欢 提交于 2019-12-25 01:39:44
问题 A typical pattern is to create a child window in the message callback ( WndProc ) at message WM_CREATE : LRESULT APIENTRY WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { ... switch (message) { case WM_CREATE: .... hwndChild[i] = CreateWindow (szChildClass[i], NULL, WS_CHILDWINDOW | WS_BORDER ... I perfectly understand this is a good opportunity, but is it a problem to do it any time later? One reason for doing so is that the child window is created within the same thread.

C# - Waiting for WinForms Message Loop

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 10:11:46
问题 I have to write an C# API for registering global hotkeys. To receive the WM_HOTKEY message, I use a System.Windows.Forms.NativeWindow and run an own message loop with System.Windows.Forms.Application.Run(ApplicationContext) . When the user wants to register a hotkey, he has to run a method called RegisterHotkey() which stops the message loop with System.Windows.Forms.ApplicationContext.ExitThread() , registers the hotkey with the RegisterHotKey() (P/Invoke) function and starts the message

Win32 Message Loops: Quitting after window closes with GetMessage(&msg, NULL, 0, 0)?

淺唱寂寞╮ 提交于 2019-12-08 07:16:42
问题 If I have the following code below, how do I detect when the window has been closed, so I can quit? r never seems to get the value -1 0 , and I need to process messages for the entire thread, not just the current window. HWND hWnd = CreateWindowExW(0, L"Edit", L"My Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 300, 200, NULL, NULL, NULL, NULL); ShowWindow(hWnd, SW_SHOWDEFAULT); MSG msg; BOOL r; while ((r = GetMessageW(&msg, NULL, 0, 0)) != 0) { if (r == -1) { break; }

Implementing a Win32 message loop and creating a Window object with P/Invoke

为君一笑 提交于 2019-12-07 10:47:12
问题 My main goal is to implement a proper message loop purely with P/Invoke calls that is able to handle USB HID events. Definitely its functionality should be identical with the following code that works well in Windows Forms. This NativeWindow descendant receives the events: public class Win32EventHandler : NativeWindow { public const int WM_DEVICECHANGE = 0x0219; public Win32EventHandler() { this.CreateHandle(new CreateParams()); } protected override void OnHandleChange() { base.OnHandleChange

Implementing a Win32 message loop and creating a Window object with P/Invoke

孤者浪人 提交于 2019-12-05 14:27:12
My main goal is to implement a proper message loop purely with P/Invoke calls that is able to handle USB HID events. Definitely its functionality should be identical with the following code that works well in Windows Forms . This NativeWindow descendant receives the events: public class Win32EventHandler : NativeWindow { public const int WM_DEVICECHANGE = 0x0219; public Win32EventHandler() { this.CreateHandle(new CreateParams()); } protected override void OnHandleChange() { base.OnHandleChange(); IntPtr handle = UsbHelper.RegisterForUsbEvents(this.Handle); } protected override void WndProc(ref

Cocoa message loop? (vs. windows message loop)

≡放荡痞女 提交于 2019-12-04 10:21:01
问题 While trying to port my game engine to mac, I stumble upon one basic (but big) problem. On windows, my main code looks like this (very simplified): PeekMessage(...) // check for windows messages switch (msg.message) { case WM_QUIT: ...; case WM_LBUTTONDOWN: ...; ... } TranslateMessage(&msg); DispatchMessage (&msg); for (std::vector<CMyBackgroundThread*>::iterator it = mythreads.begin(); it != mythreads.end(); ++it) { (*it)->processEvents(); } ... do other useful stuff like look if the window

Changing a Window's message loop thread

最后都变了- 提交于 2019-12-03 12:34:43
问题 Recently I tried putting a window's message loop in its own thread, and I wondered why it never received any messages, but I have learned that Windows posts messages to the thread that created the window. How do you create a window in one thread and cause another thread to receive that window's messages? I have seen the PostThreadMessage function but I believe that it also requires for the thread that created the window to listen for messages, which is exactly the thing I'm trying to avoid,

How to exit a thread's message loop?

和自甴很熟 提交于 2019-12-03 07:24:40
问题 A background-thread can be configured to receive window messages. You would post messages to the thread using PostThreadMessage. What's the correct way to exit that message loop? Background Before you can post messages to a background thread, the thread needs to ensure that a message queue is created by calling PeekMessage : procedure ThreadProcedure; var msg: TMsg; begin //Call PeekMessage to force the system to create the message queue. PeekMessage(msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);