![]() |
|
השדח השיג - C/C++ | |
![]() |
|
ישאר דומע | םיניינע ןכות | סינוקא ןד תאמ |
![]() |
.ההז ןפואב טעמכ המצע לע תרזוח WinMain היצקנופהש םיאור ונא ,Windows תוינכות לע םילכתסמ ונחנאשכ אלש ידכב (Header file) תרתוכ ץבוקו (הנוכמ תפשל רדוהמ ץבוק) Obj ץבוק וזה היצקנופה רובע רוצינ ןכל .תונושה תוינכותב בושו בוש התוא םושרל ךרטצנ .windowsclass תקלחמ ןיבל וניב לבלבתהל ונל לא .win גוסמ הנבמ רידגנ ,C++-ב םיתנכתמ ונאש ןוויכמ :ךכ הארית השדחה תנוכתמב WinMain-ה תיצקנופ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { win w(hInstance, iCmdShow, "winapp", "winapp: First program with short WinMain-function"); return w.result(); } .win.h םשב תרתוכ ץבוקב רדגומ win הנבמה :ךכ רדגומ ץבוקה //win.h #define STRICT #include <windows.h> LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam); struct win { win (HINSTANCE hInstance0, int iCmdShow0, PSTR szAppName0, PSTR szWindowCaption0); int result (); int iCmdShow; //For passing through ShowWindow WNDCLASSEX wndclass; HWND hWnd, //Handle for mainwindow hDlg; //Handle for modeless dialogbox PSTR szAccel; //Name accelerator table //Arguments for CreateWindow: PSTR szAppName; //registered classname PSTR szWindowCaption; //address of windowname DWORD dwStyle; //windowstyle int x; //horizontal position of window int y; //vertical position of window int nWidth; //width int nHeight; //height HWND hWndParent; //parent-window HMENU hMenu; //menuhandle HINSTANCE hInstance; //application-instance LPVOID lpParam; //window-creation-data }; היצקנופ :תויצקנופ יתש ליכמ אוה ,ןכ ומכ .(הנבמל לדחמ תרירב) Public תואשרה םע קר םינתשמ ליכמ הז הנבמ :םירטמרפ 4 םיריבעמ ונא הנובה היצקנופל .result םשב היצקנופו הנוב .Winmain לש hWnd אוה ןושארה רטמרפה .(WinMain לש יעיברה רטמרפה אוהש) iCmdShow אוה ינשה רטמרפה .תכרעמב היצקילפאה לש ימינפה םשה אוה ישילשה רטמרפה .היצקילפאה לש ןולחה תרתוכ אוה יעיברה רטמרפה ,result-ל האירקה ןיבל ולש הנובה היצקנופל האירקהו הנבמה תרדגה ןיב .םירטמרפ תלבקמ הניא result היצקנופה :לשמל .(טסקטה ןמס גוס תא ומכ) הנבמב םינתשמה לש םהיכרע תא תונשל לכונ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { win w(hInstance, iCmdShow, "winapp", "winapp: First program with short WinMain-function"); w.wndclass.hCursor = LoadCursor(NULL, IDC_CROSS); return w.result(); } :תויצקנופה טוריפ לכ תא ליכמ win.cpp ץבוק .תורדגהה תא קר קיזחמ win.h ץבוק ,רומאכ // win.cpp: Implementation of the structure win; // After compiling, link with application-file #include "win.h" win::win(HINSTANCE hInstance0, int iCmdShow0, PSTR szAppName0, PSTR szWindowCaption0) { iCmdShow = iCmdShow0; //store the arguments for CreateWindow in the structure win: szAppName = szAppName0; szWindowCaption = szWindowCaption0; dwStyle = WS_OVERLAPPEDWINDOW; x = y = 0; nWidth = GetSystemMetrics(SM_CXSCREEN); nHeight = GetSystemMetrics(SM_CYSCREEN); hWndParent = NULL; hMenu = NULL; hInstance = hInstance0; lpParam = NULL; //Fill wndclass just for now: wndclass.cbSize = sizeof(wndclass); wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = szAppName; wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); hDlg=0; szAccel = NULL; } int win::result() { RegisterClassEx(&wndclass); hWnd = CreateWindow(szAppName, szWindowCaption, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam); ShowWindow(hWnd, iCmdShow); UpdateWindow(hWnd); MSG msg; HACCEL hAccel = (szAccel ? LoadAccelerators(hInstance, szAccel) : 0); while (GetMessage(&msg, NULL, 0, 0)) { if (hDlg == 0 || !IsDialogMessage(hDlg, &msg)) { if (hAccel == 0 || !TranslateAccelerator(hWnd, hAccel, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } } return msg.wParam; } ץבוקה תא רדהנ ,ןכל .םתוא ךורעל ילבמ ולא םיצבקב שמתשהל לכונ ךא ,בכרומ דאמ הארנ הז .רדוהמה ץבוקב שמתשנו דימתלו תחא win.cpp :ךכ השענ רודיהה :Borland C++ 5.0-ב bcc32 -c -W win .דבלב רודיהל איה -c היצפואה .Windows-ב שומישל ץבוק הזש רלייפמוקל רמול איה -w היצפואה :Microsoft Visual C++ 5.0-ב cl /c win.cpp .win.obj םשב ץבוק רצונ תעכ |