Sign in to follow this  
b1gjo3

help catching a window message

Recommended Posts

b1gjo3    213
for some reason i cannot catch the message WM_DESTROY even though it is being sent to the window. even if i put DestroyWindow(myHwnd) inside of the windows message loop, it wont catch the message. i have tried specifying/not specifying the hwnd for PeekMessage, i have also tried the same for GetMessage. My inputbox is a child of my class Window. My window class has a static WndProc which gets a long pointer to a window and calls its member functions WndProc. The member function WndProc is virtual so it can be overwritten in its child classes. can someone please help me? thank you
InputBox::InputBox(HWND parent, LPCSTR title, LPCSTR message, LPCSTR defaultText):Window(title, 350, 120)
{
	myParent = parent;
	myText = NULL;

	EnableWindow(myParent, false);
	SetForegroundWindow(myHwnd);

	SetWindowStyle(WS_CAPTION | WS_SYSMENU | WS_POPUP);
	SetWindowExStyle(WS_EX_TOOLWINDOW);
	InitWindow();

	lblMessage = new Label(myHwnd, this->GetINST(), message, 12, 9, 180, 13, IBOX_LBL_FIELD);
	txtField = new TextBox(myHwnd, this->GetINST(), defaultText, 12, 88, 323, 20, IBOX_TXT_FIELD);
	cmdCancel = new CmdButton(myHwnd, this->GetINST(), "Cancel", 280, 39, 55, 23, IBOX_CMD_CANCEL);
	cmdOk = new CmdButton(myHwnd, this->GetINST(), "OK", 280, 9, 55, 23, IBOX_CMD_OK);

	SetFocus(txtField->GetHWND());
	Edit_SetSel(txtField->GetHWND(), 0, Edit_GetTextLength(txtField->GetHWND()));

	MSG msg = {0};

	while (msg.message != WM_DESTROY)
	{
		while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE)
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	EnableWindow(myParent, true);
	SetForegroundWindow(myParent);
}

LRESULT InputBox::WndProc(UINT message, WPARAM wParam, LPARAM lParam)
{
	//check any available messages from the queue
	switch (message)
	{
		case WM_COMMAND:
			switch(LOWORD(wParam))
			{
				case IBOX_CMD_CANCEL:
					DestroyWindow(myHwnd);
					break;
				case IBOX_CMD_OK:
					int length = Edit_GetTextLength(txtField->GetHWND()) + 1;
					if (myText != NULL)
						delete [] myText;
					myText = new char[length];
					len = Edit_GetText(txtField->GetHWND(), myText, length);
					DestroyWindow(myHwnd);
					break;
			}
			break;
	}

	return DefWindowProc(myHwnd, message, wParam, lParam);
}

Share this post


Link to post
Share on other sites
Evil Steve    2017
Just handle the message in your window procedure and set a global variable (Or a member variable if your window proc is wrapped up in a class). Then check that global every time you pump window messages.

Share this post


Link to post
Share on other sites
b1gjo3    213
if i have a bool variable named "exit" and then if i tell it to loop until exit is reached, i cant interact with the window.

i create an InputBox class on a button click event in another WndProc, and if inputbox doest have a loop until the user is finished, it will run through the rest of the statements in the calling wndproc.

my application is this ->
1)User hits a button and pops up an inputbox
2)The wndproc that created the inputbox will wait until user has finished input in the inputbox
3)then it will go through the rest of execution as normal

heres my inputbox class

class InputBox : public Window
{
public:
InputBox(HWND parent, LPCSTR title, LPCSTR message, LPCSTR defaultText = "(Text)");
~InputBox();
virtual LRESULT WndProc(UINT message, WPARAM wParam, LPARAM lParam);
int Lenght()const {return len;}
char* Text()const {return myText;}
private:
HWND myParent;
CmdButton* cmdOk;
CmdButton* cmdCancel;
TextBox* txtField;
Label* lblMessage;
char* myText;
int len;
bool quit;
};

InputBox::InputBox(HWND parent, LPCSTR title, LPCSTR message, LPCSTR defaultText):Window(title, 350, 120)
{
myParent = parent;
myText = NULL;
quit = false;

EnableWindow(myParent, false);
SetForegroundWindow(myHwnd);

SetWindowStyle(WS_CAPTION | WS_SYSMENU | WS_POPUP);
SetWindowExStyle(WS_EX_TOOLWINDOW);
InitWindow();

lblMessage = new Label(myHwnd, this->GetINST(), message, 12, 9, 180, 13, IBOX_LBL_FIELD);
txtField = new TextBox(myHwnd, this->GetINST(), defaultText, 12, 88, 323, 20, IBOX_TXT_FIELD);
cmdCancel = new CmdButton(myHwnd, this->GetINST(), "Cancel", 280, 39, 55, 23, IBOX_CMD_CANCEL);
cmdOk = new CmdButton(myHwnd, this->GetINST(), "OK", 280, 9, 55, 23, IBOX_CMD_OK);

SetFocus(txtField->GetHWND());
Edit_SetSel(txtField->GetHWND(), 0, Edit_GetTextLength(txtField->GetHWND()));

while (!quit)
{

}

EnableWindow(myParent, true);
SetForegroundWindow(myParent);
}

LRESULT InputBox::WndProc(UINT message, WPARAM wParam, LPARAM lParam)
{
//check any available messages from the queue
switch (message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IBOX_CMD_CANCEL:
DestroyWindow(myHwnd);
quit = true;
break;
case IBOX_CMD_OK:
int length = Edit_GetTextLength(txtField->GetHWND()) + 1;
if (myText != NULL)
delete [] myText;
myText = new char[length];
len = Edit_GetText(txtField->GetHWND(), myText, length);
DestroyWindow(myHwnd);
quit = true;
break;
}
break;
}

return DefWindowProc(myHwnd, message, wParam, lParam);
}




heres the calling wndproc

LRESULT GCIsoGui::WndProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage (0);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case CMD_ADD_FOLDER:
{
InputBox* x = new InputBox(myHwnd, "Add Folder", "Enter Folder Name");
MsgBox(x->Text(), "CAP");

Share this post


Link to post
Share on other sites
b1gjo3    213
i have read through all those pages.

my DLGTEMPLATE never worked with the DialogBoxIndirect

can you give me a small sample of how the DLGTEMPLATE shoud look, and how to use the DialogBoxIndirect to create a simple Dialog.

and could you also show me how to add just a simple command button to it so i know how to add controls for later on

thank you

Share this post


Link to post
Share on other sites
MJP    19786
Raymond Chen's blog had a good entry about creating a dialog template at runtime. To create your controls, you can do it pretty exactly the same way you were doing it except you should make them in response to the WM_INITDIALOG notification. Raymond Chen also had an entry about creating the controls contained in the template if you're interested, which is actually part of a series about dialog boxes in general.

[Edited by - MJP on April 24, 2008 3:29:46 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this