Thread: Windows API

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    24

    Windows API

    Hi am using C, Visual C++ compiler & Windows 7 O.S.,
    Am designing UI using C, Does anybody know any windows API , which could read from a buffer & display in window. ?

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Yes.

    PS If you can be a bit more specific then you will get a better answer as I won't have to guess which one I should explain.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Jul 2011
    Posts
    24
    Hi Novacain,

    I have come up with some other solution, I have a file with 10 lines of data, Now I just want to display that data in a window. Is there any API that could read fom a file & display it. ?

  4. #4
    Registered User
    Join Date
    Jul 2011
    Posts
    24
    Hi Novacain,

    I have come up with some other solution, I have a file with 10 lines of data, Now I just want to display that data in a window. Is there any API that could read fom a file & display it. ?

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Again not enough info.

    A simple WIN32 app would open the file (OpenFile()) and read it (ReadFile()) into a buffer (depending on the data type) then close it during the WM_CREATE or WM_INITDIALOG message.

    Assuming the data is text you would use CHAR or a string for the buffer.

    The app would use a Edit (or TextBox) control and set the Content or Text property to the string buffer (or use SetDlgItemText() etc).

    There is much more to it than, and multiple ways to do this in WIN32, that but you do not provide enough details.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Registered User
    Join Date
    Jul 2011
    Posts
    24
    @Novacain,

    Lets take an example.

    Consider a file " parimal.txt ", its having following data :
    Hi I am Parimal
    I like C

    Now I want the above two lines to be displayed in a window. And the window should be such that we can copy the two lines from it using mouse and paste it somewhere else. But the user should not be allowed able to edit anything from window. Means it should be a kind of static.

    As soon as the user presses OK or close button on window it should close the window & program should end !!

    Now can you suggest something ?

  7. #7
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291
    One thing about 'OpenFile()' function, as it is described on the reference manual (do not take it as a critique novacain )

    Code:
    The OpenFile function creates, opens, reopens, or deletes a file. 
    
    This function is provided for compatibility with 16-bit versions of Windows. In particular, the OpenFile function cannot open a named pipe. 
    Win32-based applications should use the CreateFile function.
    parimal.s.dave: I think that what novacain is saying is that nobody knows what you are able to do: Can you write a window application? Do you know how to process the WM_ messages? Do you know something about predefined controls? Do you know STATIC and EDIT predefined controls? Do you know how to use the file functions? Also a piece of code will be usefull.

    Regards
    Niara

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    So a very simple WIN32 app that the MSVC IDE will create for you in seconds, plus a few minutes on the resource editor.

    It has a system menu, a default button and a control to display the text, I would use a atatic control or an edit control with ES_MULTILINE and ES_READONLY.

    Have you tried any of this?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  9. #9
    Registered User
    Join Date
    Jul 2011
    Posts
    24
    HI Novacain & Niara,

    Consider the following code. I know that I have not done a much good job, but i just want to make it so that I can get my job done & move ahead. I am new to API's & specially not good with UI's. But am learning.

    Code:
    #include <stdio.h>
    #include <windows.h>
    
    int _stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
        {
            HWND a = NULL;
            FILE *Fileptr;
            char *FirstName  = calloc(150,sizeof(char));
            char *LastName   = calloc(150,sizeof(char));
            char *DomainName = calloc(300,sizeof(char));
    
            Fileptr = fopen("EmailCombinations.txt","w");
    
            a = CreateWindow("EDIT","", WS_OVERLAPPEDWINDOW,300,100,1000,100,0,0,a,0);
            ShowWindow(a, nCmdShow);
            MessageBoxEx(0,"Enter the First Name above in the above window & then press OK ","NOTE",MB_ICONEXCLAMATION,MB_OK);
            GetWindowText(a,FirstName,150);
            DestroyWindow(a);        
            
            a = CreateWindow("EDIT","", WS_OVERLAPPEDWINDOW,300,100,1000,100,0,0,a,0);
            ShowWindow(a, nCmdShow);
            MessageBoxEx(0,"Enter the Last Name in the above window & then press OK ","NOTE",MB_ICONEXCLAMATION,MB_OK);
            GetWindowText(a,LastName,150);
            DestroyWindow(a);        
            
            a = CreateWindow("EDIT","", WS_OVERLAPPEDWINDOW,300,100,1000,100,0,0,a,0);
            ShowWindow(a, nCmdShow);
            MessageBoxEx(0,"Enter the Domain Name in the above window & then press OK ","NOTE",MB_ICONEXCLAMATION,MB_OK);
            GetWindowText(a,DomainName,300);
            DestroyWindow(a);        
            
            fprintf(Fileptr,"%s%s%s\n",FirstName,LastName,DomainName);
            fprintf(Fileptr,"%s.%s%s\n",FirstName,LastName,DomainName);
            fprintf(Fileptr,"%s_%s%s\n",FirstName,LastName,DomainName);
            fprintf(Fileptr,"%s%s%s\n",LastName,FirstName,DomainName);
            fprintf(Fileptr,"%s.%s%s\n",LastName,FirstName,DomainName);
            fprintf(Fileptr,"%s_%s%s\n",LastName,FirstName,DomainName);
            fprintf(Fileptr,"%c%s%s\n",*FirstName,LastName,DomainName);
            fprintf(Fileptr,"%c.%s%s\n",*FirstName,LastName,DomainName);
            fprintf(Fileptr,"%c_%s%s\n",*FirstName,LastName,DomainName);
            fprintf(Fileptr,"%s%c%s\n",FirstName,*LastName,DomainName);
            fprintf(Fileptr,"%s.%c%s\n",FirstName,*LastName,DomainName);
            fprintf(Fileptr,"%s_%c%s\n",FirstName,*LastName,DomainName);
            fprintf(Fileptr,"%s%c%s\n",LastName,*FirstName,DomainName);
            fprintf(Fileptr,"%s.%c%s\n",LastName,*FirstName,DomainName);
            fprintf(Fileptr,"%s_%c%s\n",LastName,*FirstName,DomainName);
            fprintf(Fileptr,"%c%c%s\n",*FirstName,*LastName,DomainName);
            fprintf(Fileptr,"%c.%c%s\n",*FirstName,*LastName,DomainName);
            fprintf(Fileptr,"%c_%c%s\n",*FirstName,*LastName,DomainName);
            
            fclose(Fileptr);
            return 0;
        }
    I just want to display in window whatever is written in the file "EmailCombinations.txt". I hope I have provided sufficient information this time... : )

  10. #10
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291
    Did you compiled the code? There are an error on each CreateWindow, as it expects a HANDLE handle to application instance and you give it a HWND handle to owner window (which they are incompatible pointer types).

    Even if you can compile your code it will show 3 sequential floating windows with an edit control without focus with a message box alerting what to do. That's not the way to do a friendly application (my opinion). If you are plannig to restrict the use to yourself then there's no more to say: instead of save the content into a file, just save it into a text buffer, write it into a file and then create a new edit, set the text buffer as edit content and show another MessageBox to tell that's all. That's how you will have the file content into an edit control copy/pastable.

    If you are planning to do something more elaborated, read twice the novacain last post and start with it; also maybe you will want take a look at Windows programming links to find a list of good Win32 API tutorials - references; also check out EFNet #Winprog as it's a good starting place to start.

    Surely you won't get any code now for that thread: you are developing a car and asking how to add a turbo to the engine while the wheel is badly designed; do not take it personally, is a part of the learning process (I'm also still learning Win32)

    Hope that helps

  11. #11
    Registered User
    Join Date
    Jul 2011
    Posts
    24
    @ Niara ,

    Yup I agree with you that I have not done a good job with UI & other stuff. I have started learning MFC. Hope this helps me. Apart from that I am able to compile the code well, without any errors & warning's. Well whatever is the expected output its the same that I am getting. But in file. I just wanted to display the file content in window, so that I don't have to open the file to use content , instead I just use the content from window.

    I am really ........ed off with this Win32 API"s, the way the Microsoft guys have tried to explain things, it's becoming really difficult for a beginner like me..

  12. #12
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    theForger's Win32 API Tutorial

    This isn't just any old Win32 API tutorial. This is THE Win32 API tutorial.

    If you can't learn from this then yes it's time to move on to MFC.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Access Windows directory with OPENFILENAME in Windows mobile
    By nikhilesh1987 in forum Windows Programming
    Replies: 2
    Last Post: 05-31-2011, 02:49 AM
  2. GetDiskFreeSpace Windows API fails on windows 2000
    By dnyampawar in forum Windows Programming
    Replies: 7
    Last Post: 07-09-2009, 03:39 AM
  3. Differences between Windows XP and Windows Vista programming
    By nathan3011 in forum Windows Programming
    Replies: 3
    Last Post: 01-15-2009, 10:05 AM
  4. Open an excel file from a windows service under Windows Vista
    By AdrianaLuby in forum C# Programming
    Replies: 1
    Last Post: 06-05-2007, 03:55 AM
  5. Replies: 6
    Last Post: 01-07-2002, 02:46 AM