|
My BMP image is mainly green in colour. I want to change to red but I can't get even Paint Shop Pro to do this simple operation!
If I wrote code to do it, I would simply swap values of each pixel's green and red values.
For example (50, 150, 50) would become (150, 50, 50). This would not affect white or black pixels.
Can anyone help?
|
|
|
|
|
To do it in windows code is easy.
1) If you only need to swap the values, and speed is not a problem, you could just select it into a Device Context and do something like this
ClrRef = GetPixel(x,y);
ClrRef = SwapRG(ClrRef); // user defined func.
SetPixel(x,y);
Saving it back to disk is where life gets difficult.
1) Read the articles at code project, and other sights to find out how.
*2) Read "Programming Windows" by Charles Petzold.
INTP
|
|
|
|
|
Actually this is related to my last post about gethostaddress. I got as a result of putting in my machine IP adress , the name of my pc.........MyPC, but there was no other identifying info about the network etc. The sample code I am using takes "ftp.microsoft.com", so my "MyPC" is obviously not enough for the GetFTPConnection and it fails.....
m_pFtpConnection = InternetSession.GetFtpConnection (name1 );
where I got name1 from my gethostbyaddr. So how shall I get around this? My goal is to download some files off an IP address. The machine with this IP address will be physically connected to the machine requesting the files (my application), but I cant hardcode the machine name, and have to use the ip address.
Thanks,
ns
|
|
|
|
|
I presume, you are missing some basics.
CFtpConnection* GetFtpConnection(
LPCTSTR pstrServer,
LPCTSTR pstrUserName = NULL,
LPCTSTR pstrPassword = NULL,
INTERNET_PORT nPort = INTERNET_INVALID_PORT_NUMBER,
BOOL bPassive = FALSE
);
Here you dont need to give the target machine's IP address, ftp server name is enough.
but there was no other identifying info about the network etc
I didn't get this point!!!
You dont need to use gethostbyaddr(...). just give the machine name as the first parameter, and thats it.
"A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
|
|
|
|
|
Problem is I dont have the server name ...just the IP address. THe gethostbyaddr gives me the server name except in this case its not adequate since it just gives me back "myMachine" with no other specifics............
Thanks,
ns
|
|
|
|
|
I almost got this program to work but i always get two or more errors. Please help me.
Run a program that will ask the user for two floating point numbers. The second number asked for should be the percentage the user wants to find of the first number. It should then display the result of finding the percentage in this format:
Example: Enter a number: 25
What percent of 25 would you like to find? 3
3% of 25 is 0.75
So far I got this:
#include "conio.h"
#include "stdio.h"
void main()
{
clrscr();
float number;
float number2;
float answer;
answer=number*number2/100;
printf("Enter a number");
scanf("%f",& number,number2);
printf("What percent of %f would you like to find?",number);
printf("%f% of %f is %f",number2,number,answer);
getch():
}
and by the way what is the best c++ compiler? i have turbo c++ now and how do you add computer voice to c++ programs? Thanks
|
|
|
|
|
You need to do the calculation after you've entered the numbers.
void main()
{
clrscr();
float number;
float number2;
float answer;
printf("Enter a number");
scanf("%f",& number);
printf("What percent of %f would you like to find?",number);
scanf("%f",& number2);
answer=number*number2/100;
printf("%f% of %f is %f",number2,number,answer);
getch():
}
Michael
'War is at best barbarism...Its glory is all moonshine. It is only those who have neither fired a shot nor heard the shrieks and groans of the wounded who cry aloud for blood, more vengeance, more desolation. War is hell.' - General William Sherman, 1879
|
|
|
|
|
colin21 wrote:
I almost got this program to work...
I don't see how. answer is being computed with two uninitialized variables, number and number2 . I suspect you'll not get the correct answer simply dividing by 100. In order for the math library to work correctly, it needs to know that floating-point numbers are being used. Therefore, divide by 100.0. scanf() only has only field, yet two variables are provided. Luckily, the second one is ignored. Had it been scanf("%f %f", &number); instead, you'd indeed have problems. There does, however, need to be another call to scanf() for number2 .
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
i get 6 errors when i do that expression syntax errors and undefined symbol errors
|
|
|
|
|
Please post the code that produces these errors, or if it's the same code you've already shown, please indicate the error and line number.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Colin, I have a feeling you are really hating programming right about now! I didn't test what I did, I just took your code and rearranged it so it made sense. I thought this might help.
#include "conio.h"
#include "stdio.h"
void main()
{
clrscr();
float number;
float number2;
float answer;
printf("Enter a number: ");
scanf("%f",&number );
printf("What percent of %f would you like to find? ", number);
scanf("%f",&number2 );
answer=number*(number2/100.0);
printf("%f% of %f is %f\n",number2,number,answer);
getch():
}
colin21 wrote:
by the way what is the best c++ compiler? i have turbo c++ now and how do you add computer voice to c++ programs?
Before I started using the Visual Studios I used the Bloodshed DevCpp. I think you can get it at www.bloodshed.net It uses the Gnu compiler, which is the same compiler at Linux systems, which most schools have...so if your programs compile in the DevCpp, it should compile for your professor.
About the computer voice. I think at your level perhaps you should forget about doing anything fun in your programs for quite a while, especially voice. If you want your program to make sounds, put \a in your output statements, it'll create a feeble sounding beep.
Good luck!
Douglas A. Wright
dawrigh3@kent.edu
|
|
|
|
|
I'm using windows sockets in an application. On both the client and server I use WSAEventSelect() to register the events I'm going to handle. My question is when do the FD_READ and FD_WRITE events get triggered in relation to send() and recv()? I'm confused. Any help is appreciated.
Thanks,
Melinda
|
|
|
|
|
See if either of these two links help:
http://tangentsoft.net/wskfaq/intermediate.html#asyncreliable
http://tangentsoft.net/wskfaq/newbie.html#wouldblock
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
I recommend Network Programming for Microsoft Windows, Second Edition
by Anthony Jones and Jim Ohmund.
Kuphryn
|
|
|
|
|
I tried with the microsoft IP address, and neither call to gethost.... is successful.......the longPtrHostEnt is 0, and result is 11004 error which means valid address but no data record found..........
try {
HOSTENT* lngPtrHostEnt ;
char* strHostName ;
unsigned long Addr = inet_addr("207.46.197.102");
lngPtrHostEnt = gethostbyaddr((char*)&Addr, 4, AF_INET);
int result = WSAGetLastError();
or
lngPtrHostEnt = gethostbyaddr("207.46.197.102", 4, AF_INET);
int result = WSAGetLastError();
Thanks,
ns
|
|
|
|
|
There's nothing wrong with your code, other than not checking the return value of inet_addr() . 11004 is a valid return value and means the host could not be found. To verify, try pinging that IP address from a command prompt.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Thanks. Didnt get there with ping. I got that number off the web.
I tried the code with my secondary machines IP address, and it indeed gives me a nonzero pointer to the hostent, but then it crashes at the copymemory where I am trying to get the name....
char* strHostName ;
so I did
CString name (lngPtrHostEnt->h_name);
which worked. But why did the copy mem fail?
Thanks,
ns
|
|
|
|
|
Because strHostName is a pointer that has not been assigned any memory. Try:
char *strHostName = new char[64];<br />
CopyMemory(...);
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Hi,
From My SDI application I want to use the File->Print to print a XML document that my program creates and using File->Print preview to show the preview. How do I do them? Please help.
Thanks.
|
|
|
|
|
|
I have an encryption routine using Crypto API. Everything in my code works fine as long as I don't save the encrypted value to an Oracle Database. The Oracle Database character set does not support some of the character in the character set that Crypto API uses to Encrypt.
Is there a way to change the character set that Crypto API uses or to convert it in C++? The character set that I need is ISO 8859-1 West European 8-bit character set.
Thanks!!
HckygirlOH
|
|
|
|
|
You can either save it to an Oracle BLOB field, which is proper for binary data, or, if you really need to write it to a (var)char2 field, you may encode it as a base64 string.
You can do it on anything you choose - from .bat to .net - A customer
|
|
|
|
|
Hi all,
I'm working on a project where I have a native (unmanaged) DLL that establishes itself as a filter for system-wide (global) mouse processing. The functional bit of code is this:
<br />
extern "C" __declspec(dllexport)<br />
HHOOK Hook(PFN_MOUSE_MOVE_CALLBACK callback)<br />
{<br />
if (!_hooked)<br />
{<br />
_hooked = true;<br />
_mouseMoveCallback = callback;<br />
_hhk = SetWindowsHookEx(WH_MOUSE, SystemMouseProc, _hinstance, 0);<br />
return _hhk;<br />
}<br />
else<br />
return (HHOOK)NULL;<br />
}<br />
The argument is intended to be used in the actual mouse processing as follows:
<br />
LRESULT CALLBACK SystemMouseProc (int code, WPARAM wparam, LPARAM lparam)<br />
{<br />
if (code >= 0)<br />
{<br />
MOUSEHOOKSTRUCT* mouse = (MOUSEHOOKSTRUCT*)lparam;<br />
<br />
if (_mouseMoveCallback != NULL)<br />
_mouseMoveCallback(mouse->pt.x, mouse->pt.y);<br />
<br />
}<br />
return CallNextHookEx(_hhk, code, wparam, lparam);<br />
}<br />
The problem I'm hitting is that because it's a global hook, this DLL is "injected" (to use Microsoft's verbiage) into each process after it's initially installed by my EXE (which happens to be managed code, though I don't think it affects anything). This makes sense and is in fact what I want, EXCEPT for the fact that I want my callback to work when the thread of execution changes.
When the implementation of SystemMouseProc is changed to just dump to a file, everything's great:
<br />
FILE* stream;<br />
if ((stream = fopen("c:\\hook.txt", "a+")) != NULL)<br />
{<br />
fprintf(stream, "x: %d, y: %d\n", mouse->pt.x, mouse->pt.y);<br />
fclose(stream);<br />
}<br />
Heaps of mouse coordinates.
I guess what I'm trying to do is get some shared chunk of memory between all "instances" (is that the right word?) of my DLL so that regardless of the current process it's running in, my desired callback function can always be called. Right now, if the mouse is over any other program than the original caller, _mouseMoveCallback != NULL evaluates to false and nothing happens.
I've considered falling back on the stream method and just connecting a network socket to localhost between the DLL and calling EXE, but that really didn't seem like the best way to go if it could be helped.
Here's all the code for the DLL. TIA if you can help!
-T
<br />
#include "stdafx.h"<br />
#include "stdio.h"
<br />
<br />
LRESULT CALLBACK SystemMouseProc (int code, WPARAM wparam, LPARAM lparam);<br />
<br />
<br />
typedef void (__stdcall* PFN_MOUSE_MOVE_CALLBACK)(int, int);<br />
<br />
<br />
HHOOK _hhk = 0;<br />
HINSTANCE _hinstance = 0;<br />
bool _hooked = false;<br />
PFN_MOUSE_MOVE_CALLBACK _mouseMoveCallback = NULL;<br />
<br />
<br />
BOOL APIENTRY DllMain (HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)<br />
{<br />
if (ul_reason_for_call == DLL_PROCESS_ATTACH)<br />
{<br />
if (_hinstance == 0)<br />
{<br />
_hinstance = (HINSTANCE)hModule;<br />
FILE* stream;<br />
if ((stream = fopen("c:\\hook.txt", "a+")) != NULL)<br />
{<br />
fprintf(stream, "Process Attached %d\n", (int)_hinstance);<br />
fclose(stream);<br />
}<br />
}<br />
}<br />
return TRUE;<br />
}<br />
<br />
extern "C" __declspec(dllexport)<br />
HHOOK Hook(PFN_MOUSE_MOVE_CALLBACK callback)<br />
{<br />
if (!_hooked)<br />
{<br />
_hooked = true;<br />
_mouseMoveCallback = callback;<br />
_hhk = SetWindowsHookEx(WH_MOUSE, SystemMouseProc, _hinstance, 0);<br />
return _hhk;<br />
}<br />
else<br />
return (HHOOK)NULL;<br />
}<br />
<br />
extern "C" __declspec(dllexport)<br />
void Unhook()<br />
{<br />
if (_hooked)<br />
UnhookWindowsHookEx(_hhk);<br />
<br />
return;<br />
}<br />
<br />
<br />
LRESULT CALLBACK SystemMouseProc (int code, WPARAM wparam, LPARAM lparam)<br />
{<br />
if (code >= 0)<br />
{<br />
MOUSEHOOKSTRUCT* mouse = (MOUSEHOOKSTRUCT*)lparam;<br />
<br />
if (_mouseMoveCallback != NULL)<br />
_mouseMoveCallback(mouse->pt.x, mouse->pt.y);<br />
<br />
}<br />
return CallNextHookEx(_hhk, code, wparam, lparam);<br />
}<br />
|
|
|
|
|
I'm working on a GUI program in Dev-C++, but I keep getting the following compiler errors:
246 music1b.cpp
C:\DEV-C_~1\Include\lvp\gui_bot.h: In function `int WinMain(HINSTANCE__ *, HINSTANCE__ *, CHAR *, int)':
474 c:\dev-c_~1\include\lvp\gui_bot.h
warning: converting NULL to non-pointer type
474 c:\dev-c_~1\include\lvp\gui_bot.h
warning: converting NULL to non-pointer type
(Line 246 is the bottom of the program where I include gui\bot.h)
Is is possible that there's something wrong with my gui_bot.h file? Do I need a fresh copy of it, or could the problem be with my code?
|
|
|
|
|
I don't see an actual error in the messages, just warnings (unless you have warnings set to be treated as errors). Are there no other messages?
- Mike
|
|
|
|
|