home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / os / os2 / programm / 3882 < prev    next >
Encoding:
Text File  |  1992-07-29  |  2.4 KB  |  60 lines

  1. Newsgroups: comp.os.os2.programmer
  2. Path: sparky!uunet!darwin.sura.net!gatech!taco!garfield.catt.ncsu.edu!harris
  3. From: harris@garfield.catt.ncsu.edu (Michael Harris)
  4. Subject: Re: Problem with checkbox
  5. Message-ID: <harris.712456950@garfield.catt.ncsu.edu>
  6. Sender: news@ncsu.edu (USENET News System)
  7. Organization: North Carolina State University
  8. References: <1992Jul29.065258.19484@neptune.inf.ethz.ch>
  9. Distribution: usa, local
  10. Date: Thu, 30 Jul 1992 00:42:30 GMT
  11. Lines: 47
  12.  
  13. ezeller@iiic.ethz.ch (Emil Johann Zeller) writes:
  14.  
  15. >MRESULT ClientWinProc(HWND hwnd, USHORT msg, MPARAM mp1,
  16. >           MPARAM mp2)
  17. >{
  18. >  HWND hwndControl;
  19.    ^^^^^^^^^^^^^^^^
  20.  
  21. This is your problem. You are aware of the fact that EVERY time your window
  22. proceedure gets a message, these variables are created and then deleted
  23. when the procedure exits?  This is a LOCAL variable.  You need global storage.
  24.  
  25. >    case CWPM_CREATE:
  26. >      hwndControl = WinCreateWindow(hwnd, WC_BUTTON, "Beep on WM_PAINT",
  27. >                            WS_VISIBLE | BS_AUTOCHECKBOX,
  28. >                            cx - 100, cy - 10, 200, 20, hwnd,
  29. >                            HWND_TOP, ID_BUTTON, NULL, NULL);
  30. >    case WM_PAINT:
  31. >      if (SHORT1FROMMR(WinSendMsg(hwndControl, BM_QUERYCHECK, NULL, NULL))) WinAlarm(HWND_DESKTOP, WA_NOTE);
  32. >      return(WinDefWindowProc(hwnd, msg, mp1, mp2));
  33. >      break;
  34.  
  35. When this statement is executed, hwndControl is undefined. Either define your
  36. variable outside the context of the window procedure, or use the window word
  37. to store the handle.
  38.  
  39. Here's another suggestion that is better than the other two. If you change
  40. your WM_PAINT processing to: 
  41.  
  42. if (SHORT1FROMMR(WinSendMsg( WinWindowFromID(hwnd, ID_BUTTON),
  43.                              BM_QUERYCHECK,
  44.                              NULL,
  45.                              NULL)
  46.                  )
  47.    )
  48.    WinAlarm(HWND_DESKTOP, WA_NOTE);
  49.  
  50. you won't need the variable. WinWindowFromID returns the window handle of
  51. a window given the window's parent and the unique window id. This will only
  52. work if all children of hwnd have unique id's. (or at least the window id
  53. you are querying is unique.)
  54.  
  55.  
  56. ______________________________________________________________________________
  57.      Michael Harris - harris@catt.ncsu.edu or harris@carvm3.vnet.ibm.com
  58.  System Administrator, Computer & Technologies Theme Program, NC State Univ.
  59. (My opinions are my own and do not represent those of NCSU or IBM Corporation)
  60.