CS351 Systems Programming - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

CS351 Systems Programming

Description:

Menu items can be 'enabled', 'disabled', 'grayed out', 'checked', or 'unchecked' ... Check or uncheck a menu item. CheckMenuItem (hMenu, iID, MF_CHECKED) ... – PowerPoint PPT presentation

Number of Views:48
Avg rating:3.0/5.0
Slides: 16
Provided by: ondrejh
Category:

less

Transcript and Presenter's Notes

Title: CS351 Systems Programming


1
CS351 Systems Programming
  • Menus
  • Sockets
  • Programming Assignment

Ondrej Hrebicek Mudit Tandon
2
Introduction to Menus
  • An integral part of a Windows application
  • Easy to create using Visual Studios Resource
    Editor
  • Each selectable menu item is assigned a unique ID
    number
  • The unique ID is passed together with a
    WM_COMMAND message whenever a user chooses a menu
    item

3
Menu Structure
  • Main menu or Top-level menu located
    immediately below the caption bar
  • Submenus or Drop-down menus invoked by items
    in the main menu can be nested
  • Menu items can be enabled, disabled, grayed
    out, checked, or unchecked

4
Creating a Menu
  • Insert ? Resource ? Menu
  • Declare each menu items text and unique ID in
    the Menu Item Properties dialog box
  • Add an in front of the character youd like
    underlined (Alt key shortcut)
  • ID numbers are sent in the low word of wParam of
    a WM_COMMAND message
  • lParam is 0

5
(No Transcript)
6
(No Transcript)
7
case WM_COMMAND // Process all of our button
and menu commands switch (LOWORD
(wParam)) case ID_PUZZLE_OPEN
8
Integrating Menus with your Application
  • 1) Specify the menu name within your window class
  • wndclass.lpszMenuName TEXT (MyMenu)
  • 2) Use LoadMenu () to obtain a menu handle
  • hMenu LoadMenu (hInstance, TEXT (MyMenu))
  • hMenu LoadMenu (hInstance, MAKEINTRESOURCE
    (ID_MENU))
  • Pass hMenu to CreateWindow (...) or to SetMenu
    (hwnd, hMenu)

9
Menu Operations
  • Obtaining a windows menu handle hMenu GetMenu
    (hwnd)
  • Check or uncheck a menu item
  • CheckMenuItem (hMenu, iID, MF_CHECKED)
  • CheckMenuItem (hMenu, iID, MF_UNCHECKED)
  • Enable, disable, gray out a menu item
  • EnableMenuItem (hMenu, iID, MF_GRAYED)
  • EnableMenuItem (hMenu, iID, MF_ENABLED)
  • EnableMenuItem (hMenu, iID, MF_DISABLED)

10
Floating Popup Menus
  • Independent or main menus submenus
  • To display a popup menu in your client area
  • Capture the WM_RBUTTONUP message
  • Get the x and y coordinates of the mouse click
    (low and high word of lParam, respectively)
  • Convert x and y to screen coordinates
  • Call TrackPopupMenu (hMenu, uFlags, x, y, 0,
    hWnd, NULL)

11
Sockets
12
Sockets
  • Concept developed at UC Berkeley to add network
    support to UNIX
  • Used primarily over TCP/IP
  • Raw sockets for handmade packets
  • On Win32, the Windows Sockets API is used
  • Slightly modifies original socket interface

13
Socket Initialization
  • 1) Initialize windows networking
  • if (iError WSAStartup (MAKEWORD(2,0),
    WSAData))
  • MessageBox (hWnd, "Error in WSAStartup.",
    "Socket Error", MB_ICONERROR)
  • return FALSE
  • 2) Create an internet TCP socket stream
  • if ((sock socket (AF_INET, SOCK_STREAM,
    IPPROTO_TCP)) INVALID_SOCKET)
  • MessageBox (hWnd, "Error in socket.", "Socket
    Error", MB_ICONERROR)
  • WSACleanup ()
  • return FALSE

14
Socket Initialization (contd)
  • 3) Fill out the required address information
  • sa.sin_family AF_INET
  • sa.sin_port htons (80)
  • sa.sin_addr.S_un.S_addr inet_addr (szServer)
  • Host to Network function needed because MSB of
    port number needs to be first on Intel machines
    it is last
  • 4) Connect to the server
  • if (connect (sock, (SOCKADDR ) sa, sizeof
    (sa)) SOCKET_ERROR)
  • MessageBox (hWnd, "Error in socket.", "Socket
    Error", MB_ICONERROR)
  • WSACleanup ()
  • return FALSE

15
Sending and Receiving Data
  • send (sock, buffer, strlen (buffer), 0)
  • iBytesDownloaded recv (sock, (CHAR ) data,
    sizeof (data), 0)
  • Once data downloaded, recv () returns 0
  • closesocket (sock)
  • WSACleanup ()
Write a Comment
User Comments (0)
About PowerShow.com