In Windows, you can do it using the WIN32API function SetForegroundWindow().
Patcher32
Posts
-
How to get application focus? -
How to run an app in admin mode in Vista and 7No. Adding manifest is not the solution. I think its the process properties that one should look into.
-
Windows 4, 5 and 6?Version 3 = Windows 3.1, Windows NT 3.0, Windows NT 3.5 Version 4 = Windows NT 4.0, Windows 95/98/98SE/Me Version 5 = Windows 2000, XP, 2003 Version 6 = Windows Vista, Windows 7, Windows 2008 Windows Vista was version 6.0 and Windows 7 is actually version 6.1 So there is no 7.0 yet.
-
How to run an app in admin mode in Vista and 7I have seen some applications warn that you have to run it in admin mode, if you do not run it in admin mode in both Windows Vista and 7. How do they detect if it is running with admin privileges or not. Some application even invoke the UAC (user access control) dialog to pop up, as soon as they run. Please someone enlighten me about this.
-
problem in printing factorial.............#include < stdio.h >
void main()
{
int counter,fact=1,num=5;
counter = num;
clrscr();
while(counter > 0)
{
fact = fact * counter;
counter--;
}
printf("fact of %d is: %d",num,fact);getch();
}
-
Programmatically deleting old files with a C programSince your program creates log files names based on date and time, you can parse file names for the time when they were created. That would be better method, than finding the file's last write time.
-
The SHCreateDirectoryEx function.#include <shlobj.h>
int main(){
SHCreateDirectoryEx(NULL,"c:\\jinx",NULL);
return 0;
}tested it with ms vc++ 2008. it works like charm :)
-
DeviceIoControl to lock drive is not workingIf I lock with
(BYTE)TRUE
: works If I unlock a locked device using(BYTE)FALSE
: works If I try to unlock a device (without locking it first) using(BYTE)FALSE
: gives error #22, The device does not recognize command I think this is expected behavior. Please guide me in right direction if I am doing it wrong. -
DeviceIoControl to lock drive is not workingOkay I finally got it to work. YAY! :) :) :) I made this change :
pmr.PreventMediaRemoval = (BYTE)TRUE;
in the original code I posted. But MSDN says thePreventMediaRemoval
member isBOOLEAN
? Thanks for confusing me MSDN! :mad::mad: The value has to beBYTE
. So setting it to 1 locks drive from being ejected. Setting it to 0 unlocks the drive from ejecting. -
DeviceIoControl to lock drive is not workingYes my DVD drive is F:. and handle returned by CreateFile is valid too. Thanks for replying
-
DeviceIoControl to lock drive is not workingYes hVolume is right value. GetLastError returns 0. GENERIC_READ already has FILE_READ_ATTRIBUTES Tried using 0 for File sharing but still DeviceIoControl gives error 87 parameter not correct Thanks for replying, I appreciate it.
-
DeviceIoControl to lock drive is not workingOkay I am trying to lock CD drive (F: here) with the code shown. But DeviceIoControl is returning "error 87: Parameter not correct". Please someone help me. I cannot find out which parameter is incorrcet.
#include <windows.h>
#include <winioctl.h>
#include <stdio.h>void ShowError(void); //function to display message from GetLastError()
int main(){
char szVolume[] = "\\\\.\\F:";
HANDLE hVolume;
DWORD dwBytes = 0;
PREVENT_MEDIA_REMOVAL pmr;pmr.PreventMediaRemoval = TRUE; hVolume = CreateFile(szVolume,GENERIC\_READ|GENERIC\_WRITE,FILE\_SHARE\_READ|FILE\_SHARE\_WRITE,NULL,OPEN\_EXISTING,0,NULL); if(hVolume==INVALID\_HANDLE\_VALUE){ ShowError(); exit(1); } if(DeviceIoControl(hVolume,IOCTL\_STORAGE\_EJECTION\_CONTROL,(LPVOID)&pmr,(DWORD)sizeof(pmr),NULL,0,&dwBytes,NULL)==FALSE){ ShowError(); } CloseHandle(hVolume); return 0;
}
-
SetWindowsHookEx to modify GetSaveFileNameI want to modify MSPaint's Save file dialog's default file type to JPG using
SetWindowsHookEx
In the hook function what message should I look for to get atGetSaveFileName
? -
question about copy a picture with c [modified]wb
= open new binary file for writing, if file exists with same name, it will be truncated to 0 bytesab
= open new binary file for writing, if file exists with same name, new data would be written at end of file. This may lead to undesired results if file already exists. you should check if a file exists before opening it inwb
mode :#include<stdlib.h>
#include<stdio.h>
#define MAX 1024int main(int argc,int **argv){
FILE \*fsource,\*fdest; size\_t in; int buf\[MAX\]; char c = 'n'; fsource = fopen("F:\\\\a.jpg.rar","rb"); //-----------Check if file exists--------- fdest = fopen("D:\\\\a.jpg","r"); if(fdest!=NULL){ fclose(fdest); printf("Destination file already exists, do you want to overwrite?\\t"); scanf("%c",&c); if(c!='Y' && c!='y'){ fclose(fSource); return 1; } } //--------------------------------------- fdest = fopen("D:\\\\a.jpg","wb"); if(fsource == NULL || fdest == NULL) perror("open error"); while((in = fread(buf,sizeof(int),MAX,fsource)) != 0){ fwrite(buf,sizeof(int),in,fdest); fflush(fdest); } fclose(fsource); fclose(fdest); return EXIT\_SUCCESS;
}
-
How to convert real to binaryIs it -16.735 or -16,735? -16.735 = -10000.1011110000101000111101011100001010001111010111 -16,735 = -100000101011111 The general procedure is to do integer and fraction part separately. For integer part N : 1. If N is not zero, divide N by 2 2. If remainder is 1 write down 1, if its 0 write down 0 3. N = N/2 - remainder. Go back to Step 1. Finally, write the 0 and 1 in reverse order. Example, N = 40 1. 40/2 = 20. Remainder = 0. Write 0 2. 20/2 = 10. Remainder = 0. Write 0 3. 10/2 = 5. Remainder = 0. Write 0 4. 5/2 = 2 + 1/2. Remainder = 1/2. Write 1 5. 2/2 = 1. Remainder = 0. Write 0 6. 1/2 = 0 + 1/2. Remainder = 1/2. Write 1 Threfore, 40 = 101000 For fraction part F, 1. If F is not zero, Multiply F by 2. 2. If result is greater than or equal to 1, write down 1. F = (F * 2) - 1 3. If result is not greater than 1, write down 1. F = (F * 2) 4. If F > 0 go back to step 1. Example, F = 0.25 1. 0.25 * 2 = 0.5. Write down 0 2. 0.5 * 2 = 1. Write down 1 Thus 0.25 = 0.01
-
Using GetOpenFileName on both Win98 and WinXPYes. Its line # 34 in main.c When I remove
if
statement and just setlStructSize
to one of the values, the code compiles perfectly. -
Using GetOpenFileName on both Win98 and WinXPThis is what Pelles C Compiler displays : Building MAIN.obj. C:\Code\Hasher\MAIN.C(34): fatal error: Internal error: get_rule(). *** Error code: 1 *** Done.
-
calculation errorNone of the values have been initialized and it always causes problem as the programs works on a random garbage value. 1.
endbal
is not initialized. Either set it to 0 or some other positive value at the start of your program. 2.finbal
must be set to 0 at the start of main() function. You can initialize these at the time of declaration :float endbal = 0, finbal = 0;
Also the statementfinbal = endbal + outdep - withdraw;
is wrong. You have already added deposit amount and subtracted withdrawn amount in the variablefinbal
. So all you need isendbal = endbal + finbal
. Finally, you are displaying the wrong value. You should displayendbal
in the lastprintf
statement. I hope this helps you.modified on Wednesday, October 14, 2009 6:59 PM
-
Using GetOpenFileName on both Win98 and WinXPGetOpenFileName() is Win32 API function which accepts a pointer to a OPENFILENAME structure. In this structure, you have to set up a member lStructSize to sizeof(OPENFILENAME) for Windows XP and above. But for Windows98 it must be OPENFILENAME_SIZE_VERSION_400. When I use an if statement to do it, compiler gives fatal error and stops :
OPENFILENAME ofn;
if(win98()==FALSE)
ofn.lStructSize = sizeof(OPENFILENAME); //for Windows XP
else
ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; //for Windows 98/MEOfcourse I can make seperate functions for opening files in win98 etc. But what is a better way to do this. Thank you
-
When to execute hashing function in Win32 appThank you and others who took time to respond. Its working now :-)