?
Solved

Windows GUI programming

Posted on 2003-03-14
4
Medium Priority
?
2,112 Views
Last Modified: 2008-01-09
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
Comment
Question by:binkzz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 1

Expert Comment

by:Arrummzen
ID: 8139964
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
 
LVL 1

Accepted Solution

by:
Hermetic earned 2000 total points
ID: 8141686
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
 
LVL 20

Expert Comment

by:jmcg
ID: 10123867
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

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question