C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28695
Number of posts: 94715

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Creating Controls (buttons, listboxes, etc.) in Main Window (Win32)? Posted by Ed Hall on 10 Apr 2006 at 6:31 PM
I must be missing something. I've been through Forger's Tutorial several times and looked at MSDN and other sources, but I just don't get how to place controls on the primary window. What am I missing? I can create popup windows of all sorts with buttons, etc. But, I want to place a listbox, some editboxes and several buttons on the Main window. Can someone point me to the (probably simple) piece of info I need to make this work? Thanks!

Take Care,
Ed

Report
Re: Creating Controls (buttons, listboxes, etc.) in Main Window (Win32 Posted by stober on 10 Apr 2006 at 7:10 PM
: I must be missing something. I've been through Forger's Tutorial several times and looked at MSDN and other sources, but I just don't get how to place controls on the primary window. What am I missing? I can create popup windows of all sorts with buttons, etc. But, I want to place a listbox, some editboxes and several buttons on the Main window. Can someone point me to the (probably simple) piece of info I need to make this work? Thanks!
:
: Take Care,
: Ed
:
:


That's one why I'm an MFC fan -- it makes that sort of stuff pretty simple. And I don't know how to do it either. Myself, I wouldn't even think of writing a program of any significant size using pure win32 api functions -- makes my head hurt too much.
Report
Re: Creating Controls (buttons, listboxes, etc.) in Main Window (Win32 Posted by Ed Hall on 10 Apr 2006 at 8:07 PM
: That's one why I'm an MFC fan -- it makes that sort of stuff pretty simple. And I don't know how to do it either. Myself, I wouldn't even think of writing a program of any significant size using pure win32 api functions -- makes my head hurt too much.
:
Thanks Stober,

I've no familiarity with MFC at all yet. I do have a hole card to play still - my Borland package includes something called Object Windows Library (OWL) that I can use to do lots of stuff including the current things I'm trying to accomplish. Unfortunately, it comes with a price - OWL remaps a lot of APIs and ties up things that I haven't been able to untie. For example, I haven't been able to size the window to what I want - it's determined by something within the OWL libraries and attrib.x and attrib.y have no effect. For that reason I've been trying to get back to a more pure win32, if there is such an animal...

Take Care,
Ed


Report
Re: Creating Controls (buttons, listboxes, etc.) in Main Window (Win32 Posted by tsagld on 11 Apr 2006 at 3:15 AM
: : That's one why I'm an MFC fan -- it makes that sort of stuff pretty simple. And I don't know how to do it either. Myself, I wouldn't even think of writing a program of any significant size using pure win32 api functions -- makes my head hurt too much.
: :
: Thanks Stober,
:
: I've no familiarity with MFC at all yet. I do have a hole card to play still - my Borland package includes something called Object Windows Library (OWL) that I can use to do lots of stuff including the current things I'm trying to accomplish. Unfortunately, it comes with a price - OWL remaps a lot of APIs and ties up things that I haven't been able to untie. For example, I haven't been able to size the window to what I want - it's determined by something within the OWL libraries and attrib.x and attrib.y have no effect. For that reason I've been trying to get back to a more pure win32, if there is such an animal...
:
: Take Care,
: Ed

:
:

Placing controls on a window requires the CreateWindow or CreateWindowEx api.
MSDN explaines it well, imo. Shouldn't be any problem.


Greets,
Eric Goldstein
www.gvh-maatwerk.nl


Report
Re: Creating Controls (buttons, listboxes, etc.) in Main Window (Win32 Posted by AsmGuru62 on 11 Apr 2006 at 4:19 AM
This message was edited by AsmGuru62 at 2006-4-11 4:20:55

: Placing controls on a window requires the CreateWindow or CreateWindowEx api.
: MSDN explaines it well, imo. Shouldn't be any problem.
:
:
: Greets,
: Eric Goldstein
: www.gvh-maatwerk.nl
:
:
:
That is correct.

Just want to add where it should be done. Your main window procedure should have WM_CREATE case. In there you need to add a call to CreateWindow() passing HWND from main procedure as parent window for your child window. Use the correct class names for your controls: "edit" for simple edit box, "listbox", "combobox", etc. Also, styles must include WS_CHILD + WS_VISIBLE. The rest of styles should be according to control - MSDN specifies all styles for all controls:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/wincontrols.asp

In case, you make your main window resizeable - respond to WM_SIZE by resizing (call MoveWindow() on each control) controls according to your design.



Report
Re: Creating Controls (buttons, listboxes, etc.) in Main Window (Win32 Posted by Ed Hall on 11 Apr 2006 at 6:47 AM
: This message was edited by AsmGuru62 at 2006-4-11 4:20:55

: : Placing controls on a window requires the CreateWindow or CreateWindowEx api.
: : MSDN explaines it well, imo. Shouldn't be any problem.
: :
: :
: : Greets,
: : Eric Goldstein
: : www.gvh-maatwerk.nl
: :
: :
: :
: That is correct.
:
: Just want to add where it should be done. Your main window procedure should have WM_CREATE case. In there you need to add a call to CreateWindow() passing HWND from main procedure as parent window for your child window. Use the correct class names for your controls: "edit" for simple edit box, "listbox", "combobox", etc. Also, styles must include WS_CHILD + WS_VISIBLE. The rest of styles should be according to control - MSDN specifies all styles for all controls:
:
: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/wincontrols.asp
:
: In case, you make your main window resizeable - respond to WM_SIZE by resizing (call MoveWindow() on each control) controls according to your design.

:
Thanks guys,

I think the "where it should be done" part was what was missing. I can't work on it right now, but I hope I can do some more with it a little later today (might not be until tomorrow). I'll let you know if I get ahold of the concept. My Borland help files (and MSDN) do explain a lot, but the one thing that's missing is a good set of examples. With your help, I think there is a light trying to shine through. Thanks again.

Take Care,
Ed

Report
Re: Creating Controls in Main Window (Win32) - Update Posted by Ed Hall on 12 Apr 2006 at 6:52 AM
I'm closer, but not quite there yet. Thanks for the push in the right direction. I do now have four buttons on my main window and can read BN_CLICKED, but I haven't been able to differentiate yet. I've tried adding ID_... for the HMENU hMenu element (with ID_... added to my .h file equal to 9004), but it won't compile. I've also tried simply coding it with an integer (9004). I tried this approach because the hMenu documentation says:

"For a child window, hMenu specifies the child-window identifier, an integer value used by a dialog box control to notify its parent about events."

But it won't let me use anything other than NULL.

From the button description for returned values I read:

"...the low-order word of the wParam parameter contains the control identifier, the high-order word of wParam contains the notification code, and the lParam parameter contains the control window handle."

If I try comparing the lParam to my button handle

if (lParam == hwndButton)


I receive a type mismatch error.

Anyway I definitely appreciate the help. I won't have any time today to study this further, but maybe tomorrow. Thanks again.

Take Care,
Ed




Report
Re: Creating Controls in Main Window (Win32) - Update Posted by AsmGuru62 on 13 Apr 2006 at 12:16 AM
If you post the code inside your WM_CREATE case - we may be able to help you better. Something is missing there...
Report
Re: Creating Controls in Main Window (Win32) - Update Posted by Ed Hall on 13 Apr 2006 at 9:12 AM
: If you post the code inside your WM_CREATE case - we may be able to help you better. Something is missing there...
:
Thanks,

I've trimmed the code down quite a bit, but here's (I hope) enough to get a good look at this portion. Currently, I can pick up the fact that a button was clicked, but as it now stands any button gives a response. My BECommnd.h file includes a listing for ID_EXIT and ID_CANCEL with 9004 and 9005, but I haven't found a way to get them linked with the buttons.

As you can see I have remarked out a couple tests.

#include <windows.h>
#include "BECommnd.h"

const char g_szClassName[] = "myWindowClass";
HWND		hwndCancel, hwndExit;

...

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	 switch(msg)
	 {
		case WM_CREATE:
			hwndCancel = CreateWindow(
				"BUTTON",   // predefined class
				"Cancel",       // button text
				WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,  // styles
	
				// Size and position values are given explicitly, because
				// the CW_USEDEFAULT constant gives zero values for buttons.
				220,         // starting x position
				20,         // starting y position
				60,        // button width
				30,        // button height
				hwnd,       // parent window
				NULL,       // No menu
				(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE),
				NULL);      // pointer not needed

			hwndExit = CreateWindow(
				"BUTTON",   // predefined class
				"Exit",       // button text
				WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,  // styles
	
				// Size and position values are given explicitly, because
				// the CW_USEDEFAULT constant gives zero values for buttons.
				320,         // starting x position
				20,         // starting y position
				60,        // button width
				30,        // button height
				hwnd,       // parent window
				NULL,       // No menu I tried ID_EXIT here
				(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE),
				NULL);      // pointer not needed

		break;

		case WM_COMMAND:
			switch(LOWORD(wParam))
			{
				case BN_CLICKED:
//					switch(lParam)
//						case ID_EXIT:
//                                              case hwndExit:
//						if (lParam == hwndExit)
							PostMessage(hwnd, WM_CLOSE, 0, 0);
//						break;
				break;

				case ID_FILE_EXIT:
					 PostMessage(hwnd, WM_CLOSE, 0, 0);
				break;

		  case WM_CLOSE:
				DestroyWindow(hwnd);
		  break;
		  case WM_DESTROY:
				PostQuitMessage(0);
		  break;
		  default:
				return DefWindowProc(hwnd, msg, wParam, lParam);
	 }
	 return 0;
}



Thanks for any thougts that can get me pointed in the right direction. This project is a rework of a huge program from a couple years ago that used the Borland OWL format. I'm trying to use it to learn how to work more directly with the win32 APIs which should free me from some of the OWL constraints. I'm hoping that figuring out the buttons will help me when I move to the listbox and editboxes I'm also going to need. Fortunately, I'm not in any real hurry to get through this, but I sometimes get rather frustrated.

Thanks again,
Ed

Report
Re: Creating Controls in Main Window (Win32) - Update Posted by AsmGuru62 on 14 Apr 2006 at 4:21 AM
:
: #include <windows.h>
: #include "BECommnd.h"
: 
: const char g_szClassName[] = "myWindowClass";
: HWND		hwndCancel, hwndExit;
: 
: ...
: 
: LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
: {
: 	 switch(msg)
: 	 {
: 		case WM_CREATE:
: 			hwndCancel = CreateWindow(
: 				"BUTTON",   // predefined class
: 				"Cancel",       // button text
: 				WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,  // styles
: 	
: 				// Size and position values are given explicitly, because
: 				// the CW_USEDEFAULT constant gives zero values for buttons.
: 				220,         // starting x position
: 				20,         // starting y position
: 				60,        // button width
: 				30,        // button height
: 				hwnd,       // parent window
: 				NULL,       // No menu

The child window cannot have a zero ID - that is a problem.
Instead of a menu handle here you need to use an ID for that button -
the one you will be reacting on in WM_COMMAND case. Cast it to
HMENU, like this: (HMENU) ID_FILE_EXIT

: 				(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE),
: 				NULL);      // pointer not needed
: 
: 			hwndExit = CreateWindow(
: 				"BUTTON",   // predefined class
: 				"Exit",       // button text
: 				WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,  // styles
: 	
: 				// Size and position values are given explicitly, because
: 				// the CW_USEDEFAULT constant gives zero values for buttons.
: 				320,         // starting x position
: 				20,         // starting y position
: 				60,        // button width
: 				30,        // button height
: 				hwnd,       // parent window
: 				NULL,       // No menu I tried ID_EXIT here
: 				(HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE),
: 				NULL);      // pointer not needed
: 
: 		break;
: 
: 		case WM_COMMAND:

The case below needs some adjusting. Control notifications (from
buttons, list boxes, combo boxes) are coming here in HIWORD (wParam).
The ID of the control comes in LOWORD (wParam), watch out for that
(I see you comparing LOWORD to BN_CLICKED, and it is not there).
Since BN_CLICKED is zero, you can use a simple switch on button ID:

switch (wParam) {
  case ID_FILE_EXIT:
    // your action here...
    break;
}

: 			switch(LOWORD(wParam))
: 			{
: 				case BN_CLICKED:
: //					switch(lParam)
: //						case ID_EXIT:
: //                                              case hwndExit:
: //						if (lParam == hwndExit)
: 							PostMessage(hwnd, WM_CLOSE, 0, 0);
: //						break;
: 				break;
: 
: 				case ID_FILE_EXIT:
: 					 PostMessage(hwnd, WM_CLOSE, 0, 0);
: 				break;
: 
: 		  case WM_CLOSE:
: 				DestroyWindow(hwnd);
: 		  break;
: 		  case WM_DESTROY:
: 				PostQuitMessage(0);
: 		  break;
: 		  default:
: 				return DefWindowProc(hwnd, msg, wParam, lParam);
: 	 }
: 	 return 0;
: }
: 
: 


Report
Re: Creating Controls in Main Window (Win32) - Update Posted by Ed Hall on 14 Apr 2006 at 6:13 AM
:
: The child window cannot have a zero ID - that is a problem.
: Instead of a menu handle here you need to use an ID for that button -
: the one you will be reacting on in WM_COMMAND case. Cast it to
: HMENU, like this: (HMENU) ID_FILE_EXIT
:

:
: The case below needs some adjusting. Control notifications (from
: buttons, list boxes, combo boxes) are coming here in HIWORD (wParam).
: The ID of the control comes in LOWORD (wParam), watch out for that
: (I see you comparing LOWORD to BN_CLICKED, and it is not there).
: Since BN_CLICKED is zero, you can use a simple switch on button ID:
:
: switch (wParam) {
: case ID_FILE_EXIT:
: // your action here...
: break;
: }
:


Thanks much. I found the above yesterday and got all the buttons working just as you described above. The casting to HMENU was the real elusive point. I definitely appreciate your help (and verification). Sorry I couldn't get on the board yesterday to let you know I'd found it. I was able to also build in keystroke recognition for the buttons.

As a point of learning, why was I not able to compare the button handle (hwndExit) to lParam when I received a BN_CLICKED message? My docs say, "...and the lParam parameter contains the control window handle."

Do they need to be comaped using some other method than == as with strings where you must use strcmp or such?

Thanks again for helping me get this right.

Take Care,
Ed

Report
Re: Creating Controls in Main Window (Win32) - Update Posted by AsmGuru62 on 15 Apr 2006 at 5:21 AM
This message was edited by AsmGuru62 at 2006-4-15 5:23:39

This message was edited by AsmGuru62 at 2006-4-15 5:23:11

I am thinking that is it because that code section in which you were doing that is never called, because LOWORD is never BN_CLICKED. The notification code is inside HIWORD, not LOWORD. Try to put the verification on handle in that other case (see RED):
: 			switch(LOWORD(wParam))
: 			{
: 				case BN_CLICKED:
: //					switch(lParam)
: //						case ID_EXIT:
: //                                              case hwndExit:
: //						if (lParam == hwndExit)
: 							PostMessage(hwnd, WM_CLOSE, 0, 0);
: //						break;
: 				break;
: 
: 				case ID_FILE_EXIT:
: 					 PostMessage(hwnd, WM_CLOSE, 0, 0);
: 					 _ASSERT (lParam == hwndCancel);
: 				break;



Report
Re: Creating Controls in Main Window (Win32) - Update Posted by Ed Hall on 15 Apr 2006 at 9:29 AM
How odd...

The code below, from my earlier post, worked fine. If you take away the commented out lines you're left only with the BN_CLICKED and PostMessage lines after the switch. That worked fine before, except that it wouldn't differenciate between buttons - all of the buttons initated the PostMessage. But, now that you've said it shouldn't, I can't make it work that way anymore.

As to my hwndButton compare error, whenever I try to use (lParam == hwndButton) as a comparison, I get the following error:

"Nonportable pointer conversion in function WndProc"

Since I have the buttons working as needed, I think I'll let the rest of this sit while I build the other portions of the program, including several of the other types of controls. I may need to revisit it during those learning curves, but it may also make more sense then.

Thanks again for all your help.

Take Care,
Ed



: I am thinking that is it because that code section in which you were doing that is never called, because LOWORD is never BN_CLICKED. The notification code is inside HIWORD, not LOWORD. Try to put the verification on handle in that other case (see RED):
:
: : 			switch(LOWORD(wParam))
: : 			{
: : 				case BN_CLICKED:
: : //					switch(lParam)
: : //						case ID_EXIT:
: : //                                              case hwndExit:
: : //						if (lParam == hwndExit)
: : 							PostMessage(hwnd, WM_CLOSE, 0, 0);
: : //						break;
: : 				break;
: : 
: : 				case ID_FILE_EXIT:
: : 					 PostMessage(hwnd, WM_CLOSE, 0, 0);
: : 					 _ASSERT (lParam == hwndCancel);
: : 				break;
: 

:
:
:


Report
Re: Creating Controls in Main Window (Win32) - Update Posted by AsmGuru62 on 15 Apr 2006 at 4:59 PM
:
: "Nonportable pointer conversion in function WndProc"
:
Every time you see some conversion problem - look at the types of operands and cast one of the two. In that case we have LPARAM and HWND, so these two codes will work the same way:
// #1:
if ((HWND) lParam == hwndCancel)
{
  // ...
}

// #2:
if (lParam == (LPARAM) hwndCancel)
{
  // ...
}


Report
Yet Another (Button) Control Question Posted by Ed Hall on 15 Apr 2006 at 11:42 AM
I have ID_EXIT defined in #####.h and its case works fine from the exit button via a mouse click. I also check for the "x" being pressed and this is working properly. Here's the catch...

case ID_EXIT: is properly called via mouse click on the exit button.
I have the "x" properly registering if the keyboard is used.
ID_EXIT properly calls WM_CLOSE:

     case ID_EXIT:
          PostMessage(hwnd, WM_CLOSE, 0, 0);
          break;


the following code only works from within WndProc:

     if (FaceKey == 'X')
          PostMessage(hwnd, WM_CLOSE, 0, 0);


the following code won't work from anywhere:

     if (FaceKey == 'X')
          PostMessage(hwnd, ID_EXIT, 0, 0);


Apparently, user defined ID_EXIT is not being treated the same as predefined WM_CLOSE. Is there a way to invoke ID_EXIT other than via the control itself, by mouse click?

Thanks for all help...

Take Care,
Ed

Report
Re: Yet Another (Button) Control Question Posted by AsmGuru62 on 15 Apr 2006 at 5:04 PM
: I have ID_EXIT defined in #####.h and its case works fine from the exit button via a mouse click. I also check for the "x" being pressed and this is working properly. Here's the catch...
:
: case ID_EXIT: is properly called via mouse click on the exit button.
: I have the "x" properly registering if the keyboard is used.
: ID_EXIT properly calls WM_CLOSE:
:
:
:      case ID_EXIT:
:           PostMessage(hwnd, WM_CLOSE, 0, 0);
:           break;
: 

:
: the following code only works from within WndProc:
:
:
:      if (FaceKey == 'X')
:           PostMessage(hwnd, WM_CLOSE, 0, 0);
: 

:
: the following code won't work from anywhere:
:
:
:      if (FaceKey == 'X')
:           PostMessage(hwnd, ID_EXIT, 0, 0);
: 

:
: Apparently, user defined ID_EXIT is not being treated the same as predefined WM_CLOSE. Is there a way to invoke ID_EXIT other than via the control itself, by mouse click?
:
: Thanks for all help...
:
: Take Care,
: Ed
:
:
I am lost here... you want to be able to exit the application by pressing 'X' anywhere in the program? What if you typing some text in the edit box?

Can you clarify what exactly you need to do?
Also, please, post the code how did you get that FaceKey variable?

Report
Re: Yet Another (Button) Control Question Posted by Ed Hall on 15 Apr 2006 at 6:50 PM
: I am lost here... you want to be able to exit the application by pressing 'X' anywhere in the program? What if you typing some text in the edit box?
:
: Can you clarify what exactly you need to do?
: Also, please, post the code how did you get that FaceKey variable?
:

:
Sorry,

I'm expecting to have key recognition for the buttons when focused on the main window/buttons. Edit controls will handle their text when focused (I hope).

FaceKey is actually arbitrary and a holdover from two previous iterations where I was working with sending keystrokes to an alternate window. At this point it should probably be PressedKey.

  case WM_KEYDOWN:
	FaceKey = wParam;
	ExtKey = lParam;
	if (FaceKey == 'X')
	    PostMessage(hwnd, WM_CLOSE, 0, 0);
	checkButtons();


This currently gives me recognition of the EXIT button. checkButtons gives me recognition of the other buttons in the same manner. This code is inside WndProc. checkButtons is outside WndProc. The PostMessage with WM_CLOSE only works here, not in checkButtons. A PostMessage to ID_EXIT doesn't work anywhere.

This is really only a curiosity right now since I have working code for what I need presently. (Although, I will admit I may have many convention errors.)

I really appreciate all your help and hope I'm not tying you up too much with my queries. And thanks for the casting note. I should have realized that after having to cast the HMENU for the ID_####. Thanks for all.

Take Care,
Ed


Report
Larger section of code - trimmed Posted by Ed Hall on 15 Apr 2006 at 7:31 PM
Here's a bigger picture of some of the code so you can see what I'm doing. If you notice I end up having to handle the keystroke recognition separately from the button click recognition. This won't be an issue when I provide the routines for each button, but I had expected to be able to use PostMessage to the ID_#### in WndProc from within checkButtons. Thanks again for all.

void checkButtons()
{
	if (FaceKey == 'N')
		NextCommand();
	if (FaceKey == 'C')
		MessageBox(hwnd, "Cancel button pressed.", "It worked!", MB_OK);
}


LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
		case WM_CREATE:
			hwndNext = CreateWindow("BUTTON", "&Next", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 200, 350, 60, 30, hwnd,(HMENU) ID_NEXT, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
			hwndCancel = CreateWindow("BUTTON", "&Cancel", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 360, 350, 60, 30, hwnd,(HMENU) ID_CANCEL, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
			hwndExit = CreateWindow("BUTTON", "E&xit", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 560, 350, 60, 30, hwnd,(HMENU) ID_EXIT, (HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE), NULL);

			if (MessageBox(hwnd, "Acceptance statement", "Agreement", MB_YESNO) != IDYES)
				PostMessage(hwnd, WM_DESTROY, 0, 0);
			break;

		case WM_KEYDOWN:
			FaceKey = wParam;
			ExtKey = lParam;
			if (FaceKey == 'X')
				PostMessage(hwnd, WM_CLOSE, 0, 0);
			checkButtons();
			break;

		case WM_COMMAND:
			switch(LOWORD(wParam))
			{
				case ID_EXIT:
					PostMessage(hwnd, WM_CLOSE, 0, 0);
					break;
				case ID_NEXT:
					MessageBox(hwnd, "Next button pressed.", "It worked!", MB_OK);
					break;
				case ID_CANCEL:
					MessageBox(hwnd, "Cancel button pressed.", "It worked!", MB_OK);
					break;
				case ID_FILE_EXIT:
					 PostMessage(hwnd, WM_CLOSE, 0, 0);
					 break;
			}
			break;

		case WM_CLOSE:
			if (MessageBox(hwnd, "Close program?","Exit Application?", MB_YESNO) == IDYES)
				DestroyWindow(hwnd);
			break;
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		default:
			return DefWindowProc(hwnd, msg, wParam, lParam);
	}
	return 0;
}


Take Care,
Ed

Report
Re: Larger section of code - trimmed Posted by AsmGuru62 on 16 Apr 2006 at 5:11 AM
I see...

Keyboard input will be received by a window which currently has focus. That means if any of buttons has focus - this code will not work, because that WM_KEYDOWN will be intercepted by a button.

Try to click outside of a button and then press 'X' - see if it works.

There is also a way to do it with accelerator, but you need to use the key combination, because 'X' may be needed to edit things. Accelerator intercepts keys BEFORE they go into window procedure, so edit boxes on your window will lose 'X' character.

You can use ALT+X for exiting, so lovable by Borland.

Report
Re: Larger section of code - trimmed Posted by Ed Hall on 16 Apr 2006 at 10:25 AM
: I see...
:
: Keyboard input will be received by a window which currently has focus. That means if any of buttons has focus - this code will not work, because that WM_KEYDOWN will be intercepted by a button.
:
: Try to click outside of a button and then press 'X' - see if it works.
:
: There is also a way to do it with accelerator, but you need to use the key combination, because 'X' may be needed to edit things. Accelerator intercepts keys BEFORE they go into window procedure, so edit boxes on your window will lose 'X' character.
:
: You can use ALT+X for exiting, so lovable by Borland.

:
Actually, it's almost totally working as wanted. While the main window has focus, all keystrokes and buttons work. When in an edit or combo box, it has the keyboard and mouse. This way I can type away in the Notes editbox and all keys type. I've chosen to include CR in the edit so that doesn't leave the box either. Unfortunately, a mouse click in the unused main window doesn't remove focus from the edit (yet). Choosing a button via the mouse does remove focus from the edit. More studies to pursue... Thanks again.

Take Care,
Ed

Report
Re: Larger section of code - trimmed Posted by AsmGuru62 on 16 Apr 2006 at 1:35 PM
: : I see...
: :
: : Keyboard input will be received by a window which currently has focus. That means if any of buttons has focus - this code will not work, because that WM_KEYDOWN will be intercepted by a button.
: :
: : Try to click outside of a button and then press 'X' - see if it works.
: :
: : There is also a way to do it with accelerator, but you need to use the key combination, because 'X' may be needed to edit things. Accelerator intercepts keys BEFORE they go into window procedure, so edit boxes on your window will lose 'X' character.
: :
: : You can use ALT+X for exiting, so lovable by Borland.

: :
: Actually, it's almost totally working as wanted. While the main window has focus, all keystrokes and buttons work. When in an edit or combo box, it has the keyboard and mouse. This way I can type away in the Notes editbox and all keys type. I've chosen to include CR in the edit so that doesn't leave the box either. Unfortunately, a mouse click in the unused main window doesn't remove focus from the edit (yet). Choosing a button via the mouse does remove focus from the edit. More studies to pursue... Thanks again.
:
: Take Care,
: Ed
:
:
It is easy to remove focus from edit: in your main window procedure include case WM_LBUTTONDOWN and respond to it with SetFocus (your main HWND); Return 0 in that case. This way mouse click will send the focus back to main and since Windows cannot have focus in two places - it will effectively remove it from edit box.
Report
Re: Larger section of code - trimmed Posted by Ed Hall on 16 Apr 2006 at 2:03 PM
: It is easy to remove focus from edit: in your main window procedure include case WM_LBUTTONDOWN and respond to it with SetFocus (your main HWND); Return 0 in that case. This way mouse click will send the focus back to main and since Windows cannot have focus in two places - it will effectively remove it from edit box.
:
Works great! Thanks. I had tried SetForegroundWindow without success. I don't know why I didn't think to try SetFocus. I guess I was just too busy with my comboboxlist. I think that's all set now, but I have a huge list to put in it. I think I'll have to make it an include file.

Take Care,
Ed

1 2  Next



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.