Click to See Complete Forum and Search --> : [RESOLVED] SetWindowText() with Modal DialogBox
hypheni
October 20th, 2009, 01:12 AM
I need to set title of a modal dialogbox at runtime. so i used SetWindowTitle(). but it requires HWND of the Identifier window(ie: the modal dialogbox), but the modal dialogbox is created with DialogBox which is off INT_PTR type. i hv tried converting INT_PTR to HWND but that didn't set windows title.
note: I can't use dialogbox's window procedure because the string i'm going to set, is resides in the parent windows procedure's. Im using Win32 not MFC. i tried this code...
HWND hWin = (HWND)DialogBox(hIns, MAKEINTRESOURCE(102), hMain, (DLGPROC)ChildProc);
SetWindowText(hWin, L"Testing");
hypheni
October 20th, 2009, 03:26 AM
I have solved the particular isuue, but is there any way by which we can obtain a 'HWND' handle to a DialogBox() ie: A modal dialogbox ..??
olivthill2
October 20th, 2009, 04:26 AM
Sorry, I don't understand very well your question.
You can save the handle when your window is created. Of course, you will have to save it in a safe place, e.g. a static variable rather than an auto variable on the stack where it might be erased. Maybe you can send that handle in a customized message to another window if this is needed.
Or if your program is not responsible for the creation of that window, you can find its handle with FindWindow()
VladimirF
October 20th, 2009, 02:17 PM
...is there any way by which we can obtain a 'HWND' handle to a DialogBox() ie: A modal dialogbox ..??Where and when do you want to obtain it?
You understand that the control will get to the next line after DialogBox() call only after that dialog is closed – right?
ovidiucucu
October 23rd, 2009, 01:06 PM
DialogBox returns an int (the value passed in EndDialog or -1 in case of failure) and not a HWND (window handle);
DialogBox (as VladimirF already told) doesn't return until the dialog is closed;
You can set the window text directly in dialog resource template, or in dialog procedure by handling WM_INITDIALOG.
JohnCz
October 28th, 2009, 01:34 AM
There is a way of getting a handle. Use SetWindowsHookEx (WH_CBT).
But the question remains: why would you do it just to set text?
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.