// hello.cpp : Defines the entry point for the application. // #include "stdafx.h" #include "resource.h" #define MAX_LOADSTRING 100 #define ID_SENDTEXT 6 #define ID_SENDBTN 5 //__declspec( dllimport ) void LCD_put_data_string(unsigned short s[]); //__declspec( dllimport ) void LCD_init(void); // Global Variables: HINSTANCE hInst; // current instance TCHAR szTitle[MAX_LOADSTRING]; // The title bar text TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text // Foward declarations of functions included in this code module: ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT DoCommandMain (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { // TODO: Place code here. MSG msg; HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_HELLO, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_HELLO); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam; } // // FUNCTION: MyRegisterClass() // // PURPOSE: Registers the window class. // // COMMENTS: // // This function and its usage is only necessary if you want this code // to be compatible with Win32 systems prior to the 'RegisterClassEx' // function that was added to Windows 95. It is important to call this function // so that the application will get 'well formed' small icons associated // with it. // ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC) WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = 0; wc.hCursor = 0; wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); wc.lpszMenuName = 0; wc.lpszClassName = szWindowClass; return RegisterClass(&wc); } // // FUNCTION: InitInstance(HANDLE, int) // // PURPOSE: Saves instance handle and creates main window // // COMMENTS: // // In this function, we save the instance handle in a global variable and // create and display the main program window. // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd,hC1,hC2; hInst = hInstance; // Store instance handle in our global variable hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE, 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } //******** ADDED CODE HERE **************************************** //This creates the text box for input hC1=CreateWindowEx(WS_EX_CLIENTEDGE, TEXT ("edit"),TEXT (""), WS_VISIBLE | WS_CHILD, 20,80,150,25,hWnd, (HMENU) ID_SENDTEXT,hInstance,NULL); //This creates the send button hC2=CreateWindowEx(WS_EX_CLIENTEDGE, TEXT ("button"),TEXT ("&Send"), WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 180,80,75,25,hWnd, (HMENU) ID_SENDBTN, hInstance,NULL); //************** END ADDED CODE************************************ ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); LCD_init(); /* initialize display */ // LCD_put_data_string("12345678901234567890"); return TRUE; } // // FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; TCHAR szHello[MAX_LOADSTRING]; LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); switch (message) { case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... RECT rt; GetClientRect(hWnd, &rt); DrawText(hdc, szHello, _tcslen(szHello), &rt, DT_CENTER); EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; case WM_COMMAND: return DoCommandMain(hWnd, message, wParam, lParam); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } // DoCommandMain gets a command from the MainWindow LRESULT DoCommandMain (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) { WORD idItem, wNotifyCode; HWND hwndCtl; INT i; TCHAR buffer[30] = TEXT(" "); // Parse the parameters. idItem = (WORD) LOWORD (wParam); wNotifyCode = (WORD) HIWORD (wParam); hwndCtl = (HWND) lParam; switch(idItem) { case ID_SENDBTN: //*********ADDED CODE HERE********* i = GetDlgItemText(hWnd,ID_SENDTEXT,buffer,30); while ((20 - i )> 0) // pad it with spaces { buffer[i] = (unsigned short) ' '; i++; } LCD_put_data_string(buffer);//Library call to send string return 0; break; //*******END ADDED CODE********* default: return 0; } }