Hi,

I have few problems, so I hope someone will help me :) I started with win32 API yesterday and I really like it, but I need little help :)

#1 edit: I already fixed this :P

#2 I created small "login" application, after user press "login" it should get his username and password and copy it into arrays, and then check if "username" is "lal", if yes, then open message box with "OK" msg, else, open msg box with "error" msg, I'm still getting error msg box, even if I have "lal" in username

code:

case IDC_CONNECT1:
				{
					char Username[256];
					char Password[256];
					SendMessage(hUsername, WM_GETTEXT, sizeof(Username)/sizeof(Username[0]), reinterpret_cast<LPARAM>(Username));
					SendMessage(hPassword, WM_GETTEXT, sizeof(Password)/sizeof(Password[0]), reinterpret_cast<LPARAM>(Password));
					if(Username == "lal")
					{
						MessageBox(hWnd, "OK", NULL, MB_OK);
					}
					else
					{
						MessageBox(hWnd, "Error!", NULL, MB_OK);
					}
					break;
				}

#3 this one is for both, chat and login application, when I type something into edit box (username/password - login, message - chat) and press enter, it will just play that error beep or something, so I need to click on send/login manually, BUT, it works if I click on menu or something (I will type something into edit box, then I press file in menu, close menu, and then when I press enter it will send that message...), so I need to "deactivate" edit box or something

code: (chat client)

case WM_KEYDOWN:
		{
			switch(wParam)
			{
			case VK_RETURN:
				{
					char buffer[256];
					SendMessage(hEdit, WM_GETTEXT, sizeof(buffer)/sizeof(buffer[0]), reinterpret_cast<LPARAM>(buffer));
					MessageBox(hEdit, buffer, "Information", MB_ICONINFORMATION);
				}
				break;
			}
			break;
		}

#4 what can I use like handler for messages?

something like this

-------------------------------
| Text from input field       |
| when the user clicked       |
| 'send'                      |
|                             |
|                             |
-------------------------------
|                             |
|      Enter Text Here        |
|                             |
-------------------------------
                        | SEND|

I need that window at top :P

Edited 5 Years Ago by senergy: n/a

>>#2

You cannot use the == operator for comparing C-strings (arrays of chars), this will only compare the pointer values. To compare the actual C-strings, you need to use the strcmp function.

For the rest, I don't understand the questions or what you want.

>>#2

You cannot use the == operator for comparing C-strings (arrays of chars), this will only compare the pointer values. To compare the actual C-strings, you need to use the strcmp function.

For the rest, I don't understand the questions or what you want.

#4 - http://filebeam.com/4a6496aeec4b2bb30aa8fb11c66e00fc.jpg

#3 - I need function that when I press enter will send message from edit box (that thing where u can write in chat...)

Edited 5 Years Ago by senergy: n/a

You need to send the edit control an WM_GETTEXT message and pass ca C string as the WPARAM argument along with the size of the string in the LPARAM arg.The string pointed to by the WPARAM parameter will receieve the text contained by that edit control.

Edited 5 Years Ago by caut_baia: n/a

You need to send the edit control an WM_GETTEXT message and pass ca C string as the WPARAM argument along with the size of the string in the LPARAM arg.The string pointed to by the WPARAM parameter will receieve the text contained by that edit control.

I started with win32 API yesterday

can u show me code or something ? :)

char buff[128]={0};
std::size_t sizeof_buf=sizeof(buff);
HWND edit_ctrl=CreateWindow ("edit","contained text",1,WM_CHILD,0,0,0,0,NULL,NULL,NULL); //edit control
SendMessage (edit_ctrl,WM_GETTEXT,(WPARAM) buff,(LPARAM) sizeof_buf);
//buff should contain the string "contained text"

I have not compiled that so i don't know if i wrote the function call to CreateWindow correctly but you should get the idea

Edited 5 Years Ago by caut_baia: n/a

char buff[128]={0};
std::size_t sizeof_buf=sizeof(buff);
HWND edit_ctrl=CreateWindow ("edit","contained text",1,WM_CHILD,0,0,0,0,NULL,NULL,NULL); //edit control
SendMessage (edit_ctrl,WM_GETTEXT,(WPARAM) buff,(LPARAM) sizeof_buf);
//buff should contain the string "contained text"

I have not compiled that so i don't know if i wrote the function call to CreateWindow correctly but you should get the idea

I already have done this... look at code, I need a function that will run this when I press VK_RETURN...

I have problems understanding what you're asking for but i think you need accelerators.You should look that up on msdn.

while (GetMessage(&msg,NULL,NULL,NULL))  {
      if (!IsDialogMessage (hwnd,&msg))  {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
        }
      else if (TranslateAccelerator(hwnd,Accltors,&msg))  {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
        }
     }

Try to make your main function contain the above.You should figure out where that needs be placed.You can ommit the TranslateAccelerator part.I just copied this from a program i wrote once but the interesting part should be this

if (!IsDialogMessage (hwnd,&msg))  {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
        }

Edited 5 Years Ago by caut_baia: n/a

while (GetMessage(&msg,NULL,NULL,NULL))  {
      if (!IsDialogMessage (hwnd,&msg))  {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
        }
      else if (TranslateAccelerator(hwnd,Accltors,&msg))  {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
        }
     }

Try to make your main function contain the above.You should figure out where that needs be placed.You can ommit the TranslateAccelerator part.I just copied this from a program i wrote once but the interesting part should be this

if (!IsDialogMessage (hwnd,&msg))  {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
        }

how can I create "accltros" ?

hey, look, I need just an simple "thing" that will do "thing" when I press enter

I have this, but this works only if my edit control IS NOT activated (when I'm not writing to it)

case WM_KEYDOWN:
		{
			switch(wParam)
			{
			case VK_RETURN:
				{
					char buffer[256];
					SendMessage(hEdit, WM_GETTEXT, sizeof(buffer)/sizeof(buffer[0]), reinterpret_cast<LPARAM>(buffer));
					MessageBox(hEdit, buffer, "Information", MB_ICONINFORMATION);
				}
				break;
			}
			break;
		}

when I press enter, this will display the text of edit control in message box, I just need to make this to work while edit control is active (whem I'm writing to it)

Edited 5 Years Ago by senergy: n/a

You must create an accelerator table and then define them in a resource header which must be separately compiled.It's a bit more complicated.Have you tried what i've suggested ?

well, I never worked with accelerators, so I have no idea how to use them, I just tried that "interesting part", but it;'s not working...

Try something like this

case WM_COMMAND:
   switch (LOWORD(wParam))  {
      case EDIT_ID: //the id of the edit control
         if (HIWORD(GetKeyState(VK_RETURN)))  {
            //do whatever needs be done
          }
       break;
     }
break;

I can only point you toward using a dialog box for your main window and a custom dialog procedure for handling messages but that will give you a bit more to work on.Good luck

This article has been dead for over six months. Start a new discussion instead.