User Interface Coding Examples


User Interface Coding Examples

The examples in this section show how to port an X Windows -based application to Microsoft Windows :

  • X Windows Hello World example (including xHello.mak)

  • Win32 Hello World example

  • Win32 DialogWindow example

X Windows Hello World Example

The following example demonstrates the Hello World code for X Windows:

 /*  ** xHello.c ** ** One possible "Hello World" according to X11  ** */ #include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/Intrinsic.h> char helloString[] = "Hello World"; int main(int argc, char **argv) {   int           iScreen;   unsigned long ulForeground;   unsigned long ulBackground;     Display      *pDisplay;   Window        exampleWindow;   GC            gc;   XSizeHints    sizeHints;   XWMHints      wmHints;   XTextProperty textProperty;   XEvent        xEvent;   pDisplay         = XOpenDisplay(NULL);   iScreen          = DefaultScreen(pDisplay);   ulBackground     = WhitePixel(pDisplay, iScreen);   ulForeground     = BlackPixel(pDisplay, iScreen);   sizeHints.x      = 0;   sizeHints.y      = 0;   sizeHints.width  = 250;   sizeHints.height = 30;   sizeHints.flags  = (PPosition  PSize);   wmHints.flags    = InputHint;   wmHints.input    = True;   exampleWindow    = XCreateSimpleWindow(pDisplay,                                           DefaultRootWindow(pDisplay),                                           sizeHints.x,                                           sizeHints.y,                                           sizeHints.width,                                           sizeHints.height,                                           2,                                           ulForeground,                                           ulBackground);      XStringListToTextProperty(&argv[0],1,&textProperty);   XSetWMName(pDisplay, exampleWindow ,&textProperty);   XSetWMProperties(pDisplay,                      exampleWindow,                      &textProperty,                      NULL,                      NULL,                      0,                      &sizeHints,                      &wmHints,                      NULL);   gc = XCreateGC(pDisplay, exampleWindow, 0,0);   XSetBackground(pDisplay, gc, ulBackground);   XSetForeground(pDisplay, gc, ulForeground);   XSelectInput(pDisplay, exampleWindow, (KeyPressMask  ExposureMask));   XMapWindow(pDisplay, exampleWindow);   do {     XNextEvent(pDisplay, &xEvent);     if (xEvent.type == Expose) {       if (xEvent.xexpose.count == 0) {         XClearWindow(pDisplay, exampleWindow);         XDrawImageString(pDisplay,                           exampleWindow,                           gc,                           (sizeHints.width/10),                           (sizeHints.height/2),                           helloString,                           (strlen(helloString)));       }     }   } while (1);       exit(0) ; } 

The xHello.mak File

The following example shows the X Windows xHello.mak file used with the previous Hello World code:

 CC = cc INSTALL = ./ INCLUDES = -I/usr/X11R6/include LIBS = -L/usr/X11R6/lib -lX11 -lXaw -lXt -lXext OBJS = xHello.o xHello : ${OBJS} ${CC} -o xHello ${OBJS} ${INCLUDES} ${LIBS} clean: rm -fr *.o xHello 

Win32 Hello World Example

