john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

Win CE c read file c windows main

/* 2010-02-20 jpfeiffer
When Next button is pressed update
Window display , can convert char[] to wchar[]  BUT zero wchar before pass by ref!
*/

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <aygshell.h>
#include "stringToWchar.txt"
#include "drawText.txt"
#include "getFileLine.txt"


#define  IDC_ExitButton    40099
#define  IDC_textRefreshButton    40098


LRESULT CALLBACK MenuWndProc(                                    HWND hwnd,   UINT message, WPARAM wParam,   LPARAM lParam) 
{       wchar_t text[128];
    char buffer[128];
    int textpointX=100;
    int textpointY=100;
    char c;
    FILE* fp;
    fp=NULL;

  switch (message)              
       {   
    case WM_CREATE:
/* opens in root directory */
    fp = fopen("test.txt","r"); 
    if( fp==NULL )
    {   printf("\nfopen error\n");
        exit(1);
    }else{  
    printf("\nfopen ok\n");
getFileLine( fp, buffer );
    fclose(fp);
    }
     break;

     case WM_COMMAND:         
            switch(LOWORD(wParam))    
               {       case IDC_ExitButton:       
                     PostQuitMessage(0);
                     break;
             case IDC_textRefreshButton: 
    strcpy(  buffer , "text2");
    memset( text , 0, sizeof( text ));
        stringToWchar(  buffer , text);        
/* invalidateRect(hwnd,NULL,TRUE);
*/
       drawText( hwnd, text, 
textpointX, textpointY );
   textpointY  = textpointY + 10;   
printf("\nY=%d", textpointY );      
        break;

                    default:
                    break;          
     }      
    break;  
     case WM_DESTROY: 
                  PostQuitMessage(0);    
               break;

               case WM_PAINT:
         initializeBackground( hwnd );
     break;

                default:      
                   return DefWindowProc(hwnd, message, wParam, lParam);
       }
    return 0;
}

int APIENTRY WinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPTSTR lpCmdLine, int ncmdshow )
{ 
    HWND hwnd = NULL;  
    HWND ExitButton = NULL;  
    HWND textRefreshButton = NULL; 
    MSG msg;   
    WNDCLASS wc;
    HMENU hMenu;

 wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC)MenuWndProc; 
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = 0;
    wc.hCursor = 0;
    wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = (LPTSTR) L"Menu App";

  if(!  RegisterClass (&wc))
{ 
    MessageBox(NULL, TEXT("errors "),
  L"IMPORTANT", MB_OK); 
    return 0;
 }

    hwnd = CreateWindow (L"Menu App", L"refresh text", WS_VISIBLE,
        0,27, 200, 200,
        (HWND)NULL, NULL, hInstance, (LPSTR)NULL);

ExitButton = CreateWindow( 
L"BUTTON", L"quit", WS_CHILD | 
WS_VISIBLE | BS_PUSHBUTTON, 
0, 0, /* top left x,y */
40, 40, /* width & height */
hwnd, (HMENU)IDC_ExitButton, 
hInstance, NULL);


   textRefreshButton = CreateWindow( 
L"BUTTON", L"Next", WS_CHILD | 
WS_VISIBLE | BS_PUSHBUTTON, 
160, 160, 40, 40, hwnd, (HMENU)IDC_textRefreshButton,
hInstance, NULL);


ShowWindow(hwnd, ncmdshow); 
UpdateWindow(hwnd);

 while(GetMessage(&msg, NULL, 0, 0))  {       
    TranslateMessage(&msg);                  
    DispatchMessage(&msg); 
   }   
    return msg.wParam;
} /* end WinMain */

  • « Win CE c read file gcc bat
  • drupal 6 custome theme how to create a zen subtheme part one »

Published

Feb 21, 2010

Category

c

~264 words

Tags

  • c-readfile 5
  • cwm 2
  • win-ce 40