Oddity
-
Postów
0 -
Dołączył
-
Ostatnio
Nigdy
Typ zawartości
Profile
Fora
Kalendarz
Articles
Pliki
Posty napisane przez Oddity
-
-
clever napisał:koles, jak nie umiesz sobie dodac zmiennej, to jestes d**a. Nie bede wklejal calego kodu, bo nie mam na to czasu. To miala byc IDEA, ale widocznie twoj mozg jest zbyt maly, by to zrozumiec.
Od redakcji
Każdy kiedyś zaczynał. A brak doświadczenia to nie powód, żeby kogoś obrażać. Radzimy opamiętać się na przyszłość -
-
-
-
Rzuc kodem :D
-
-
bool _ftoa (TCHAR *szStr, double d) { if (!szStr) return false ; gcvt (d, 15, szStr) ; if (szStr [lstrlen (szStr) - 1] == '.') szStr [lstrlen (szStr) - 1] = '\0' ; return true ; } float v ; TCHAR szV [32] ; _ftoa (szV, (double) v) ; wsprintf (buf, TEXT ("wynik = %s mag"), szV) ;
Spróbuj w ten sposób. Pozdrawiam.
-
Zwróc uwagę na ten fragment dokumentacji funkcji InitiateSystemShutdown:
RemarksTo shut down the local computer, the calling process must have the SE_SHUTDOWN_NAME privilege. To shut down a remote computer, the calling process must have the SE_REMOTE_SHUTDOWN_NAME privilege on the remote computer. By default, users can enable the SE_SHUTDOWN_NAME privilege on the computer they are logged onto, and administrators can enable the SE_REMOTE_SHUTDOWN_NAME privilege on remote computers.
Kiedyś pisałem podobny program dla szkolnej sieci (Win ME). Na każdym komputerze uruchomiona była mała aplikacja, z którą łączyło się z głównego komputera i wysyłało polecenie wyłączenia systemu.
Pozdrawiam
-
Pamięć wirtualna jest tworzona po to, aby nie doszło do sytuacji, gdy brakuje RAM-u. Czy Twój program znajdzie się w VM, czy w rzeczywistym RAM-ie, zależy od systemu i nie masz na to wpływu (oczywiście im mniejszy program, tym bardziej prawdopodobne, że znajdzie się w RAM). Z poziomu aplikacji nie ma żadnego rozróżnienia pomiędzy pamięcią fizyczną a wirtualną. Otrzymujesz wskaźniki wirtualne, które wskazują na pamięć wirtualną. Na wskaźniki rzeczywiste konwertuje je Windows.
A tak na marginesie, możliwość ingerencji przez program w pamięć ogólnodostępną w środowisku wielozadaniowym byłaby swoistą bombą zegarową. Wyobraź sobie zwykłe przepełnienie bufora, po którym w pamięci umieszczone są dane systemowe lub kernel. Mały błąd w programie i crash całego systemu? Tak, tak by to właśnie wyglądało.
Jeśli chodzi o alokowanie dużej ilości pamięci, to nie ma problemu. Jeśli chcesz, możesz sobie zaalokować 2GB, jeśli wystarczy Ci na to miejsca na dysku.
Na koniec powtórze jeszcze jedno: w programie nie rozróżniasz RAM/Virtual Memory. Nie możesz zadecydować, gdzie przechowywana będzie zmienna. Robi to za Ciebie system operacyjny (i całe szczęście). Wskaźnik to wskaźnik, jego dokładną wartością nie musisz się martwić. -
no i wylancza progsa, wlanczam 30 innych, i znow ten progs, ta sama pamiec jesli powininem przydzielic inna, kopiuje go 30 razy, walnczam kazda kopie wszedzie ta sama pamiec?? wiec pytam sie was o co tu chodzi z ta pamiecia?
Windows przydziela każdemu programowi wirtualną przestrzeń adresową. Każdy program działa w oddzielnym, prywatnym bloku pamięci, dlatego uruchamiając program po raz n-ty, dostajesz te same adresy.
Pozdrawiam
-
-
-
Wyrwane żywcem z dokumentacji:
The GetVersion function returns the current version number of Windows and information about the operating system platform.
This function has been superseded by GetVersionEx, which is the preferred method for obtaining system version number information. New applications should use GetVersionEx. The GetVersionEx function was developed because many existing Windows applications err when examining the DWORD return value of a GetVersion function call, transposing the major and minor version numbers packed into that DWORD. The GetVersionEx function forces applications to explicitly examine each element of version information, and allows for future enhancements to that information.
DWORD GetVersion(VOID)
Parameters
This function has no parameters.
Return Values
If the function succeeds, the return value is a DWORD value that contains the major and minor version numbers of Windows in the low order word, and information about the operating system platform in the high order word.
For all platforms, the low order word contains the version number of Windows. The low-order byte of this word specifies the major version number, in hexadecimal notation. The high-order byte specifies the minor version (revision) number, in hexadecimal notation.To distinguish between operating system platforms, use the high order bit and the low order byte, as shown in the following table:
Platform High order bit Low order byte (major version number)
Windows NT zero 3 or 4
Windows 95 1 4
Win32s with Windows 3.1 1 3For Windows NT and Win32s, the remaining bits in the high order word specify the build number.
For Windows 95 the remaining bits of the high order word are reserved.Remarks
This function does not return the current version number of MS-DOS.
The following code fragment illustrates how to extract information from the GetVersion return value:dwVersion = GetVersion();
// Get major and minor version numbers of Windows
dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
dwWindowsMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion)));// Get build numbers for Windows NT or Win32s
if (dwVersion < 0x80000000) // Windows NT
dwBuild = (DWORD)(HIWORD(dwVersion));
else if (dwWindowsMajorVersion < 4) // Win32s
dwBuild = (DWORD)(HIWORD(dwVersion) & ~0x8000);
else // Windows 95 -- No build numbers provideddwBuild = 0;
See Also
GetVersionEx
-
Subclassing
-
-
-
-
Jakby coś dalej nie działało, to zagadaj do mnie na gadu-gadu: 4338319 (przeważnie jestem niewidoczny).
Pozdrawiam
-
Poniżej znajduje się zaczerpnięty z dokumentacji opis funkcji LoadImage. Potrafi ona wczytywać bitmapy z pliku.
The LoadImage function loads an icon, cursor, or bitmap.
HANDLE LoadImage(
HINSTANCE hinst, // handle of the instance that contains the image
LPCTSTR lpszName, // name or identifier of image
UINT uType, // type of image
int cxDesired, // desired width
int cyDesired, // desired height
UINT fuLoad // load flags
);Parameters
hinst
Identifies an instance of the module that contains the image to be loaded. To load an OEM image, set this parameter to zero.
lpszName
Identifies the image to load.
If the hinst parameter is non-NULL and the fuLoad parameter does not include LR_LOADFROMFILE, lpszName is a pointer to a null-terminated string that contains the name of the image resource in the hinst module.
If hinst is NULL and LR_LOADFROMFILE is not specified, the low-order word of this parameter must be the identifier of the OEM image to load. The OEM image identifiers are defined in WINUSER.H and have the following prefixes:Prefix Meaning
OBM_ OEM bitmaps
OIC_ OEM icons
OCR_ OEM cursorsWindows 95: If the fuLoad parameter includes the LR_LOADFROMFILE value, lpszName is the name of the file that contains the image.
Windows NT: LR_LOADFROMFILE is not supported.uType
Specifies the type of image to be loaded. This parameter can be one of the following values:
Value Meaning
IMAGE_BITMAP Loads a bitmap.
IMAGE_CURSOR Loads a cursor.
IMAGE_ICON Loads an icon.cxDesired
Specifies the width, in pixels, of the icon or cursor. If this parameter is zero and the fuLoad parameter is LR_DEFAULTSIZE, the function uses the SM_CXICON or SM_CXCURSOR system metric value to set the width. If this parameter is zero and LR_DEFAULTSIZE is not used, the function uses the actual resource width.
cyDesired
Specifies the height, in pixels, of the icon or cursor. If this parameter is zero and the fuLoad parameter is LR_DEFAULTSIZE, the function uses the SM_CYICON or SM_CYCURSOR system metric value to set the height. If this parameter is zero and LR_DEFAULTSIZE is not used, the function uses the actual resource height.
fuLoad
Specifies a combination of the following values:
Value Meaning
LR_DEFAULTCOLOR The default flag; it does nothing. All it means is "not LR_MONOCHROME".
LR_CREATEDIBSECTION When the uType parameter specifies IMAGE_BITMAP, causes the function to return a DIB section bitmap rather than a compatible bitmap. This flag is useful for loading a bitmap without mapping it to the colors of the display device.
LR_DEFAULTSIZE Uses the width or height specified by the system metric values for cursors or icons, if the cxDesired or cyDesired values are set to zero. If this flag is not specified and cxDesired and cyDesired are set to zero, the function uses the actual resource size. If the resource contains multiple images, the function uses the size of the first image.
LR_LOADFROMFILE Loads the image from the file specified by the lpszName parameter. If this flag is not specified, lpszName is the name of the resource.
LR_LOADMAP3DCOLORS Searches the color table for the image and replaces the following shades of gray with the corresponding 3D color:Color Replaced with
Dk Gray, RGB(128,128,128) COLOR_3DSHADOW
Gray, RGB(192,192,192) COLOR_3DFACE
Lt Gray, RGB(223,223,223) COLOR_3DLIGHTLR_LOADTRANSPARENT Retrieves the color value of the first pixel in the image and replaces the corresponding entry in the color table with the default window color (COLOR_WINDOW). All pixels in the image that use that entry become the default window color. This value applies only to images that have corresponding color tables. If fuLoad includes both the LR_LOADTRANSPARENT and LR_LOADMAP3DCOLORS values, LRLOADTRANSPARENT takes precedence. However, the color table entry is replaced with COLOR_3DFACE rather than COLOR_WINDOW.
LR_MONOCHROME Loads the image in black and white.
LR_SHARED Shares the image handle if the image is loaded multiple times. If LR_SHARED is not set, a second call to LoadImage for the same resource will load the image again and return a different handle.Do not use LR_SHARED for images that have non-standard sizes, that may change after loading, or that are loaded from a file.Return Values
If the function succeeds, the return value is the handle of the newly loaded image.
If the function fails, the return value is NULL. -
Okno dialogowe wyświetla się przy użyciu jednej z tych funkcji:
1. Dla okna modalnego
DialogBox (hInstance, szTemplate, hwndParent, DlgProc) ;
2. Dla okna niemodalnego
CreateDialog, argumenty te same co w DialogBox
Argumenty:
hInstance - uchwyt realizacji programu (można go uzyskać poprzez skopiowanie do zmiennej globalnej pierwszego argumentu WinMain)
szTemplate - nazwa zasobu z oknem dialogowym, jeśli zamiast nazwy jest identyfikator liczbowy, należy wtedy użyć makra MAKEINTRESOURCE (identyfikator).
hwndParent - wskazuje na okno, które jest "rodzicem" okna dialogowego
DlgProc - adres procedury okna dialogowego
-
Korzystając z prawa programowania mojego autorstwa sądzę, błąd jest pewnie banalny. Czy aby na pewno kontrolka, której kliknięcie ma spowodować zapisanie tekstu, posiada identyfikator 106? Podczas obsługi WM_COMMAND i wartości 106 niższego słowa parametru wParam (czyli gdzieś w kodzie służącym do zapisu pliku), spróbuj wstawić taki kod:
MessageBox (hwnd, TEXT ("Wszystko jest OK"), TEXT ("Wiadomość"), MB_OK) ;
Skompiluj program i kliknij na kotrolkę służącą do zapisu tekstu. Jeśli nie wyświetli się okno dialogowe, to znaczy, że kod zapisu nie jest wogóle wykonywany. Upewnij się wtedy, czy 106 to prawidłowy identyfikator.
-
Wykorzystaj poniższą funkcję zamiast obiektu file. Pierwszym argumentem jest ścieżka pliku (np. "c:\\moje dokumenty\\plik.txt"). Pamiętaj, że gdy w C/C++ podajesz położenie plików, to musisz używać podwójnych ukośników \\. Inaczej kompilator potraktuje znak następujący bezpośrednio po slashu jako znak kontrolny ASCII.
Drugim parametrem funkcji jest wskażnik do bufora z tekstem. Gdy masz kontrolkę o identyfikatorze 100 i chcesz zapisać z niej dane do pliku c:\dane.dat, to piszesz:GetDlgItemText (hwnd, 100, szText, sizeof (szText) / sizeof (TCHAR)) ;
fileWriteFile (TEXT ("c:\\dane.dat"), szText) ;A oto i funkcja:
BOOL fileWriteFile (PTSTR pstrFileName, PTSTR pstrBuffer) { DWORD dwBytesWritten ; HANDLE hFile ; int iLength ; WORD wByteOrderMark = 0xFEFF ; SetCursor (LoadCursor (NULL, IDC_WAIT)) ; // Open the file, creating it if necessary if (INVALID_HANDLE_VALUE == (hFile = CreateFile (pstrFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL))) return FALSE ; iLength = lstrlen (pstrBuffer) ; ; if (!pstrBuffer) { CloseHandle (hFile) ; return FALSE ; } #ifdef UNICODE WriteFile (hFile, &wByteOrderMark, 2, &dwBytesWritten, NULL) ; #endif WriteFile (hFile, pstrBuffer, iLength * sizeof (TCHAR), &dwBytesWritten, NULL) ; if ((iLength * sizeof (TCHAR)) != (int) dwBytesWritten) { CloseHandle (hFile) ; SetCursor (LoadCursor (NULL, IDC_ARROW)) ; return FALSE ; } CloseHandle (hFile) ; SetCursor (LoadCursor (NULL, IDC_ARROW)) ; return TRUE ; }
Pozdrawiam Pinolca, żeby nie czuł się niepozdrowiony :P
-
-
urządzenie
w C
Przyznaję się bez bicia. Zielonego pojęcia nie mam :P
ini
w C
Napisano
Jest jeszcze jeden problem. Program po prostu nie znajduje pliku.
Podana jest ścieżka dostępu w formie c:\settings.ini. Ukośnik powoduje, że następna litera, w tym przypadku 's', traktowana jest jako znak kontrolny '\s'. Spróbuj dać: "c:\\settings.ini". Powinno działać.