简体   繁体   中英

Calling WinMain from other functions

So i have a .cpp file that has for example functions: drawLine(), drawSquare() and it has main(). In main() i want to invoke function (from other file) that creates a window using WinApi and after that invoke drawLine() and drawSquare() to paint some figures in that window. How can I invoke this WinMain() if it looks like that (only declaration):

int WINAPI WinMain (HINSTANCE hThisInstance,
                HINSTANCE hPrevInstance,
                LPSTR lpszArgument,
                int nFunsterStil) 

And one more thing. Does this creating window have to be in WinMain or is there a way to put instructions in a regular function?

main is the entry point for console applications.

WinMain is for GUI apps.

Your project should have only one of these, period.

You can put window creation code anywhere; it doesn't need to be in WinMain .

Q. How can I invoke this WinMain() if it looks like that (only declaration)?

  • The parametes are not essential for your GUI application to work. Try do like this:

WinMain( 0, 0, 0, 0 );

Q. Does this creating window have to be in WinMain or is there a way to put instructions in a regular function?

  • WinMain is just the entry point. You can put it wherever you want...

--

It seems your setup is a little bit confusing. As far as I could understand, you don't really need WinMain... just call the Windows API functions in order to create your Window.

WinMain is the entry point and must be ( like main in c ) named like it is. AFAIK there is no possibility to rename this function. And calling this function from another file might perhaps work, but this is usually not done and should not be done, because ONLY windows os is a legitimate caller to all WinMain functions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM