开发者

Simple value input in a Windows program

开发者 https://www.devze.com 2023-03-11 06:24 出处:网络
I have a program that runs in the Win32 environment. There is one variable that I would like to set before the program begins. The only reason it is a Win32 program is because I am accessing serial po

I have a program that runs in the Win32 environment. There is one variable that I would like to set before the program begins. The only reason it is a Win32 program is because I am accessing serial ports. I don't care how I input the variable - it is a number and I suppose a dialog edit box would be best - but I don'开发者_开发问答t know how to go about this with Win32!

Ignoring the bulk of the program, my code is as follows:

#include <windows.h>

//Initialise Windows module
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)

{
 int variable;

 //ACTION USING THE VARIABLE OCCURS HERE

 return 0;
}


A quick hack:

#include <windows.h>
#include <stdlib.h>

//Initialise Windows module
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)

{
 int variable = atoi( lpszArgument );

 //ACTION USING THE VARIABLE OCCURS HERE

 return 0;
}

You can then run your program as:

myprog.exe 42

Creating a dialog via the Windows API is quite complicated. But why are you writing this in C or C++? Why not use C#, or Python?


To access serial port, you don't need windows application. You can create a simple console based application, it will be a still win32 by architecture.

The advantages being using a console application would that you could use 'C' style scanf or C++ style cin to read the input from user.

For the windows application, you need to create a dialog with text box in it and Show the window and wait for user to input, let user to press a 'OK' button or enter.. thats a lot of process..

Just write a console application.. That will do.. Otherwise use MFC..

0

精彩评论

暂无评论...
验证码 换一张
取 消