Reputation: 1096
I'm looking to use the Win32 API in a project I'm working on. However I have no idea how to call the Win32 API from my cygwin project. Can someone point me in the correct direction?
Upvotes: 9
Views: 9691
Reputation: 327
If you know Perl, you may want to use the win32::GUI module to create windows and dialogs. Make sure perl5 was included in your cygwin install.
Run cpan from the cygwin command line to get the cpan interpreter then do a get win32::GUI.
**To Get Familiar with win32::GUI**
===========================================
win32-gui-demos.pl for a tutorial
man 1 win32-gui-demos.pl for an overview -or-
perldoc win32-gui-demos.pl for an overview
perldoc win32::GUI for an intro
If the tutorials don't run from its menus, just copy and paste them into a vi file and make them executable when saved.
eg:(simple dialog to enhance)
#!perl -w
use strict;
use warnings;
use Win32::GUI();
my $main = Win32::GUI::DialogBox->new(
-name => 'Main',
-text => 'Continue with Outlook Backup?',
-width => 200,
-height => 200
);
$main->AddButton(
-name => 'Default',
-text => 'Ok',
-default => 1, # Give button darker border
-ok => 1, # press 'Return' to click this button
-width => 60,
-height => 20,
-left => $main->ScaleWidth() - 140,
-top => $main->ScaleHeight() - 30,
);
$main->AddButton(
-name => 'Cancel',
-text => 'Cancel',
-cancel => 1, # press 'Esc' to click this button
-width => 60,
-height => 20,
-left => $main->ScaleWidth() - 70,
-top => $main->ScaleHeight() - 30,
);
$main->Show();
Win32::GUI::Dialog();
exit(0);
sub Main_Terminate {
return -1;
}
sub Default_Click {
print "OK to Proceed Selected\n";
return 0;
}
sub Cancel_Click {
print "Cancel Backup Selected\n";
return 1;
}
Upvotes: 2
Reputation: 19064
The Win32 API can be accessed from a cygwin program by including the "windows.h" header file. It implies that you have the win32 packages installed, of course. Here is an example program:
#include <iostream>
#include <string>
#include <windows.h>
int main(int argc, char *argv[])
{
std::string val;
if (argc > 1)
{
val = argv[1];
}
std::cout << "You typed: " << val << std::endl;
::MessageBox(NULL, val.c_str(), "You Typed:", MB_OK);
return 0;
}
This can be compiled and linked with "make filename" where filename.cpp contains the above source. Then execute by typing ./filename xxxx at the bash prompt. Then xxxx will appear in a message box window.
Upvotes: 7
Reputation: 28782
You could look at the Cygwin FAQ (specifically 6.9 How do I use Win32 API calls?)
Of course you will need to get a hold of the WIN32API headers -- your best option is to download/install a fre c++ compiler (e.g. MinGW) and refer to its headers.
Upvotes: 3