The following example demonstrates the corresponding Hello World code for Win32:

 #include <windows.h>   // basic windows functionality #include <tchar.h>     // required for _tcsclen() in WndProc //+ //  type TCHAR  //  //  If the symbol _UNICODE is defined for your program,  //    TCHAR is defined as type wchar_t, a 16-bit character type. //  Otherwise,  //    TCHAR is defined as char, the normal 8-bit character type.  // //  //  If you have MSDN installed, look for these and other  //  papers and help files about UNICODE: //   //    "International Support in Microsoft Windows 2000" //    "Defining a Character Set" //    "Unicode Programming Summary" //    "Unicode and Character Sets" // // //  The TEXT macro identifies a string as  //    Unicode when UNICODE or _UNICODE is defined during compilation.  //  Otherwise, it identifies a string as an ANSI string.  // //- TCHAR     *szAppName     = TEXT("HelloWorld"); TCHAR     *szTitle       = TEXT("Win32 - Hello World"); TCHAR     *szMessage     = TEXT("Hello World!"); HINSTANCE  hInst; // A sometimes useful global copy of our instance handle //+ // //  The WindowProc function is an application-defined  //  function that processes messages sent to a window.  // //  The WNDPROC type defines a pointer to this callback function.  //  WindowProc is a placeholder for the application-defined function name.  // //  *** In the WinMain() function  //  *** notice this line of code   > wc.lpfnWndProc = (WNDPROC)WndProc; // //- LRESULT CALLBACK WndProc(HWND hWnd,                            UINT message,                            WPARAM uParam,                            LPARAM lParam)      {   //+   //  A device context is a structure that defines a set of graphic objects    //  and their associated attributes, as well as the    //  graphic modes that affect output.    //   //  The graphic objects include:   //    a pen for line drawing,    //    a brush for painting and filling,    //    a bitmap for copying or scrolling parts of the screen,    //    a palette for defining the set of available colors,    //    a region for clipping and other operations,    //    a path for painting and drawing operations.    //-   HDC hDC; // Handle to the device context, such as the GC in an X11 app   //+   //  The PAINTSTRUCT structure contains information for an application.    //  This information can be used to paint the client area of a    //  window owned by that application.    //   //   //  typedef struct tagPAINTSTRUCT {    //    HDC  hdc;    //    BOOL fErase;    //    RECT rcPaint;    //    BOOL fRestore;    //    BOOL fIncUpdate;    //    BYTE rgbReserved[32];    //  } PAINTSTRUCT, *PPAINTSTRUCT;    //   //-   PAINTSTRUCT    ps;       //+   //  The RECT structure defines the coordinates of the    //  upper-left and lower-right corners of a rectangle.    //   //  typedef struct _RECT {    //    LONG left;    //    LONG top;    //    LONG right;    //    LONG bottom;    //  } RECT, *PRECT;    //-   RECT           rect;   //+   //   This switch is used to catch and respond to messages sent to this window   //   //   An X Windows program using XNextEvent() might use a do { ... } while(1); loop    //   to process events retrieved by XNextEvent().   //   //   A Win32 program uses this function WndProc() and    //   this sort of switch(message){ .. }   //   architecture to asynchronously  process "window Messages"   //   //-   switch (message) {   //+   //     //    The WM_PAINT message is sent when the system or another    //    application makes a request to paint a portion    //    of an applications window.    //     //    The message is sent when the UpdateWindow() or    //    RedrawWindow() function is called, or by the DispatchMessage() function   //    when the application obtains a WM_PAINT message    //    by using the GetMessage() or PeekMessage() function.    //   //-   case WM_PAINT:     //+     //  The BeginPaint function prepares the specified window for painting      //  and fills a PAINTSTRUCT structure with information about the painting.      //-     hDC = BeginPaint (hWnd, &ps);     //+     //  NOTE ***      //     //  More complex applications could/should call a painting function here     //  passing the HDC (hDC) or the PAINTSTRUCT (ps) as parameters.     //  The HDC (hDC) is a member of the PAINTSTRUCT (ps)     //-     //+     //  The GetClientRect function retrieves the coordinates of a      //  windows client area. The client coordinates specify the      //  upper-left and lower-right corners of the client area.      //     //  Because client coordinates are relative to the      //  upper-left corner of a windows client area,      //  the coordinates of the upper-left corner are (0,0).      //-     GetClientRect(hWnd, &rect);     //+     // The DrawText function draws formatted text in the specified rectangle.      //     // It formats the text according to the specified method      //  (expanding tabs, justifying characters, breaking lines, and so forth).      //     //-     DrawText(hDC,                szMessage,                _tcsclen(szMessage)  ,               &rect,                 DT_CENTER  DT_VCENTER  DT_SINGLELINE);     //+     // The EndPaint function marks the end of painting in the specified window.      //     // This function is required for each call to the BeginPaint function,      //   but only after painting is complete.      //     EndPaint(hWnd, &ps);     break;   //+   //  The WM_DESTROY message is sent when a window is being destroyed.    //   //  It is sent to the window procedure of the window being destroyed    //  after the window is removed from the screen.    //   //  This message is sent first to the window being destroyed and then    //  to the child windows (if any) as they are destroyed.    //   //  During the processing of the message,    //  it can be assumed that all child windows still exist.    //-   case WM_DESTROY:       //+     //  The PostQuitMessage function indicates to the system that a      //  thread has made a request to terminate (quit).      //  It is typically used in response to a WM_DESTROY message     //-     PostQuitMessage(0);     break;   //+   //  The WM_CLOSE message is sent as a signal that a    //  window or an application should terminate   //-   case WM_CLOSE:     //+     //   The DestroyWindow function destroys the specified window.      //   The function sends WM_DESTROY and WM_NCDESTROY messages to      //   the window to deactivate it and remove the keyboard focus from it.      //     //   The function also destroys the windows menu,      //   flushes the thread message queue,      //   destroys timers, removes clipboard ownership,      //   and breaks the clipboard viewer chain      //   (if the window is at the top of the viewer chain).      //     //   If the specified window is a parent or owner window,      //   DestroyWindow automatically destroys the associated      //   child or owned windows      //     //   when it destroys the parent or owner window.      //        //   The function first destroys child or owned windows,      //   and then it destroys the parent or owner window.      //-     DestroyWindow (hWnd);     break;   //+   // Pass message on if unprocessed   //-   default:        //+     //   The DefWindowProc function calls the default window procedure      //   to provide default processing for any window messages      //   that an application does not process.      //     //   This function ensures that every message is processed.      //   DefWindowProc is called with the same parameters      //   received by the window procedure     //-     return (DefWindowProc(hWnd, message, uParam, lParam));   }   return (0); } //+ //  The WinMain function is called by the system as the  //  initial entry point for a Windows-based application.  // //  Your WinMain should  // //   1. initialize the application,  // //   2. display its main window,  // //   3. enter a message retrieval-and-dispatch loop that is the top-level  //      control structure for the remainder of the applications execution.  //- int APIENTRY WinMain(HINSTANCE hInstance,                       HINSTANCE hPrevInstance,                       LPSTR lpCmdLine,                       int nCmdShow) {   HWND      hWnd;        //+   //  The MSG structure contains message information    //  from a threads message queue.    //   //  typedef struct tagMSG {   //    HWND   hwnd;    //    UINT   message;    //    WPARAM wParam;    //    LPARAM lParam;    //    DWORD  time;    //    POINT  pt;    //  } MSG, *PMSG;    //     //-     MSG msg;        //+   //  The WNDCLASS structure contains the window class attributes that    //  are registered by the RegisterClass function.    //     //  This structure has been superseded by the WNDCLASSEX structure used    //  with the RegisterClassEx function.    //   //  You can still use WNDCLASS and RegisterClass if you do not need to set    //  the small icon associated with the window class.   //   //  typedef struct _WNDCLASS {    //    UINT       style;    //    WNDPROC    lpfnWndProc;    //    int        cbClsExtra;    //    int        cbWndExtra;    //    HINSTANCE  hInstance;    //    HICON      hIcon;    //    HCURSOR    hCursor;    //    HBRUSH     hbrBackground;    //    LPCTSTR    lpszMenuName;    //    LPCTSTR    lpszClassName;    //  } WNDCLASS, *PWNDCLASS;    //   //-   WNDCLASS  wc;   hInst = hInstance; // Store instance handle in our global variable   //+   //   1. Initialize   //   //       register the window class (required)   //       Allocate global resources   //       start threads   //       connect to hardware etc.   //  register the window class for this application   //-   wc.style         = CS_HREDRAW  CS_VREDRAW;          // Class style(s).   wc.lpfnWndProc   = (WNDPROC)WndProc;                 // Window Procedure   wc.cbClsExtra    = 0;                                   wc.cbWndExtra    = 0;                                   wc.hInstance     = hInstance;                           wc.hCursor       = LoadCursor(NULL, IDC_ARROW);   wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);      wc.lpszMenuName  = NULL;    wc.lpszClassName = szAppName;                     wc.hIcon         = NULL;      //+   //  The RegisterClass function registers a window class    //  for subsequent use in calls to the CreateWindow or    //  CreateWindowEx function.    //   //  Note  The RegisterClass function has been    //        superseded by the RegisterClassEx function.    //        You can still use RegisterClass, however, if you do    //        not need to set the class small icon.    //-   RegisterClass(&wc);   //+   //   //  2. Display the Main Window   //      //      a. CreateWindow(), CreateWindowEx() or CreateDialog()   (required)   //      b. return false on failure                              (required)   //      c. ShowWindow();   based on program logic   //      d. UpdateWindow();   //   //-   hWnd = CreateWindowEx(0,                          szAppName,                                                 szTitle,                                                   WS_OVERLAPPEDWINDOW,                          0,                          0,                          250,                          250,                                       NULL,                                              NULL,                                                      hInstance,                                                 NULL);   if (!hWnd)      return(FALSE);   //+   //  The ShowWindow() function sets the specified windows show state.   //-   ShowWindow(hWnd, nCmdShow);   //+   //  The UpdateWindow() function updates the client area    //  of the specified window by sending a WM_PAINT message to    //  the window if the windows update region is not empty.    //   //  The function sends a WM_PAINT message directly to    //  the window procedure of the specified window,    //  bypassing the application queue.    //   //  If the update region is empty, no message is sent.    //+   UpdateWindow(hWnd);           //+   //   //   3. Enter the message loop    //   //   The GetMessage() function retrieves a message    //   from the calling threads message queue.    //   //   The function dispatches incoming sent messages    //   until a posted message is available for retrieval.    //-   while (GetMessage(&msg, NULL, 0, 0)) {     //+     //   The TranslateMessage() function translates      //   virtual-key messages into character messages.      //     //   The character messages are posted to the calling      //   threads message queue, to be read the next time      //   the thread calls the GetMessage() or PeekMessage() function.      //-     TranslateMessage(&msg);     //+     //   The DispatchMessage() function dispatches a message      //   to a window procedure. It is typically used to      //   dispatch a message retrieved by the GetMessage() function.      //-     DispatchMessage(&msg);   }   return (msg.wParam);    lpCmdLine; // TRICK ***              //               // keep the compiler from complaining about unreferenced parameter              //               } 

