..
.., ..
WINDOWS
-
, 2016
.., ..
Windows: - . : i, 2016. 143 .
:
.. ..-.., - ;
.. ..-.., - ;
.. ..., , . .. .
(API) Win32 , , , -. .
.., ..
. .. , 2016
1. Win32 API | |
2. Win32 API | |
3. Win32 API | |
4. | |
5. | |
6. | |
7. | |
8. Win32 API | |
9. Win32 API | |
10. Win32 API | |
11. | |
- Microsoft Visual Studio 2010 Win32 API( Win32) (API Application Programming Interface), () Windows.
11 , Win32. , , , - .. , Win32, , . MS Visual Studio 2010, , , , . Win32 , Visual Studio 2010.
|
|
:
1) ;
2) ;
3) ;
4) ;
5) ;
5) .
, , .
. , .
, 4.
:
− ;
− ;
− ;
− ;
, , , Win32, Windows- , .
Win32, Windows Windows NT.
1
Win32 API
:
1. Windows.
2. , Win32API.
3. Win32 .
Windows- , . MS-DOS . Windows, , . Windows , , , . , . 1 Windows-.
|
|
Windows , , , . - , , , .
1. Windows
Windows , , (Application Program Interface, API).
, , , (Graphics Device Interface, GDI).
API- , , , Windows-, . , Windows bool, Windows- bool, int. Windows .
API- , , , Pascal. pascal, Windows CALLBACK, APIENTRY WINAPI. - , , . , API- .
Windows-
, MS-DOS, Windows . , Windows- :
1. .
2. .
3. .
4. .
5. .
. , .
1 "" Windows-.
1. Windows-
#include <windows.h>
#include <tchar.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
TCHAR WinName[] = _T("MainFrame");
int APIENTRY _tWinMain(HINSTANCE This, //
HINSTANCE Prev, // 0
LPTSTR cmd, //
int mode) //
{
HWND hWnd; //
MSG msg; //
WNDCLASS wc; //
//
wc.hInstance = This;
wc.lpszClassName = WinName; //
wc.lpfnWndProc = WndProc; //
wc.style = CS_HREDRAW | CS_VREDRAW; //
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); //
wc.hCursor = LoadCursor(NULL,IDC_ARROW); //
wc.lpszMenuName = NULL; //
|
|
wc.cbClsExtra = 0; //
wc.cbWndExtra = 0; //
//
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
if(!RegisterClass(&wc)) return 0; //
//
hWnd = CreateWindow(WinName, //
_T(" Windows-"), //
WS_OVERLAPPEDWINDOW, //
CW_USEDEFAULT, // x
CW_USEDEFAULT, // y
CW_USEDEFAULT, // Width
CW_USEDEFAULT, // Height
HWND_DESKTOP, //
NULL, //
This, //
NULL); //
ShowWindow(hWnd, mode); //
//
while(GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);//
DispatchMessage(&msg); // WndProc()
}
return 0;
}
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{ //
switch(message)
{
case WM_DESTROY: PostQuitMessage(0);
break; //
//
default: return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
Windows-
. , Windows-.
#include <windows.h>
Visual Studio , , : windef.h, winbase.h, wingdi.h, winuser.h; , API-, .
:
#include <tchar.h>
, , _() Unicode :
#define _T(x) T(x)
#ifdef _UNICODE
#define __T(x) L ## x
#else
#define __T(x) x
#endif
2.
"L", UNICODE, UNICODE; " ", . UNICODE Character Set ( 2). Property Pages Property Manager Solution Explorer.
, Unicode, Windows-. , Windows .
:
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
, . , , . LRESULT long Win32-.
:
TCHAR WinName [] = _T("MainFrame");
TCHAR wchar_t, _UNICODE, char, .
|
|
wchar_t short Unicode, 16 .
. , .
:
int APIENTRY _tWinMain(HINSTANCE This, //
HINSTANCE Prev, // 0
LPTSTR cmd, //
int mode) //
Windows- Unicode wWinMain(), 8- -WinMain(), _t, API-. , :
− This , ;
− Prev , . ( Windows 95, );
− cmd , . LPTSTR TCHAR*;
− mode .
() Windows, . - . : HINSTANCE, HWND ., 32- .
:
− hWnd ;
− msg , , :
struct MSG
{
HWND hWnd; //
UINT message; //
WPARAM wParam; // 32-
LPARAM lParam; //
DWORD time; //
POINT pt; // (x,y)
};
struct POINT
{
LONG x,y;
};
wparam " " 16- 16- , Win32 32- , lparam.
wc , . :
wc.hlnstance = This; .
wc.lpszClassName = WinName;
.
wc.lpfnWndProc = WndProc;
.
wc.style = CS_HREDRAW | CS_VREDRAW;
.
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
() . LoadIcon() . NULL, , :
idi_application ;
idi_asterisk ;
idi_exclamation ;
idi_hand ;
IDI_QUESTION ;
idi_winlogo Windows;
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
LoadCursor () , , :
idc_arrow ;
idc_appstarting ;
idc_cross ;
idc_ibeam ;
idc_no ;
idc_sizeall ;
idc_sizenesw , - -;
idc_sizenwse , - -;
idc_sizens , ;
idc_sizewe , ;
idc_uparrow ;
idc_wait ;
wc.lpszMenuName = NULL;
, null.
wc.cbClsExtra = 0;
.
wc.cbWndExtra = 0; .
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
, . , WHITE_BRUSH. HBRUSH.
, API- CreateWindow(), :
|
|
1. WinName , .
2. _T(" Windows-") Unicode -.
3. ws_overlappedwindow , -
, , , ,
, .
, :
#define WS_OVERLAPPEDWINDOW (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|
WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX)
, , :
WS_OVERLAPPED ;
WS_CAPTION ;
WS_THICKFRAME ;
WS_MAXIMIZEBOX ;
WS_MINIMIZEBOX ;
WS_SYSMENU ;
WS_HSCROLL ;
WS_VSCROLL ;
WS_VISIBLE ;
WS_CHILD ;
WS_POPUP ;
4. (x,y), : Width Height . CW_USEDEFAULT , ( ) .
5. , NULL, .
6. , This.
7. , , , NULL.
, , . , ShowWindow(hWnd, mode), : hWnd mode . , .
, . while, GetMessage(&msg, NULL, 0, 0). Windows-, , . , GetMessage() :
□ &msg MSG, ;
□ hWnd , , , null;
□ [min, max] . , 0.
, winuser.h. WM_.
:
TranslateMessage(&msg);
DispatchMessage(&msg);
WM_CHAR. wParam msg Windows- CP-1251, lParam , , 1.
.
, DispatchMessage(&msg), .
.
WndProc(), Windows- .
1. , HIWORD(lParam)
1, , 0 | |
1, | |
1, <Alt> | |
129 | |
1, | |
70 | Scan- |
switch, message. WM_DESTROY. , . , PostQuitMessage(0), 0. WM_QUIT, GetMessage () . .
DefWindowProc(), , return.
2.
#include <windows.h> // , API
// - int main() :
int WINAPI WinMain(HINSTANCE hInstance, //
HINSTANCE hPrevInstance, // Win32
LPSTR lpCmdLine, //
int nCmdShow) //
{
// "" ( )
MessageBox(NULL, L", !!!", L" ", MB_OK);
return NULL; //
}
3.
#include <windows.h> // API
// :
int WINAPI WinMain (HINSTANCE hInst, //
HINSTANCE hPreviousInst, // Win32 ,
LPSTR lpCommandLine, //
int nCommandShow) //
{
int result = MessageBox(NULL, L" WINAPI?!", L"",
MB_ICONQUESTION | MB_YESNO);
switch (result)
{
case IDYES: MessageBox (NULL, L" !!!",
L"", MB_OK| MB_ICONASTERISK); break;
case IDNO: MessageBox (NULL, L" !!!", L"",
MB_OK| MB_ICONSTOP); break;
}
return NULL;
}
:
:
MB_ABORTRETRYIGNORE : ABORT, RETRY, IGNORE
MB_CANCELTRYCONTINUE : CANCEL, TRY, CONTINUE
MB_HELP MB_OK MB_OKCANCEL 2 : OK, CANCEL
MB_RETRYCANCEL 2 : RETRY, CANCEL
MB_YESNO 2 : YES, NO
MB_YESNOCANCEL : YES, NO, CANCEL
:
MB_ICONSTOP ()
MB_ICONQUESTION ( )
MB_ICONEXCLAMATION
MB_ICONASTERISK ( )
MessageBox :
IDABORT ABORT
IDCANCEL . CANSEL
IDCONTINUE .. CONTINUE
IDIGNORE . IGNORE
IDNO . NO
IDOK . OK
IDRETRY . RETRY