|
I got it!!
BOOL CSelectPayroll_PP2::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message== WM_KEYDOWN && pMsg->wParam==13)
{
OnAdd() ;
pMsg->hwnd= NULL;
}
return CPropertyPageEx::PreTranslateMessage(pMsg);
}
Fortitudine Vinsinues!
|
|
|
|
|
Hey guys!
I have been working on my random combinor for a while now, and I want to take it to the next level.
The thing actually does this:
It has two arrays of strings, one being filled with names, the other being filled with activities that a person can do.
The program then randomly generates a number (1-9, where 9 is the amount of strings in both arrays) and displays the corresponding name/action.
E.g. "Kim" + " is working in the garden" = Kim is working in the garden.
(You can find the source underneath here, in case you need it)
Now, I want the program to EXCLUDE already used options.
For instance, in my exapmle, the name "Kim" and the activity " is working in the garden." will not be used anymore.
How can I do this? I thought of creating integers carrying or either the value 1 or 0 and when the program generates the random numbers it's going to check that value (0 means the name or activity has not yet been used)and turn it into 1 and proceed, or try another one when it's 1 until he finds one with 0.
But the problem is I don't know how to do this, unless by creating a lot of code, which is too ineffecient to me.
Does anyone have any ideas?
Thanks in advance!
random_activities.cpp<br />
#include < cstdlib ><br />
#include < ctime ><br />
#include < iostream ><br />
#include < string ><br />
using namespace std;<br />
<br />
int main()<br />
{<br />
<br />
string person[9] = {<br />
"Jason",<br />
"My best friend",<br />
"Uncle Ben",<br />
"Mark",<br />
"Eva",<br />
"Dad",<br />
"My daughter",<br />
"Deborah",<br />
"That kid over there"};<br />
<br />
string activity[9] = {<br />
" is preparing a diner for two.",<br />
" is playing a game of tennis with mum.",<br />
" is making out with his/her girl/boyfriend.",<br />
" is studying his geography exam.",<br />
" is still sleeping.",<br />
" is cruising on his motorcycle.",<br />
" is shooting baskets in the garden.",<br />
" is relaxing by the pool.",<br />
" is coding a simple program in C++"};<br />
<br />
int a = 0;<br />
int b;<br />
int i;<br />
int j;<br />
const int N = 9;<br />
<br />
cout << "Who is doing what? Find out with this program!\n";<br />
<br />
cout << "Of how many persons would you like to know what they are doing?\nThey might be busy doing more things at a time, though!\n"; <br />
<br />
cin >> b;<br />
<br />
cout << endl;<br />
<br />
srand( (unsigned)time( NULL ) );<br />
<br />
while (a < b){<br />
<br />
i = rand() % N;<br />
j = rand() % N; <br />
cout << person[i] << activity[j] << endl; <br />
a++;<br />
<br />
}<br />
<br />
cout << "\n\nNow you know a bit more about the people around you!\nCome back later, you hear!";<br />
<br />
getchar();<br />
<br />
return 0;<br />
<br />
}
|
|
|
|
|
try this... Declare a struct first with the string resources
struct StringResource{
string person[9] = {
"Jason",
"My best friend",
"Uncle Ben",
"Mark",
"Eva",
"Dad",
"My daughter",
"Deborah",
"That kid over there"};
string activity[9] = {
" is preparing a diner for two.",
" is playing a game of tennis with mum.",
" is making out with his/her girl/boyfriend.",
" is studying his geography exam.",
" is still sleeping.",
" is cruising on his motorcycle.",
" is shooting baskets in the garden.",
" is relaxing by the pool.",
" is coding a simple program in C++"};
};
In your main program call the struct:
StringResource bunchostrings;
Everytime a string is used just empty the values. Ex:
bunchostrings.activity[8] = "";
Check to see if the string is empty, if it isnt, use it then after empty it. If the string is empty, then randomly search for another one.
Hope that helps,
Robbie
|
|
|
|
|
Here's how I'd do it:
#include <algorithm>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
typedef const char* PCSTR;
PCSTR names[] =
{
"Bob",
"Jane",
"Tina",
"Bill"
};
PCSTR* names_end = names+sizeof(names)/sizeof(names[0]);
PCSTR tasks[] =
{
"is laughing",
"is crying",
"is jumping",
"is having fun"
};
PCSTR* tasks_end = tasks+sizeof(tasks)/sizeof(tasks[0]);
random_shuffle(names, names_end);
random_shuffle(tasks, tasks_end);
for (
PCSTR *pName=names, *pTask=tasks;
pName!=names_end && pTask!=tasks_end;
++pName, ++pTask )
{
cout << *pName << " " << *pTask << "." << endl;
}
return 0;
}
Steve
|
|
|
|
|
luckily I read your post before I replied - yep, gotta love those stl Algorithms like random_shuffle .. I found stl took a while to get the hang of, but it sorta grows on me now ..
'g'
|
|
|
|
|
another way would be to create a 9x9 array of bool values:
bool used[9][9];
for (int z=0;z<9;z++) for (int q=0;q<9;q++) used[z][q]=false;
then, when you choose i,j make sure that pair hasn't been used:
int tested=0;
while (used[i][j] && tested<9*9)
{
.. choose new i,j
tested++;
}
then, when you know your i,j haven't been used, set the appropriate used flag to true
used[i][j] = true;
maybe not ideal, but it's an option.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
can we use these when designing an MFC application?
it keeps telling me:
error C2065: 'HDEVINFO' : undeclared identifier
-AND-
error C2065: 'SP_DEVICE_INTERFACE_DATA' : undeclared identifier
I've #included the following:
#include <stdlib.h>
#include <objbase.h>
#include <setupapi.h>
#include <winioctl.h>
#include <process.h>
#include <memory.h>
#include "stdafx.h"
Could someone tell me what i'm doing wrong... or if I need to drink more coffee...
Kitty5
|
|
|
|
|
Do you have the following line?
#include <setupapi.h>
|
|
|
|
|
Viorel. wrote: Do you have the following line?
#include <setupapi.h>
Yes.
I #included the following:
#include "windows.h"
#include "stdlib.h"
#include "objbase.h"
#include "setupapi.h"
#include "winioctl.h"
#include "process.h"
#include "memory.h"
#include "stdafx.h"
Kitty5
|
|
|
|
|
Since the SetupAPI.h file defines the SP_DEVICE_INTERFACE_DATA structure in this manner:
#if _SETUPAPI_VER >= 0x0501
. . .
typedef ..... SP_DEVICE_INTERFACE_DATA;
. . .
#endif
I think you have to add a definition like
#define _SETUPAPI_VER 0x0501
before all of your #include .
|
|
|
|
|
how do you know to do that?
Kitty5
|
|
|
|
|
I used Search operation within *.h files supplied with Visual Studio, for "SP_DEVICE_INTERFACE_DATA" string. Thus I found the SetupAPI.h file and then I analyzed it.
|
|
|
|
|
nope... still didn't work.
I've also made sure that the setupapi.lib is also part of the options for the linker and that I've provided a path to the lib files in the project properties.
Kitty5
|
|
|
|
|
Today it was reported a similar problem with other header files.
The solution was to put your #include after "stdafx.h":
#include "stdafx.h"
#include <windows.h>
#include <stdlib.h>
#include <objbase.h>
#include <setupapi.h>
#include <winioctl.h>
#include <process.h>
#include <memory.h>
If it works, you can move your #include to the end of "stdafx.h" file and then rebuild the solution. In this case, next time your file will be compiled faster.
-- modified at 11:57 Friday 16th June, 2006
|
|
|
|
|
Hi
XlTable Structure has 255 as the max length for a string block
so if I want to send a unicode text I'm restricted with 127 max
and the worst is that when an application like Excel expect to have
- lets say 200 - chars each block then we can't send unicode text
so any Idea how can I send unicode using XlTable
-if any one knows other format except tdtString that do the job -
regards
BASSEL
|
|
|
|
|
Hey there,
I'm building a gui that has multiple tabs, and what I had done was set the hwnd variables as static variables such as below:
<br />
BOOL CALLBACK OptionsDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)<br />
{<br />
<br />
static HWND* tab1_hwnd = new HWND;<br />
static HWND* tab2_hwnd = new HWND;<br />
static HWND* tab3_hwnd = new HWND;<br />
static HWND* tab4_hwnd = new HWND;<br />
static HWND* tab5_hwnd = new HWND;<br />
static HWND* tab6_hwnd = new HWND;<br />
static HWND* CurrentTabHwnd = new HWND;<br />
static int* CurrentTabIndex = new int;<br />
static HWND* hwndTab = new HWND;<br />
<br />
switch(msg)<br />
{<br />
case WM_INITDIALOG:<br />
{<br />
<br />
LPSTR tab1_title = "General";<br />
LPSTR tab2_title = "Player Edit";<br />
LPSTR tab3_title = "Stats Attributes";<br />
LPSTR tab4_title = "Stats Format";<br />
LPSTR tab5_title = "File Upload";<br />
LPSTR tab6_title = "Advanced";<br />
<br />
<br />
INITCOMMONCONTROLSEX tabctl;<br />
<br />
tabctl.dwSize = sizeof(tabctl);<br />
tabctl.dwICC = ICC_TAB_CLASSES;<br />
<br />
InitCommonControlsEx(&tabctl);<br />
<br />
*hwndTab = GetDlgItem(hwnd,IDC_TAB1);<br />
<br />
TCITEM ItemStruct;<br />
<br />
ItemStruct.mask = TCIF_TEXT;<br />
ItemStruct.pszText = tab1_title;<br />
ItemStruct.cchTextMax = sizeof(tab1_title);<br />
ItemStruct.iImage = 0;<br />
ItemStruct.lParam = 0;<br />
<br />
SendMessage(*hwndTab, TCM_INSERTITEM, 0, (LPARAM)&ItemStruct);<br />
<br />
ItemStruct.pszText = tab2_title;<br />
ItemStruct.cchTextMax = sizeof(tab2_title);<br />
<br />
SendMessage(*hwndTab, TCM_INSERTITEM, 1, (LPARAM)&ItemStruct);<br />
<br />
ItemStruct.pszText = tab3_title;<br />
ItemStruct.cchTextMax = sizeof(tab2_title);<br />
<br />
SendMessage(*hwndTab, TCM_INSERTITEM, 2, (LPARAM)&ItemStruct);<br />
<br />
ItemStruct.pszText = tab4_title;<br />
ItemStruct.cchTextMax = sizeof(tab2_title);<br />
<br />
SendMessage(*hwndTab, TCM_INSERTITEM, 3, (LPARAM)&ItemStruct);<br />
<br />
ItemStruct.pszText = tab5_title;<br />
ItemStruct.cchTextMax = sizeof(tab2_title);<br />
<br />
SendMessage(*hwndTab, TCM_INSERTITEM, 4, (LPARAM)&ItemStruct);<br />
<br />
ItemStruct.pszText = tab6_title;<br />
ItemStruct.cchTextMax = sizeof(tab2_title);<br />
<br />
SendMessage(*hwndTab, TCM_INSERTITEM, 5, (LPARAM)&ItemStruct);<br />
<br />
*tab1_hwnd = CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_OPTIONS_GENERAL), *hwndTab, General_OptionsDialogProc, 0);<br />
*tab2_hwnd = CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_OPTIONS_PLAYEREDIT), *hwndTab, PlayerEdit_OptionsDialogProc, 0);<br />
*tab3_hwnd = CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_OPTIONS_STATSATTR), *hwndTab, StatsAttr_OptionsDialogProc, 0);<br />
*tab4_hwnd = CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_OPTIONS_STATSFORMAT), *hwndTab, StatsFormat_OptionsDialogProc, 0);<br />
*tab5_hwnd = CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_OPTIONS_FILEUPLOAD), *hwndTab, FileUpload_OptionsDialogProc, 0);<br />
*tab6_hwnd = CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_OPTIONS_ADVANCED), *hwndTab, Advanced_OptionsDialogProc, 0);<br />
<br />
*CurrentTabIndex = 0;<br />
*CurrentTabHwnd = *tab1_hwnd;<br />
<br />
ShowWindow(*tab1_hwnd,SW_SHOWDEFAULT);<br />
<br />
<br />
}<br />
break;<br />
<br />
case WM_NOTIFY:<br />
{<br />
<br />
LPNMHDR lpnmhdr = (LPNMHDR) lParam; <br />
<br />
switch(lpnmhdr->code){<br />
case TCN_SELCHANGE:<br />
{<br />
ShowWindow(*CurrentTabHwnd, SW_HIDE);<br />
<br />
switch(TabCtrl_GetCurSel(*hwndTab)){<br />
case 0:<br />
ShowWindow(*tab1_hwnd,SW_SHOWDEFAULT);<br />
*CurrentTabHwnd = *tab1_hwnd;<br />
*CurrentTabIndex = 0;<br />
break;<br />
case 1:<br />
ShowWindow(*tab2_hwnd,SW_SHOWDEFAULT);<br />
*CurrentTabHwnd = *tab2_hwnd;<br />
*CurrentTabIndex = 1;<br />
break;<br />
case 2:<br />
ShowWindow(*tab3_hwnd,SW_SHOWDEFAULT);<br />
*CurrentTabHwnd = *tab3_hwnd;<br />
*CurrentTabIndex = 2;<br />
break;<br />
case 3:<br />
ShowWindow(*tab4_hwnd,SW_SHOWDEFAULT);<br />
*CurrentTabHwnd = *tab4_hwnd;<br />
*CurrentTabIndex = 3;<br />
break;<br />
case 4:<br />
ShowWindow(*tab5_hwnd,SW_SHOWDEFAULT);<br />
*CurrentTabHwnd = *tab5_hwnd;<br />
*CurrentTabIndex = 4;<br />
break;<br />
case 5:<br />
ShowWindow(*tab6_hwnd,SW_SHOWDEFAULT);<br />
*CurrentTabHwnd = *tab6_hwnd;<br />
*CurrentTabIndex = 5;<br />
break;<br />
<br />
}<br />
}<br />
break;<br />
default:<br />
return FALSE; <br />
}<br />
<br />
}<br />
break;<br />
case WM_COMMAND:<br />
{<br />
<br />
switch(LOWORD(wParam)){<br />
<br />
case IDOK:<br />
SendMessage(hwnd, WM_CLOSE, 0, 0);<br />
break;<br />
case IDCANCEL:<br />
SendMessage(hwnd, WM_CLOSE, 0, 0);<br />
break;<br />
}<br />
<br />
}<br />
break;<br />
case WM_CLOSE:<br />
{<br />
<br />
EndDialog(hwnd, 0);<br />
delete tab1_hwnd;<br />
delete tab2_hwnd;<br />
delete tab3_hwnd;<br />
delete tab4_hwnd;<br />
delete tab5_hwnd;<br />
delete tab6_hwnd;<br />
delete CurrentTabHwnd;<br />
delete CurrentTabIndex;<br />
delete hwndTab;<br />
<br />
}<br />
<br />
break;<br />
<br />
default:<br />
return FALSE;<br />
}<br />
return 0;<br />
}<br />
As you can also see I have dynamically allocated them as well. The reason for doing this is because I dont want to make sure that the dialog boxes dont hog a lot of memory. The problem I am receiving is that once this dialog box is called that contains the multiple tabs, I get an error once I close, reopen and close once again this specific dialog box. The error is as follows:
Debug Assertion Failed!
Program: C:/.../RS_Stats32.exe
File: dbgdel.cpp
Line: 47
Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
I looked on MSDN but it doesnt offer any helpful advice on how I fix this error. I know its an issue with dynamically allocating those variables because I did not receive this error when the variables were just static and not dynamically allocated. My questions basically are:
1) Is it possible to dynamically allocate static variables, and allow the variables to dynamically allocated and destroyed once a routine has been completed? If so how?
2) Is making the hwnd variables dynamically allocated worth it? Does it actually save a considerable amount of memory?
Any help would be appreciated
Thanks,
Robbie
|
|
|
|
|
wrote:
EndDialog(hwnd, 0);
delete tab1_hwnd;
delete tab2_hwnd;
delete tab3_hwnd;
delete tab4_hwnd;
delete tab5_hwnd;
delete tab6_hwnd;
delete CurrentTabHwnd;
delete CurrentTabIndex;
delete hwndTab;
Instead of this try to call the EndDialog(hwnd, 0); after deleting all the tabs.it may resolve your problem
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
Hey man,
lol thanks for the fix, but I ran into a BIG problem. When I ran the program and closed the dialog box, I got my 8th (i think?) ever BSoD and some very weird exorcist sounds coming from my speakers. So dont think that worked out too well. Any other ides you may have?
Robbie
|
|
|
|
|
I think the problem is because of multiple delete operations performed on the same pointer. You probably believe that a line like
static HWND* tab1_hwnd = new HWND;
within a function allocates the object on each execution of that function. This is not true: the pointer is allocated once.
You can change it like this:
static HWND* tab1_hwnd = NULL;
...
case WM_INITDIALOG:
tab1_hwnd = new HWND;
. . .
case WM_CLOSE:
::DestroyWindow(*tab1_hwnd);
delete tab1_hwnd;
tab1_hwnd = NULL;
. . .
Actually HWND is not so a big object. It takes only 4 bytes. Therefore you can work without pointers:
static HWND tab1_hwnd = NULL;
|
|
|
|
|
Ok thats cool, I'll just take out the pointers since its easier that way. Thanks for your help guys.
|
|
|
|
|
Hi All
I have been puzzelled in a problem,
What have to do is, that I have some file names ( like 000001.doc, programming.doc, etc.) now I have to find out the files that are in hexadecimal (leaving file extension).
Please guide me to find out this
Thanks
|
|
|
|
|
Use isxdigit() on the file's name.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Ahh david's is a much easier way. Its in the following library as well!
#include <ctype.h>
int isxdigit(int c);
|
|
|
|
|
1) Retrieve the file list
2) Loop through each file. For every File name, loop through its name until the extension is reached and check to see if each character is either [0-9] or [A-F]. If its not, just do continue; and start back at the beginning of the loop again. Use this website to utilize the ANSI character set.
http://www.alanwood.net/demos/ansi.html
Remember, the letters can be either lower case or uppercase and have different ANSI codes.
3) Record the file names in an array. (Create a dynamic allocated array for big file names).
Robbie
|
|
|
|
|
Try this idea:
char name[100] = "......." ;
char * p;
strtoul(name, &p, 16);
if( *p == 0)
{
}
else
{
}
Hope it helps.
|
|
|
|
|