Thread: API WinMain(all this stuff)

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912

    API WinMain(all this stuff)

    Okay,
    How can I access the parameters passed to the program like you would with argc, argv, etc., and what's with the API return type. How do I return that?

    One other question, in windows.h (I'm an extreme newbie, and I'm trying to write it with code only). How do I add elements to a dialog, and how would I create a new dialog on screen?

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    1. The third param passed to WinMain is of type LPTSTR........ That can be used to get the args......

    2. The easiest way to create a dialog is with a resource editor (VC++ has one). You can drag & drop controls and call the dialog with CreateDialog()

  3. #3
    Registered User ExDigit's Avatar
    Join Date
    Jan 2002
    Posts
    31
    Well, the command line that the user sed to execute your program is kept in the LPSTR part (usually lpCmdLne or similar).

    Secondly, to display a dialog it is probably easiest to use a resource script. You can learn how to do this by reading the "Dialogs - A GUI Coder's Best Friend" section at the www.winprog.org tutorial.

    I recommend using Microsoft Visual C++ for this.

    Good luck, hope you like Windows coding too.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    OK. That Helps a lot (at least now I know somewhat where to look). My programmers manual (and this is the first time it's actually helped!) says it is a far pointer in 16 bit windows. How do I know if I'm using 16 bit. Is Windows 3.1 16 bit? Also, how do I actually access the string inside LPSTR, and will it be the entire command line, or will it be just the arguments?

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    If you are using Win95 or up then you are on 32bit....... (Thank God )

    To access the params, have a quick look at this;

    Code:
    #include <string>
    using std::string;
    #include <windows.h>
    #include <cstring>
    
     
    int WINAPI WinMain(HINSTANCE hinst, HINSTANCE prev,LPSTR cmdparam,int x)
    {
    	string out("You entered ");
    
    	if(strlen(cmdparam)){
    		out += cmdparam;
    		MessageBox(0,out.c_str(),"",MB_OK);
    	}
    	else MessageBox(0,"No params","",MB_OK);
    	return 0;
     
    }
    That displays the params

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more advanced API tutorial
    By bennyandthejets in forum C++ Programming
    Replies: 10
    Last Post: 09-07-2002, 08:31 PM
  2. OLE Clipboard :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 08-11-2002, 05:57 PM
  3. Thread Synchronization :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 08-09-2002, 09:09 AM
  4. Is it foolish to program with Win32 API ?
    By Kelvin in forum Windows Programming
    Replies: 2
    Last Post: 07-09-2002, 02:03 PM
  5. Your stuff
    By smog890 in forum C Programming
    Replies: 6
    Last Post: 06-13-2002, 11:50 PM