 |
|
 |
Thanks a lot, I've been searching for this for a very long time.
|
|
|
|
 |
|
 |
Works great for years in my project!
|
|
|
|
 |
|
 |
I believe that Thou Shalt Not DestroyWindow(hwnd) Whilst
Thou Handles the WM_DESTROY message for that very hwnd, or
BSOD.
|
|
|
|
 |
|
 |
This code doesn't look like it will work:
if (!GetClassInfoEx(hInst, "InputBox", &wcex))
{
wcex.cbSize = sizeof(WNDCLASSEX);
...
}
GetClassInfoEx() requires the cbSize field to be set before the call:
wcex.cbSize = sizeof(WNDCLASSEX);
if (!GetClassInfoEx(hInst, "InputBox", &wcex))
{
...
}
-Mike
|
|
|
|
 |
|
 |
Thanks a lot, I really needed a non-MFC InputBox, since I was launching it from a worker thread (don't do that with MFC).
I have some comments however... I can't see how anyone has got it working without modifying the destroying procedure. You send WM_DESTROY to the window, and then the window procedure calls DestroyWindow on itself. But calling DestroyWindow will send a WM_DESTROY to the window, which calls DestroyWindow on itself, etc etc etc -> stack overflow
Also, the WM_DESTROY handler calls PostQuitMessage, which seems a little dangerous...
The proper way (IMHO) is to call DestroyWindow in the DoModal method on VK_RETURN or VK_ESCAPE, and then just return 0 or 1 from in there (without requiring GetMessage to fail).
That would look something like this (DoModal):
while (GetMessage(&msg, NULL, 0, 0))
{
if (msg.message == WM_KEYDOWN)
{
if (msg.wParam == VK_ESCAPE)
{
EnableWindow(m_hWndParent, TRUE);
SetForegroundWindow(m_hWndParent);
DestroyWindow(m_hWndInputBox);
return IDCANCEL;
}
if (msg.wParam == VK_RETURN)
{
int nCount = GetWindowTextLength(m_hWndEdit);
nCount++;
if (Text)
{
delete[] Text;
Text = NULL;
}
Text = new TCHAR[nCount];
GetWindowText(m_hWndEdit, Text, nCount);
EnableWindow(m_hWndParent, TRUE);
SetForegroundWindow(m_hWndParent);
DestroyWindow(m_hWndInputBox);
return IDOK;
}
if (msg.wParam == VK_TAB)
{
hWndFocused = GetFocus();
if (hWndFocused == m_hWndEdit) SetFocus(m_hWndOK);
if (hWndFocused == m_hWndOK) SetFocus(m_hWndCancel);
if (hWndFocused == m_hWndCancel) SetFocus(m_hWndEdit);
}
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
And in the window procedure:
case WM_DESTROY:
DeleteObject(m_hFont);
return DefWindowProc(hWnd, message, wParam, lParam);
case WM_CLOSE:
PostMessage(m_hWndInputBox, WM_KEYDOWN, VK_ESCAPE, 0);
break;
Anyway, thanks again!
/Simon
This is not a signature
|
|
|
|
 |
|
 |
Yes, Simon, you are right. =) I just didn't find my inner strength to post update here (or it was my laziness?).
Anyway thank you, Simon.
|
|
|
|
 |
|
 |
This is just what I've been looking for. I like it! I ported it to WinCE and it works great! Only had to make the box narrower to fit WinCE's small window.
|
|
|
|
 |
|
 |
I wrote the MFC and .NET versions and hey presto, someone comes up with a API only vesion
Talk about InputBox overkill, eh?
Nish
p.s. If someone writes a WTL version a few people are gonna go raving mad
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Buy it, read it and admire me
|
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Thanks for your joke, Nish. I am glad that you are glad =)
mah
|
|
|
|
 |
|
 |
Not overkill at all -- nice work. API-only has obvious advantages over MFC dependence.
|
|
|
|
 |
|
 |
brad W wrote:
Not overkill at all -- nice work. API-only has obvious advantages over MFC dependence.
Yes, I agree. Anyway me and the author were only kidding each other
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Buy it, read it and admire me
|
|
|
|
 |
|
 |
I also wrote an MFC version after you'd written yours, not realising that you'd done an article covering that topic alread.
You can read it here if you're interested .
--
Andrew.
|
|
|
|
 |
|
|
 |
|
 |
Nishant S wrote:
though mine was the first one
I was looking at the last updated date, you'll see mine was posted in June 2001...
.
I haven't done any editing tricks or anything either (I wouldn't do that).
Not that it matters of course, I'm just pulling your leg.
--
Andrew.
|
|
|
|
 |
|
|
 |
|
 |
Should I pull out my old Forth compiler and hack out a version in that?
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
 |
|
|
 |