Win32 DialogWindow Example

The code in this section is based entirely on a single modeless dialog box. This type of implementation is very quick to put together in Visual Studio using the resource editor. This example demonstrates how to communicate with many of the typical controls found in a Win32-based application.

 // resource.h //{{NO_DEPENDENCIES}} // Microsoft Developer Studio generated include file. // Used by DialogWindow.rc // #define EXAMPLE_DIALOG                  103 #define IDC_EXIT                        1000 #define IDC_RADIO1                      1001 #define IDC_DESTROY_PLANET              1001 #define IDC_RADIO2                      1002 #define IDC_DESTROY_STAR                1002 #define IDC_CHECK1                      1003 #define IDC_CHECK2                      1004 #define IDC_AUTHORIZATION_CODE          1005 #define IDC_TARGET_TEXT                 1006 #define IDC_ATTACK                      1007 #define IDC_TARGET_LIST                 1008 #define IDC_MISSION_VALUE               1009 #define IDC_TARGET_VALUE                1010 #define IDC_M_P                         1011 // Next default values for new objects //  #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE        106 #define _APS_NEXT_COMMAND_VALUE         40001 #define _APS_NEXT_CONTROL_VALUE         1012 #define _APS_NEXT_SYMED_VALUE           101 #endif #endif // DialogWindow.rc // // Notice that EXAMPLE_DIALOG is the identifier of this template and // is used in the call to CreateDialog(,MAKEINTRESOURCE(EXAMPLE_DIALOG) ,,) //                 #include "resource.h"               #define APSTUDIO_READONLY_SYMBOLS               #include "afxres.h"               #undef APSTUDIO_READONLY_SYMBOLS EXAMPLE_DIALOG DIALOG DISCARDABLE  0, 0, 267, 161 STYLE DS_MODALFRAME  WS_POPUP  WS_CAPTION  WS_SYSMENU CAPTION "  Mission Setup " FONT 8, "MS Sans Serif" BEGIN     PUSHBUTTON      "&Quit",IDC_EXIT,210,135,50,15     GROUPBOX        "  Select Mission ",IDC_STATIC,5,5,100,55     CONTROL         "Destroy Planet",IDC_DESTROY_PLANET,"Button",                     BS_AUTORADIOBUTTON  WS_GROUP,10,20,62,10     CONTROL         "Destroy Star",IDC_DESTROY_STAR,"Button",                      BS_AUTORADIOBUTTON,10,35,55,10     EDITTEXT        IDC_AUTHORIZATION_CODE,190,85,60,14,ES_AUTOHSCROLL     LTEXT           "Authorization Code :",IDC_TARGET_TEXT,120,85,65,13     PUSHBUTTON      "&Attack",IDC_ATTACK,155,135,50,14     LISTBOX         IDC_TARGET_LIST,5,90,100,60,LBS_NOINTEGRALHEIGHT                       WS_VSCROLL  WS_TABSTOP     LTEXT           "Select Target",IDC_STATIC,5,75,100,15     GROUPBOX        " Selected Mission Parameters ",IDC_STATIC,115,10,145,                     110     LTEXT           "Mission :",IDC_STATIC,120,35,60,8     LTEXT           "Target :",IDC_STATIC,120,60,60,8     EDITTEXT        IDC_MISSION_VALUE,190,35,60,14,ES_AUTOHSCROLL                       ES_READONLY     EDITTEXT        IDC_TARGET_VALUE,190,60,60,14,ES_AUTOHSCROLL                       ES_READONLY END // DialogWindow.c // #include <windows.h> #include "resource.h" /* ** Global Variables */ HWND             hExampleDlg = 0;   /* Handle to modeless dialog box */ HANDLE           hInst; //+ //  Static strings used in list boxes //- TCHAR *PlanetList[] = {   {TEXT("Mercury")},   {TEXT("Venus  ")},   {TEXT("Earth  ")},   {TEXT("Mars   ")},   {TEXT("Jupiter")},   {TEXT("Saturn ")},   {TEXT("Neptune")},   {TEXT("Uranus ")},   {TEXT("Pluto  ")},   NULL }; TCHAR *StarList[] = {   {TEXT("Andromeda       ")},   {TEXT("51 Pegasi       ")},   {TEXT("70 Virginis     ")},   {TEXT("47 Ursae Majoris")},   {TEXT("Beta Pictoris   ")},   {TEXT("G1229           ")},   {TEXT("Rho 1 Cancri    ")},   NULL }; //+ //  The DialogProc function is an application-defined callback  //  function used with the CreateDialog function.  // //  It processes messages sent to the dialog box.  // //  The DLGPROC type defines a pointer to this callback function.  //  DialogProc is a placeholder for the application-defined function name.  // //- BOOL APIENTRY ExampleDlgProc(HWND hDlg,unsigned iMessage, WORD wParam,LONG lParam) {   int     x;   LRESULT currentTarget;   switch (iMessage) {   //+   //  The WM_INITDIALOG message is sent to the dialog box    //  procedure immediately before a dialog box is displayed.    //   //  Dialog box procedures typically use this message    //  to initialize controls and carry out any other initialization    //  tasks that affect the appearance of the dialog box.    //-   case WM_INITDIALOG  :     //+     //  The CheckRadioButton function adds a check mark to      //  the specified radio button in a group and removes a check mark from     //  all other radio buttons in the group.      //     //  If DialogWindow.rc is opened as a text file, the following lines     //  can be found.     //     //  GROUPBOX        "  Select Mission ",IDC_STATIC,5,5,100,55     //  CONTROL         "Destroy Planet",IDC_DESTROY_PLANET,"Button",     //                  BS_AUTORADIOBUTTON  WS_GROUP,10,20,62,10     //  CONTROL         "Destroy Star",IDC_DESTROY_STAR,"Button",     //                  BS_AUTORADIOBUTTON,10,35,55,10     //       //  The GROUPBOX contains the two BS_AUTORADIOBUTTON controls.     //  This containment allows the radio buttons to be grouped together     //-     CheckRadioButton(hDlg,                        IDC_DESTROY_PLANET,                        IDC_DESTROY_STAR,                        IDC_DESTROY_PLANET);          //+     //  SendDlgItemMessage() sends a message to the designated control.      //  In this case it is a listbox control and the LB_INSERTSTRING message      //  is used to load a string in the list box.     //     //  For details about this message/command look up LB_INSERTSTRING      //  in MSDN or Visual Studio Help     //-     for (x=0;PlanetList[x] != NULL;x++)       SendDlgItemMessage(hDlg,                           IDC_TARGET_LIST,                           LB_INSERTSTRING,                           x,                           (LPARAM)PlanetList[x]);       //+     //  An application sends an LB_SETCURSEL message to select a string      //  and scroll it into view, if necessary.      //       //  When the new string is selected, the list box removes      //  the highlight from the previously selected string.      //-     SendDlgItemMessage(hDlg,IDC_TARGET_LIST,LB_SETCURSEL,0,(LPARAM)0);     //+     //  The SetDlgItemText() function sets      //  the title or text of a control in a dialog box.      //-     SetDlgItemText(hDlg, IDC_TARGET_VALUE, PlanetList[0]);     SetDlgItemText(hDlg, IDC_MISSION_VALUE, TEXT(" Destroy Planet"));     SetDlgItemText(hDlg, IDC_AUTHORIZATION_CODE, TEXT("JD12131950"));     break;   //+   //   The WM_COMMAND message is sent when the user selects    //   a command item from a menu, when a control sends a    //   notification message to its parent window,    //   or when an accelerator keystroke is translated.    //   //   In this example case    //-   case WM_COMMAND:     switch (wParam) {     //+     //  this message is received each time the user clicks      //  the IDC_DESTROY_PLANET radio button     //-     case IDC_DESTROY_PLANET :       currentTarget = 0;       SendDlgItemMessage(hDlg,                           IDC_TARGET_LIST,                           LB_RESETCONTENT,                           (WPARAM)0,                           (LPARAM)0);       for (x=0;PlanetList[x] != NULL;x++)         SendDlgItemMessage(hDlg,                             IDC_TARGET_LIST,                              LB_INSERTSTRING,                             x,                            (LPARAM)PlanetList[x]);       SetDlgItemText(hDlg, IDC_MISSION_VALUE, TEXT(" Destroy Planet"));       SetDlgItemText(hDlg, IDC_TARGET_VALUE, PlanetList[currentTarget]);       SendDlgItemMessage(hDlg,                           IDC_TARGET_LIST,                           LB_SETCURSEL,                           currentTarget,(LPARAM)0);       break;     //+     //  this message is received each time a user clicks      //  the IDC_DESTROY_STAR radio button     //-     case IDC_DESTROY_STAR :       currentTarget = 0;       SendDlgItemMessage(hDlg,                           IDC_TARGET_LIST,                           LB_RESETCONTENT,                           (WPARAM)0,                           (LPARAM)0);              for (x=0;StarList[x] != NULL;x++)         SendDlgItemMessage(hDlg,                             IDC_TARGET_LIST,                              LB_INSERTSTRING,                             x,                            (LPARAM)StarList[x]);              SetDlgItemText(hDlg, IDC_MISSION_VALUE, TEXT(" Destroy Star"));       SetDlgItemText(hDlg, IDC_TARGET_VALUE,  StarList[currentTarget]);       SendDlgItemMessage(hDlg,                           IDC_TARGET_LIST,                           LB_SETCURSEL,                           currentTarget,                           (LPARAM)0);       break;     //+     //  make sure a target was picked.     //  this message will be sent if the user     //  clicks anywhere in the list box     //-     case IDC_TARGET_LIST :                 //+       //  Send an LB_GETCURSEL message to retrieve the index of the currently       //  selected item, if any, in a single-selection list box.        //-       currentTarget = SendDlgItemMessage(hDlg,                                            IDC_TARGET_LIST,                                            LB_GETCURSEL,                                            0,                                           0);       if (SendDlgItemMessage(hDlg,                              IDC_DESTROY_PLANET,                             BM_GETCHECK, 0,0) == BST_CHECKED) {         SetDlgItemText(hDlg, IDC_TARGET_VALUE, PlanetList[currentTarget]);       }       else {         SetDlgItemText(hDlg, IDC_TARGET_VALUE, StarList[currentTarget]);       }       break;          //+     //  this message is received when a user clicks the IDC_ATTACK button     //-     case IDC_ATTACK :      {         TCHAR   authorizationCode[255];         TCHAR   missionString[255];         TCHAR   targetString[255];         TCHAR   executionString[255];                    //+         //  In a single-selection list box,          //  the return value is the zero-based index          //  of the currently selected item.          //  If there is no selection, the return value is LB_ERR.         //-         currentTarget =                     SendDlgItemMessage(hDlg, IDC_TARGET_LIST, LB_GETCURSEL, 0,0);         //+         //  The GetDlgItemText function retrieves the title or          //  text associated with a control in a dialog box.          //-         GetDlgItemText(hDlg,                          IDC_AUTHORIZATION_CODE,                          authorizationCode,                          32);          GetDlgItemText(hDlg, IDC_MISSION_VALUE, missionString, 32);         GetDlgItemText(hDlg, IDC_TARGET_VALUE,  targetString, 32);                  //+         //  The wsprintf function formats and stores a series of characters          //  and values in a buffer. Any arguments are converted and copied          //  to the output buffer according to the corresponding format          //  specification in the format string.          //         //  The function appends a terminating null character to          //  the characters it writes, but the return value does          //  not include the terminating null character in its          //  character count.          //         //  use this rather than sprintf() in a Win32-based application         //-         wsprintf(executionString,          TEXT("%s (%s) Authorization Code - %s, Has been carried out!"),           missionString,           targetString,           authorizationCode);         //+         //  The MessageBox function creates, displays, and operates          //  a message box. The message box contains an application-defined         //  message and title, plus any combination of predefined icons          //  and push buttons.         //         //  MessageBox() returns a value based on the type          //  indicated in the 4th parameter and user response.         //           //  it is used similarly to the X/Motif  XmCreateQuestionDialog()         //         //  dialog = XmCreateQuestionDialog (w, "notice", args, n);         //         //-         MessageBox(hDlg,                      executionString,                     TEXT("Mission Execution"),                      MB_OK);     }     break;          case IDC_EXIT:       DestroyWindow(hDlg);       break;     default:       return FALSE;     }     break;   case WM_DESTROY:     PostQuitMessage(0);     break;   case WM_CLOSE:        DestroyWindow(hDlg);       break;   default:     return FALSE;   }   return FALSE; } //+ //  This example application is based on DialogBox. // //  WinMain calls CreateDialog(), shows that window and  //  enters the message loop. // //  This sort of implementation can be used to quickly  //  develop applications that require a small GUI.  //  There is however, nothing to prevent large applications //  from using this model. //- int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,  LPSTR  lpCmdLine, int nCmdShow) {   MSG       msg;   hInst     = hInstance;   //+    // Create modeless dialog box.    //   // The CreateDialog macro creates a modeless dialog box from    // a dialog box template resource.    //   // This resource is found in DialogWindow.rc.   hExampleDlg =      CreateDialog(hInstance,                    MAKEINTRESOURCE(EXAMPLE_DIALOG),                   (HWND)NULL,                   (DLGPROC)ExampleDlgProc);   if (hExampleDlg != NULL) {     ShowWindow(hExampleDlg, SW_SHOW);    }   while (GetMessage(&msg, NULL, 0, 0)) {     if (hExampleDlg == 0  !IsDialogMessage(hExampleDlg, &msg)) {       TranslateMessage(&msg);       DispatchMessage(&msg);     }   }   return (msg.wParam); } 



UNIX Application Migration Guide
Unix Application Migration Guide (Patterns & Practices)
ISBN: 0735618380
EAN: 2147483647
Year: 2003
Pages: 134

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net