January 14, 2015, 1:12 pm
Please take a look the code below, its not the complete thing obviously since that'd be too long.
Essentially the problem is that when I click the mouse, the program doesn't seem to record the coordinates. So the if statements are never executed.
One thing I noticed was that when the do while loop is running and the left mouse button is not pressed then X and Y of dwMousePosition are both 0. But then if I press the left mouse button then the coordinates become x = 1 and y = 0.
Any help is appreciated
NOTE Im on Windows 7, 64 bit, using Visual Studio Express 2013 for Windows Desktop
Code:
#include <iostream>
#include <windows.h>
#include <string>
#include <new>
#include <stdio.h>
using namespace std;
INPUT_RECORD ir[128];
DWORD nRead;
COORD pos;
UINT z;
POINTER_INFO pointerInfo = {};
POINT p;
HANDLE hStdInput = GetStdHandle(STD_INPUT_HANDLE);
HANDLE hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
HANDLE handles[2] = { hEvent, hStdInput };
FlushConsoleInputBuffer(hStdInput);
do
{
Sleep(1);
if (!wait_for_up)
{
if ((GetKeyState(VK_LBUTTON) & 0x100) != 0)
{
ReadConsoleInput(hStdInput, ir, 128, &nRead);
pos.X = 0, pos.Y = 0;
SetConsoleCursorPosition(hStdOutput, pos);
if (*login == false)
{
if ((ir[z].Event.MouseEvent.dwMousePosition.Y) == 0)
{
*choice = 1;
finished = true;
}
if ((ir[z].Event.MouseEvent.dwMousePosition.Y) == 4)
{
*choice = 2;
finished = true;
}
}
}
}
} while (!finished);
cout << *choice;
↧
January 14, 2015, 2:05 pm
This is a typical way to create a window,
Code:
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
// Step 2: Creating the Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"The title of my window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
NULL, NULL, hInstance, NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
// Step 3: The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
At the end, we always call GetMessage to handle the windows message. It is noted that there is a while loop which means unless we close the window, the program won't proceed. I wonder if there is any way to display the window and at the mean time, the program executes the code after while loop? I know multithreaded programming can be an option. Is there any other way than multithreaded programming to achieve that? Thanks.
↧
↧
January 16, 2015, 3:21 am
I get a task: to color the control scrollbar (a gridctrl scrollbar, whatever). In the first attempting I didn't succeded ... So, I started to trying coloring a CListBox scrollbar ... I developed a derived CListBox where I override OnCtlColor:
Code:
HBRUSH CMyListBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CListBox::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
if(CTLCOLOR_STATIC == nCtlColor)
{
pDC->SetTextColor(RGB(200, 34, 0));
pDC->SetBkColor(RGB(250, 230, 200));
return m_Brush;
}
return hbr;
}
not working ...
I override CTestDlg::OnCtlColor:
Code:
HBRUSH CTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
// if(CTLCOLOR_SCROLLBAR == nCtlColor)
{
pDC->SetTextColor(RGB(200, 34, 0));
pDC->SetBkColor(RGB(250, 230, 200));
return m_Brush;
}
return hbr;
}
I colored everything, except scrollbars :)) ... I attached the app demo ...
I already tried this solution:
http://www.codeproject.com/Articles/...r-with-a-custo
but in my case, didn't worked ...
My question is, how can I color the control scrollbar ? It is possible ? If yes, how ?
I'll appreciate any hint, link, etc.
Thank you.
↧
January 17, 2015, 2:26 am
This is a question about ole32.dll (and .lib) although it could equally apply to other MS libraries with "32" in their name...
I want my app to call
CoCreateInstance() which (according to that MSDN article) is located in ole32.dll
So what happens if I decide to build a 64-bit version of my app?? I took a quick look around a 64-bit system - but there was no DLL called ole64.dll as far as I could see. Is there a 64-bit version of that DLL (but still called ole32.dll) :confused:
↧
January 17, 2015, 10:13 am
I would like to write a program Chat Room similar to yahoo chat rooms or cheetah chat room :D Nothing quite as big maybe 5 chat rooms with avatar's.
Any tutorials and beginner code programs ?
Anything will help me get started thank's
John
↧
↧
January 19, 2015, 6:18 am
Hi,
The question says:
Make an "analog clock" that is, a clock with hands that move. You get the time of day from the operating system through a library call. A major part of this exercise is to find the functions that give you the time of day and a way of waiting for a short period of time (e.g., a second for a clock tick) and to learn to use them based on the documentation you found. Hint: clock(), sleep().
OK, I wrote below code. It is in its primary stages and has not been completed yet.
Code:
#include <GUI.h>
#include <time.h>
#include <iostream>
using namespace Graph_lib;
//---------------------------------
class Dynamic_clock : public Window {
public:
Dynamic_clock(Point p, int w, int h, const string& title):
Window(p, w, h, title),
quit_button(Point(x_max()-90,20), 60, 20, "Quit", cb_quit),
l1(Point (p.x+100,p.y), Point(p.x+120,p.y)),
l2(Point (p.x-100,p.y), Point(p.x-120,p.y)),
l3(Point (p.x,p.y-100), Point(p.x,p.y-120)),
l4(Point (p.x,p.y+100), Point(p.x,p.y+120)),
hour1(Point(300,250), Point(300,155)),
hour2(Point(300,250), Point(310,165)),
c(Point(p), 120) {
attach(c);
attach(l1);
attach(l2);
attach(l3);
attach(l4);
attach(quit_button);
clock_hands();
}
private:
Button quit_button;
Circle c;
Line l1, l2, l3, l4, hour1, hour2;
double h, m, s;
void quit() { hide(); }
void clock_hands() {
get_current_time();
hour1.set_style(Graph_lib::Line_style(Graph_lib::Line_style::solid, 3));
attach(hour1);
Sleep(1000);
detach(hour1);
attach(hour2);
}
void get_current_time() {
time_t t = time(0);
t -= 1421526600;
double h = t/3600;
t -= h*3600;
double m = t/60;
t -= m*60;
double s = t;
}
static void cb_quit(Address, Address pw) {reference_to<Dynamic_clock>(pw).quit();}
};
//------------------
int main() {
Dynamic_clock dc(Point(300,250), 800, 600, "Dynamic_clock");
return gui_main();
}
Now what is the problem?
I expect the system in
void clock_hands() (line 38) attaches
hour1 (line 41) then waits for 1000 ms (using
Sleep(1000)) then detaches
hour1 and attaches
hour2 this time. But it doesn't occur in practice. When the system reaches
Sleep(1000); it seems to go into a comma! It doesn't show the
hour1 so seeing the movement of clock ticks by the clock's hands will not be possible.
Any idea please?
Regardless of my code, how you would solve the problem if you were me?
The problem is an exercise. #6 of here:
http://books.google.com/books?id=We2...epage&q&f=true
↧
January 20, 2015, 4:47 am
Good Day,
I am developing a small home cockpit (as a hobbyist and not as professional) with Microsoft Flight Simulator and the Aerosoft Airbus X. I use a VB.NET app and FSUIPC to connect my hardware to the sim.
Unfortunately this addon is not supported by the FSUIPC so I had to find another way to get the lvars. I have find a sample code which act as a gauge (dll) and it is written in C++. I have successfully managed to add new variables to the sample code and had the idea to make them accessible from my VB app. Since I am not familiar with C++, I goggled a lot to figure out do it but I have limited success.
When I added the following code to the dll, I can call it (from VB) without problem (as a test).
Code:
extern "C" __declspec(dllexport) int addFunc(int a, int b){
return (a + b);
}
But if I try the code below, I just get "0"
Code:
extern "C" __declspec(dllexport) double getLVar(int c){
ND=currentLVARs.NDMode;
return ND;
}
As I understand the code the lvars are stored in the currentLVARs structure
Code:
struct structLVARs
{
double FMAThrottleMode;
double NDMode;
double NDRange;
double FDstat;
//....
//....
//....
};
//internel structure to hold all LVAR values
structLVARs currentLVARs;
I have no idea how to reach those variables.
I have attached the cpp file as well.
I hope you can help me out and thanks in advance.
elektroby
p.s. I am not a native speaker so please forgive me my English
↧
January 21, 2015, 2:08 am
↧
January 21, 2015, 5:05 am
Hi,
I'm new to Visual Studio and have been tasked with taking over someone else's C++ code. The Win32 application in question has several complicated dialogs open simultaneously. What is the best way to determine which dialog window is on top, i.e. the window that has been clicked on (anywhere in the window) most recently? Example code would be very helpful. Thanks in advance, cheers!
Tim
↧
↧
January 21, 2015, 8:21 pm
Hi All,
I have created a SDI application. It have a horizontal splitter in middle for getting two views.
There is one dialog is attached to the lower view for adding few controls like static control, edit box, combo box etc.
My Lower view class is inherited from CFormView class.
As I move the splitter downwards, automatically the vertical scrollBar appears.
I want to create my custom scroll bar instead of that MFC ScrollBar.
So I have two questions to ask:
1. How can I stop this appearance of this default scrollBar on moving of splitter?
2. How can I add my custom ScrollBar to my view.
Please guide.
Thanks in Advance,
Mayank
↧
January 22, 2015, 12:41 pm
I'm using TutorialsPoint C++ examples to figure some things out, and though I've figured out what I can, I cannot tell why my output isn't going the way I want with the setw() "method"?
As you can see in the code I've c/p'ed, I'm trying to get the Book info to align with the first line of information after "Book 1:"
I've kept the Book 2 section of the output as is in case I want to start over, never mind it.
MY question is, the setw() only responds after I put in a high enough value. For the first setw() value it wouldn't begin moving "Book1.author" until the value was 11 or higher. The second setw() value didn't begin moving "Book1.subject" until the value was 28 or higher, but as you can see, "Book1.book_id" responded properly to setw(15). It didn't follow a trend that I can see, so I'm at a loss as to where it is getting it's marching orders outside of my setw() values.
Also, thanks for any help. I'm positive my lingo is off, please forgive me. As I progress, the questions will be worded with the proper terminology.
Code:
#include "stdafx.h"
#include <iostream>
#include <cstring>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;
using std::setw;
struct Books
{
char title[50];
char author[50];
char subject[200];
int book_id;
};
int main( )
{
struct Books Book1; // Declare Book1 of type Book
struct Books Book2; // Declare Book2 of type Book
// book 1 specification
strcpy( Book1.title, "Learn C++ Programming");
strcpy( Book1.author, "Chand Miyan");
strcpy( Book1.subject, "a huge ****ing subject line");
Book1.book_id = 6495407;
// book 2 specification
strcpy( Book2.title, "Telecom Billing");
strcpy( Book2.author, "Yakit Singha");
strcpy( Book2.subject, "Telecom");
Book2.book_id = 6495700;
// Print Book1 info
cout << "Book 1: " << Book1.title << endl;
cout << setw(19) << Book1.author << endl;
cout << setw(45) << Book1.subject << endl;
cout << setw(15) << Book1.book_id << endl;
// Print Book2 info
cout << "Book 2 title : " << Book2.title << endl;
cout << "Book 2 author : " << Book2.author << endl;
cout << "Book 2 subject : " << Book2.subject << endl;
cout << "Book 2 id : " << Book2.book_id << endl;
return 0;
}
Thanks
↧
January 23, 2015, 6:19 am
Hi,
I am trying to draw a rubber band rectangle. I have got a following code from a site but its giving an error:
Code:
class CSampleView: Public CView
{
...
public:
CrectTracker m_tracker;//Changed to CRectTracker
...
};
Secondly, in the constructor to initialize the object CRectTracker document class:
CSampleDoc :: CSampleDOC ()
{
// Initialize tracker position, size and style.
m_tracker.m_rect.SetRect (0, 0, 10, 10);
m_tracker.m_nStyle = CRectTracker :: resizeInside |
CRectTracker :: dottedLine;
}
The error is:
Code:
error C2065: 'm_tracker' : undeclared identifier
Can some body please guide me how to get rid of this error??
Zulfi.
↧
January 23, 2015, 12:08 pm
Good evening,
Please help. This code doesnt send parameters to mysql database vis WININET post, i see it send empty fields, what exactly could be the problem
my code goes thus
Code:
#include <stdio.h>
#include <windows.h>
#include <string.h>
#include <Wininet.h>
#define PAGE_NAME "gate.php"
#pragma comment (lib, "wininet")
void compName()
{
LPCSTR compName = getenv("COMPUTERNAME");
printf("Computer name is : %s\n",compName);
}
void userName()
{
LPCSTR userName = getenv("USERNAME");
printf("UserName is : %s\n",userName);
}
void hWid()
{
HW_PROFILE_INFO hwProfileInfo;
if(GetCurrentHwProfile(&hwProfileInfo))
{
LPCSTR hWid = hwProfileInfo.szHwProfileGuid;
printf("HWID: %s\n",hWid);
}
}
void ip()
{
HINTERNET hInternet , hFile;
DWORD rSize;
char ip[50];
hInternet = InternetOpen(NULL,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
hFile = InternetOpenUrlA(hInternet,"http://housenaija.com/ip/ip.php",NULL,0,INTERNET_FLAG_RELOAD,0);
InternetReadFile(hFile,&ip,sizeof(ip),&rSize);
ip[rSize] ='\0';
InternetCloseHandle(hFile);
InternetCloseHandle(hInternet);
printf("IP adress : %s \n",ip);
}
void sendPCInfo()
{
char hWid[50];
char compName[50];
char userName[50];
char ip[50];
static TCHAR hdrs[] = TEXT("Content-Type: application/x-www-form-urlencoded");
static TCHAR accept[] = "Accept: */*";
LoadLibraryA("wininet.dll");
// trying to do a concatenation for gate.php?hWid=&compName=&userName=&ip= to save string to Database
char* data = (char*)VirtualAlloc(NULL, 4096, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
strcpy(data,PAGE_NAME);
lstrcat(data,PAGE_NAME);
lstrcat(data,"?&hWid=%s");
lstrcat(data,hWid);
lstrcat(data,"&compName=%s");
lstrcat(data,(const char*)&compName);
lstrcat(data,"&userName=%s");
lstrcat(data,(const char*)&userName);
lstrcat(data,"&ip=%s");
lstrcat(data,(const char*)&ip);
//HINTERNET hSession;
//HINTERNET hConnect;
//HINTERNET hRequest;
HINTERNET hSession = InternetOpen("Soldier",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
HINTERNET hConnect = InternetConnect(hSession,"localhost",80,NULL,NULL,INTERNET_SERVICE_HTTP ,0,1);
HINTERNET hRequest = HttpOpenRequest(hConnect,"POST","/pcinfo/gate2.php",NULL,NULL,(const char**)"text/*",0,1);
HttpSendRequestA(hRequest,"Content-Type: app1ication/x-www-form-urlencoded",strlen("Content-Type: app1ication/x-www-form-urlencoded"),data,strlen(data));;
InternetCloseHandle(hRequest);
InternetCloseHandle(hConnect);
InternetCloseHandle(hSession);
MessageBox(NULL,"PC Information Sent Successfully","Sent Info",MB_ICONINFORMATION | MB_OK);
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
compName();
userName();
hWid();
ip();
sendPCInfo();
system("pause");
}
Now my php looks like this
Code:
<?php
$hwid = $_POST['hWid'];
$compName = $_POST['compName'];
$userName = $_POST['userName'];
$ip = $_POST['ip'];
$msg = "$hwid + $compName + $userName + $ip";
$file = fopen("test.txt","w");
fwrite($file,$msg);
fclose($file);
?>
↧
↧
January 23, 2015, 2:00 pm
Hi,
I'm working on a improving my C++ skills and am trying program with C++ 11 using iterators.
So heres my code:
Inputs - grid is ["---", "-m-","p--"] tgt = p
Aim is to return the coodinates of p from the grid the answer is 0,2 as grid is indexed using Matrix Convention
Code:
pair<int, int> getCoordinates(vector<string> grid, string tgt)
{
// First step is creating an interator for grid
vector<string>::iterator it;
// finding the correct element using find
it = find(grid.begin(), grid.end(), tgt);
pair<int, int> res = make_pair(0, 0);
// getting the index using distance - so far we have the y coordinate, 2
res.second = distance(grid.begin(), it);
// Now as i understand it *it is pointing to a string object,
// specfically "p--" the last element in my vector<string> grid
// So here im trying to us *it-> to point to the string objects member interator begin
// Then using the same technique i used above to find "p" in "p--"
string::iterator it2 = find(*it->begin(), *it->end(), tgt); // <-- This is the line i get a complier error from
res.first = distance(*it->begin(), it2);
cout << "x = " << res.first << " y = " << res.second << endl;
return res;
}
However, doing this throws the following error:
error C2440: 'initializing' : cannot convert from 'char' to 'std::_String_iterator<std::_String_val<std::_Simple_types<char>>>'
At this time I've been able to workout why its talking about a char at all.
I think *it must be pointing to a char object instead of a string object but have no idea why if that is the case
Any advice on what im doing wrong?
Thanks
↧
January 23, 2015, 6:19 am
Hi,
I am trying to draw a rubber band rectangle. I have got a following code from a site but its giving an error:
Code:
class CSampleView: Public CView
{
...
public:
CrectTracker m_tracker;//Changed to CRectTracker
...
};
Secondly, in the constructor to initialize the object CRectTracker document class:
CSampleDoc :: CSampleDOC ()
{
// Initialize tracker position, size and style.
m_tracker.m_rect.SetRect (0, 0, 10, 10);
m_tracker.m_nStyle = CRectTracker :: resizeInside |
CRectTracker :: dottedLine;
}
The error is:
Code:
error C2065: 'm_tracker' : undeclared identifier
Can some body please guide me how to get rid of this error??
Zulfi.
↧
January 24, 2015, 4:57 am
Hi,
I am able to create a rubber band rectangle. But i am not able to create two rubber band rectangles at the same time. My code is at:
http://forums.codeguru.com/showthrea...band-rectangle
Somebody please guide me how to create multiple rubber band rectangles.
Zulfi.
↧
January 24, 2015, 7:58 am
I have a view in an application and i export the display to a wmf file. athe result is correct, but when i active the opengl mode the wmf file seems empty, is this posible. What can i do?
thanks a lot. PERE
↧
↧
January 25, 2015, 12:09 am
Hello,
I'm trying to have a button marked by the
sqrt sign, '√'.
I wrote below code and typed that sign by holding down "
alt" and typing 251 using numpad. But result is the
question mark instead of
sqrt mark!
How to solve the problem please?
My machine is Windows 7 x86 and IDE is visual studio 2012.
Code:
#include <GUI.h>
using namespace Graph_lib;
//---------------------------------
class Test : public Window {
public:
Test(Point, int, int, const string&);
private:
Button quit_button;
void quit() { hide(); }
static void cb_quit(Address, Address pw) { reference_to<Test>(pw).quit(); }
};
//----------------------------------------------------------------------------------
Test::Test(Point xy, int w, int h, const string& title):
Window(xy, w, h, title),
quit_button(Point(x_max()-120, 120), 80,30, "√", cb_quit) {
attach(quit_button);
}
//-------------------------------------------
int main() {
Test curr(Point(100,100), 500, 300, "Test");
return gui_main();
}
↧
January 25, 2015, 2:58 am
Hey..
I'm working on a C++ application that deals with Sql Server Database .
This query insert an image to the table (on the condition that you should be bulkadmin).
Code:
CREATE TABLE Files (ID int , userImage image)
INSERT INTO Tbl(ID, userImage)
SELECT 1, * FROM OPENROWSET (BULK N'Path', SINGLE_BLOB) rs
Now the image (bytes) representation appears to be :
'0xFFD8FFE000104A46494600010101006000600000FFE...................... '
but when I am reading the image as a binary file using this code in C++
Code:
ifstream input("..\\image.jpg", ios::in | ios::binary | ios::ate);
int size;
if (!input)
{
return 0;
}
if (input.is_open())
{
size = input.tellg();
char* memset= new char[size];
input.seekg(0, ios::beg);
input.read(memset, size);
input.close();
for (int i = 0; i < size; ++i)
printf("%x", memset[i]);
delete memset;
}
it appears to be completely different..
Why is that ?
and if there is a mistake, what is the right thing to do ?
↧
January 25, 2015, 11:35 am
How to insert and read images to/from database (sql server) using MFC ?
an example or a reference would be appreciated :)
↧