Thread: win32 api help

  1. #1
    Banned
    Join Date
    May 2004
    Posts
    55

    win32 api help

    Hello, I'm going to make a program that first reads from program.ini and then writes it when a key is pressed, like, you press f12, it writes your password, but I've got stuck here:
    Code:
        switch (message)
        {
            case WM_DESTROY:
                PostQuitMessage (0);
                break;
            case WM_CLOSE:
                DestroyWindow(hwnd);
                break;
            case WM_KEYDOWN:
                switch (wParam)
                {
                    case VK_F12:
                    // Here the code must be
                }
            default:
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
    Notice this isn't console app, its win32 api app, grateful for answer

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    1) What exactly is the problem you're having?
    2) This may be more appropriate in the Windows Programming forum, depending on the first question.
    3) USE CODE TAGS! Oh... Sorry... Force of habit... YOU USED CODE TAGS! YOU ROCK!

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>//code goes here<<

    Read this faq and this faq; for a winapi specific solution the file management functions can be found here with a very small example of opening a file for reading and writing on this page. The api's of interest are CreateFile, CloseHandle, ReadFile and, unsurprisingly, WriteFile

    Once you have decided whether you are going for a winapi (windows), c or c++ approach and you have at least a little file io code to work with you should be better placed to direct any future questions to the relevant board.

    edit: editing
    Last edited by Ken Fitlike; 08-15-2004 at 03:20 PM.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    For .ini files you can also use WritePrivateProfileString:
    Code:
    WritePrivateProfileString(TEXT("PasswordSettings"), TEXT("UserName"), TEXT("my user name"), TEXT("C:\\Path to\\program.ini"));
    
    WritePrivateProfileString(TEXT("PasswordSettings"), TEXT("Password"), TEXT("my password"), TEXT("C:\\Path to\\program.ini"));
    which will give you something like:
    Code:
    [PasswordSettings]
     UserName = my user name
     Password = my password
    You can read the values back using GetPrivateProfileString:
    Code:
    TCHAR szPassword[128];
    
    GetPrivateProfileString(TEXT("PasswordSettings"), TEXT("Password"), TEXT("Default password"), szPassword, 128, TEXT("C:\\Path to\\program.ini"));

  5. #5
    Banned
    Join Date
    May 2004
    Posts
    55
    You mean like this?
    Code:
    {
        switch(Msg)
        {
        case WM_DESTROY:
            PostQuitMessage(WM_QUIT);
            break;
        case WM_KEYDOWN:
            switch(wParam)
                {
                    case VK_F12:
                    WritePrivateProfileString(TEXT("PasswordSettings"), TEXT("Password"), TEXT("my password"), TEXT("Program.ini"));
                }
                 break;
        default:
    
            return DefWindowProc(hWnd, Msg, wParam, lParam);
        }
    
        return 0;
    }
    Didn't worked :\

    Here is the .ini file:
    Code:
    [PasswordSettings]
    Password = my password
    The idea is to type my password when pressing F12
    Last edited by Noxir; 08-16-2004 at 11:38 AM.

  6. #6
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Continued here...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Win32 API or Win32 SDK?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 07-20-2005, 03:26 PM
  2. OpenSSL and Win32 SSL API :: SSL/TLS
    By kuphryn in forum Networking/Device Communication
    Replies: 0
    Last Post: 03-10-2004, 07:46 PM
  3. FILES in WinAPI
    By Garfield in forum Windows Programming
    Replies: 46
    Last Post: 10-02-2003, 06:51 PM
  4. OLE Clipboard :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 08-11-2002, 05:57 PM
  5. Thread Synchronization :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 08-09-2002, 09:09 AM