flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
revolution 21 Jan 2010, 05:24
Just use CreateFile with the CREATE_NEW flag set. You get and error indicating if the file already exists. Then just increment your number and try again.
|
|||
![]() |
|
bitshifter 21 Jan 2010, 05:48
Hi Dex, this demo show basics of Win32 file handling...
http://board.flatassembler.net/download.php?id=4624 |
|||
![]() |
|
sinsi 21 Jan 2010, 06:09
If you don't care what it is called you could try GetTempFileName.
You could also try wsprintf using 'shot%u' and a 4 digit number you track, modifying the %u (sorry. too lazy to look up leading zeros) Another is to increment the last char of the name from '0' to '9', roll it over into the previous char and so on. |
|||
![]() |
|
Dex4u 22 Jan 2010, 18:13
Thanks everyone, it was very easy in the end.
|
|||
![]() |
|
Dex4u 24 Jan 2010, 21:08
As a side note to this topic, the app i made was a screenshot app, that hooked into a keypress and took a full screenshot and also played a camera clicking sound.
Saving each image as shot??.bmp ?? being a number, increasing each shot. It works fine in XP, but under windows7 it would only take 6 shots before not working. The problem seems to be in the key hook, its seem windows only lets 6 key hooks per app, it maybe a security thing ?. |
|||
![]() |
|
bitshifter 24 Jan 2010, 23:13
I wrote the same thing a while back
but instead of hooking the keyboard i sent input event and copied it via clipboard. If you would like to C my code just ask... |
|||
![]() |
|
f0dder 25 Jan 2010, 00:59
Dex4u wrote: The problem seems to be in the key hook, its seem windows only lets 6 key hooks per app, it maybe a security thing ?. Other apps have no problems hotkey-triggering under Win7 (I use several ![]() revolution wrote: Just use CreateFile with the CREATE_NEW flag set. You get and error indicating if the file already exists. Then just increment your number and try again. _________________ ![]() |
|||
![]() |
|
Dex4u 25 Jan 2010, 06:15
Thanks bitshifter, i would like to see your code.
f0dder, I use F9, the hook is a background hook so the program need no focus. It works normal until and takes screenshots on pressing the F9 key, but once you have pressd the key 6 times, it does not take any more shots until you close the screen shot app and re-open it. When you say other win7 work OK, thats maybe because they use the .net. Do you know of a asm example of a keyhook, that works more than 6 in the background, ?. |
|||
![]() |
|
sinsi 25 Jan 2010, 06:36
>Thanks everyone, it was very easy in the end
So tell us (me) how you did it? As for your problem, post some code - I have win7 |
|||
![]() |
|
f0dder 25 Jan 2010, 07:10
Dex4u wrote: f0dder, I use F9, the hook is a background hook so the program need no focus. Dex4u wrote: It works normal until and takes screenshots on pressing the F9 key, but once you have pressd the key 6 times, it does not take any more shots until you close the screen shot app and re-open it. Dex4u wrote: When you say other win7 work OK, thats maybe because they use the .net. _________________ ![]() |
|||
![]() |
|
bitshifter 25 Jan 2010, 09:04
Ok, here is my code for taking screenshot...
Code: #include <windows.h> #include <stdio.h> void TakeScreenShot(LPCSTR); int main(int argc, char **argv) { TakeScreenShot("ScreenShot.bmp"); return 0; } void TakeScreenShot(LPCSTR lpszFileName) { keybd_event(VK_SNAPSHOT, 0x45, KEYEVENTF_EXTENDEDKEY, 0); keybd_event(VK_SNAPSHOT, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); OpenClipboard(NULL); HBITMAP h = (HBITMAP)GetClipboardData(CF_BITMAP); CloseClipboard(); BITMAPINFO bmpInfo; ZeroMemory(&bmpInfo, sizeof(BITMAPINFO)); bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); HDC hdc = GetDC(NULL); GetDIBits(hdc, h, 0, 0, NULL, &bmpInfo, DIB_RGB_COLORS); if(bmpInfo.bmiHeader.biSizeImage <= 0) { bmpInfo.bmiHeader.biSizeImage = bmpInfo.bmiHeader.biWidth * abs(bmpInfo.bmiHeader.biHeight) * (bmpInfo.bmiHeader.biBitCount + 7) / 8; } LPVOID pBuf = malloc(bmpInfo.bmiHeader.biSizeImage); bmpInfo.bmiHeader.biCompression = BI_RGB; GetDIBits(hdc, h, 0, bmpInfo.bmiHeader.biHeight, pBuf, &bmpInfo, DIB_RGB_COLORS); BITMAPFILEHEADER bmpFileHeader; bmpFileHeader.bfReserved1 = 0; bmpFileHeader.bfReserved2 = 0; bmpFileHeader.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + bmpInfo.bmiHeader.biSizeImage; bmpFileHeader.bfType = 0x4D42; // BM (little endian = MB) bmpFileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); FILE* fp = fopen(lpszFileName, "wb"); fwrite(&bmpFileHeader, sizeof(BITMAPFILEHEADER), 1, fp); fwrite(&bmpInfo.bmiHeader, sizeof(BITMAPINFOHEADER), 1, fp); fwrite(pBuf, bmpInfo.bmiHeader.biSizeImage, 1, fp); ReleaseDC(NULL, hdc); free(pBuf); fclose(fp); } Enjoy ![]() _________________ Coding a 3D game engine with fasm is like trying to eat an elephant, you just have to keep focused and take it one 'byte' at a time. |
|||
![]() |
|
score_under 26 Jan 2010, 12:07
@Bitshifter: that was horrible. (relying on windows to send it to the clipboard then retreiving from the clipboard)
I believe there's some method that involves opening the desktop window's DC and collecting the image from there. |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.