Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2115
  • Last Modified:

Windows GUI programming

hia..

I'm a delphi man and very much new to C. I'm trying to write a small GUI program in LCC with a few text controls and some basic interaction. I have the .rc set up with a dialog including two edit boxes and two labels.

If I were to change something in edit box 1, I want edit box 2 to be updated according to the info of edit box 1.

For that I'll need to be able to capture the onkey and change the edit box, but how?

Also, if I press enter, the dialog (and program) closes, I don't want this to happen.

It's essential this is done in C, not C++.

-- Program code --
/*@@ Wedit generated application. Written Fri Mar 14 16:13:59 2003
 @@header: c:\lcc\projects\nitrous2\nitrous2res.h
 @@resources: c:\lcc\projects\nitrous2\nitrous2.rc
 Do not edit outside the indicated areas */
/*<---------------------------------------------------------------------->*/
/*<---------------------------------------------------------------------->*/
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <string.h>
#include "nitrous2res.h"
/* --- The following code comes from c:\lcc\lib\wizard\dlgbased.tpl. */
/*<---------------------------------------------------------------------->*/

/*
Template for a dialog based application. The main procedure for this
template is the DialogFunc below. Modify it to suit your needs.
*/
/* prototype for the dialog box function. */
static BOOL CALLBACK DialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
/*
Win main just registers a class of the same type that the dialog class, and
then calls DialogBox. Then it exits. The return value is the return value of
the dialog procedure.
*/

int APIENTRY WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR lpCmdLine, int nCmdShow)
{
     WNDCLASS wc;

     memset(&wc,0,sizeof(wc));
     wc.lpfnWndProc = DefDlgProc;
     wc.cbWndExtra = DLGWINDOWEXTRA;
     wc.hInstance = hinst;
     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
     wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
     wc.lpszClassName = "nitrous2";
     RegisterClass(&wc);

     return DialogBox(hinst, MAKEINTRESOURCE(IDD_MAINDIALOG), NULL, (DLGPROC) DialogFunc);

}

/*
You should add your initialization code here. This function will be called
when the dialog box receives the WM_INITDIALOG message.
*/
static int InitializeApp(HWND hDlg,WPARAM wParam, LPARAM lParam)
{
     return 1;
}

/*
This is the main function for the dialog. It handles all messages. Do what your
application needs to do here.
*/
static BOOL CALLBACK DialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
     switch (msg) {
     /* This message means the dialog is started but not yet visible.
        Do All initializations here
        */
     case WM_INITDIALOG:
          InitializeApp(hwndDlg,wParam,lParam);
          return TRUE;
     /* By default, IDOK means close this dialog returning 1, IDCANCEL means
           close this dialog returning zero
        */
     case WM_COMMAND:
          switch (LOWORD(wParam)) {
               case IDOK:
                    EndDialog(hwndDlg,1);
                    return 1;
               case IDCANCEL:
                    EndDialog(hwndDlg,0);
                    return 1;
          }
          break;
        /* By default, WM_CLOSE is equivalent to CANCEL */
     case WM_CLOSE:
          EndDialog(hwndDlg,0);
          return TRUE;
     
     }
     return FALSE;
}
-------------------------

TIA,


-B
0
binkzz
Asked:
binkzz
1 Solution
 
ArrummzenCommented:
To fix this problem -
1: add another button to the form.
2: set that buttons visible property to false
3: set that buttons disabled property to true
4: set that buttons deffault button property to true
5: make sure that the OK and Cancel buttons have there deffault button propert set to false.
6: recompile

why it works -
The reason the program is closing is most likely because the button called IDOK or IDCANCEL has focus. When you push enter Windows sends a WM_COMMAND message saying that the button that has the focus was clicked.
So basicly by pushing enter while the ok or cancel button has focus you are clicking on them.
To fix this problem you can eather remove the ok or cancel button and just leve the program via the little "X" in the uper rite hand coner or you can add another button and use tab to give the other button focus that way when you push enter the ok or cancel buttons wont get the been clicked message.
Thank you for your time,
Arrummzen
0
 
HermeticCommented:
To fix the "enter key closes dialog", all you have to
do is add the ES_WANTRETURN style to your editbox in
the dialog resource.

to capture the EN_CHANGE notification, alter your
message proc as follows:


    case WM_COMMAND:
         switch (LOWORD(wParam)) {
              case IDOK:
                   EndDialog(hwndDlg,1);
                   return 1;
              case IDCANCEL:
                   EndDialog(hwndDlg,0);
                   return 1;
              case IDC_EDITBOX: //Whatever ID you used for it
                   if (HIWORD(wParam) == EN_CHANGE)
                   { //do something
                     //HWnd of editbox in lParam
                        return 1;
                   }
         }
0
 
jmcgOwnerCommented:
Nothing has happened on this question in more than 10 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by Hermetic.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now