Virtual/Personal Assistant - Raspberry Pi General

Hi, some days ago I was looking for a virtual assistant for the raspberry, but there aren't any that works as I like (Yeah, I know Jasper), so I decided to create my own, it will be released or on before the 30 april (in Spanish and English, if someone wants to help me I could translate it to other languages), with all the hardware and software documentation .
I'd never proggramed in python or in any other langugae, just a bit of android source, java and css and html. Until today I've been codding lots of hours, as I'm very enthusiastic with this project, now it automately recognise when you say it's name (It is customizable), and it can play music, look for information of any famouse person, any math operation, and it can tell jokes an of course, I'm going to add more modules as twitter for exaple.
Well, I have a little problem with the speech recognition always listening, so I need help of a programmer or someone who knows good the python language to copy the way Jasper is always listening and implement it on my project (now i'm using this: https://pypi.python.org/pypi/SpeechRecognition/ )so please, if you're interested with the proyect and want to help me, answer on this post or pm me as soon as possible.
This is my actual code:
Code:
def name(): #JUST TO RECOGNISE THE NAME
r = sr.Recognizer(language = "es-ES", key = "AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw")
with sr.Microphone() as source:
audio = r.listen(source)
try:
print r.recognize(audio)
return r.recognize(audio)
except LookupError:
print("Could not understand audio")
name() #It starts again so it should recognize the name
I also need some simple jokes so if you could help me I'd be very grateful.
Thanks a lot!

I don't know ! why in this word people create problems !
Well according to me there is no need to write a code that creates stack in any case. Where your code is
Code:
def name(): #JUST TO RECOGNISE THE NAME
r = sr.Recognizer(language = "es-ES", key = "AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw")
with sr.Microphone() as source:
audio = r.listen(source)
try:
print r.recognize(audio)
return r.recognize(audio)
except LookupError:
print("Could not understand audio")
name() #It starts again so it should recognize the name
if it finds any error it will call itself after throwing the error message, so ! for every failure the processor will maintain stack and much more processes and memory is utilized for such complex call ... Finally what I want to convey is use this code ...
Code:
while True: #JUST TO RECOGNISE THE NAME
r = sr.Recognizer(language = "es-ES", key = "AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw")
with sr.Microphone() as source:
audio = r.listen(source)
try:
print r.recognize(audio)
return r.recognize(audio)
break
except LookupError:
print("Could not understand audio")
And though if you want to use the UDF you can always use return values !

I can help in translation into Russian language and sharing info about this project in Russian community like xda etc.

Related

converting ASCII to Unicode

hi ther i wonder if you could help me on this simple task. I'm creating a GPS application to run on the XDA2, i'm using eVC++ to do the implementation.
at the moment i'm reading the GPS signal via bluetooth over a virtual COM port, the signal coming from the GPS if a ASCII sinal and i'm duimping this into a char buffer.
However i need to convert this to UNICODE in order to display it on the Pocket PC, how's best to convert a buffer full of ASCII into Unicode so i may display it?
I tried using MultiByteToWideChar(), but it doesn't seem to work properly, maybe i haven't set it up correctly? Could someone point me in the right direction!
Below is an example of what i tried:
Code:
char buf[50]; // contains output from GPS
TCHAR Message[50]; //where i intended to put the message so i could display it
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, buf, -1, Message, 0);
Thank in advance
I'm sure it's not the right way to go about it, but I generally wsprintf for short strings.
However, don't listen to me, I'm a mad man. Check this page out instead:
http://www.i18nguy.com/unicode/c-unicode.html
V
Thanks for that, out of curiosity, how would you use wsprintf to convert ASCII to unicode, i tried that before with no real success!
The last value passed to MultiByteToWideChar tells this function the size of the result buffer, Message in your case. You have passed zero, all that does is makes the function return the size of a TCHAR variable it needs to put the Ascii input buf into.
You need to put sizeof(Message) as the last parameter and not zero.
The other way (better way ?) of doing this is first you call the MultiByteToWideChar function with the zero parameter as you have and then you malloc the result * sizeof(TCHAR).
Thanks for the advise, after looking into the function more i realised this is where i was going wrong, and i have now managed to make the conversion. Thanks for pointing that out though!

What code language is this?????

I found this code posted on another thread, but was wondering... What language is this? And what software do I need to compile it? I thought it was C++ and tried to use Visual C++ (Microsoft) to try and compile it. I saved the file as a .cpp and tried to compile it from the command prompt (cl /clr filename.cpp). Thanks in advance. I have little experience in this area, but I'm trying to learn.
Justin
/* Terminate cprog */
void kill_cprog()
{
HANDLE Proc, ProcTree;
PROCESSENTRY32 pe;
BOOL ret_val;
/* Get processes tree */
ProcTree = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
pe.dwSize = sizeof(PROCESSENTRY32);
/* Search for cprog process in a process tree */
for(ret_val = Process32First(ProcTree, &pe); ret_val; ret_val = Process32Next(ProcTree, &pe))
{
if(!wcsicmp(TEXT("cprog.exe"),pe.szExeFile))
{
/* Terminate cprog */
Proc = OpenProcess(0, 0, pe.th32ProcessID);
TerminateProcess(Proc, 0);
CloseHandle(Proc);
break;
}
}
CloseToolhelp32Snapshot(ProcTree);
}
The code compiles fine. Its plain win32, just make sure you include Tlhelp32.h or will get errors. I did not test if it dose anything. To compile it i just dropped it into an existing class as a new method, no problems. It looks like it wants to stop your phone process.
If you arer really new.... this code dose nothing by itself it needs to be part of a larger program. The code is used for stopping the process that is the phone on a ppc. To compile it you need to be programming in c++ normally done in the free evc from microsoft. In a file in your program eg someFile.h put the line #include <Tlhelp32.h> . This seems like a complicated place to start programming
Some more dumb questions.....
Where can I get the Tlhelp32.h? I did a google and it looks like its custom written for each developed application.
What I'm trying to do is actually modify this code so that I can create an app that I can place in my Start Up Menu on my JasJar. The app looks for a specific process (in my case a GPS application). Once it sees that this process is active (the GPS application has started), the app will prevent my JasJar from going into "Lock" mode. I think I've got it written correctly, but I'm confused on how to compile it.
I have programming experience, but I dont' know what a header file is. I don't know what a class is. I don't know what a method is. Is there a web site that explains all this?
Thanks Justin
I salute your attempt at programming the hard way :lol: . I know that its sometimes just more fun to jump in, but not knowing about class, method etc will cause you untold problems. Look on emule for some books on c++. Anyway... the file Tlhelp32.h came with evc 3.0 I think. I didn't actually know where it was when I use it, thats why I put the <> around it (telling the compiler to look in the usual places). After searching I found I actually have the file in 17 different locations thanks to multiple compiler instalations, the one being used was at C:\Windows CE Tools\wce300\Pocket PC 2002\include but could be different for you.
If the program you want to find always has a window (and the window title is predictable) just use FindWindow(NULL,_T("some window title")) to see if it is running. If it returns NULL then there is no program with that title running. If you want to see FindWindow in action get this...
http://odeean.veritel.com.au/ORDprocessManager/processKillerNoInterface.exe
and run it on your desktop pc. Press left shift and right shift for instructions. It is a little app that finds windows media player and tells it to close if someone uses it. No need for snapshots there.
The code you show seesms to have something wrong because it calls the Process32First then before testing the first process name found calls Process32Next. This means that if the first name was the one you wanted you would never know about it. Other than that your on the right track.
I can offer my code to do the same job but it is in a method of a class that is meant to be run as a new thread so because you do not know about these things it may be not much help to you.
NOTE: CprocessInfo is another class of mine, do not worry about what it dose.
//-----------------------------------------------------------------
DWORD WINAPI processFinder:rocessManagerThread(LPVOID lpVoid)
{
//get a pointer to the object
processFinder * thisObject=(processFinder*)lpVoid;
//take the snapshot
thisObject->hSnapshot=CreateToolhelp32Snapshot(thisObject->snapshotFlags,thisObject->th32ProcessID);
//check results
if( thisObject->hSnapshot==INVALID_HANDLE_VALUE )
{
//failure
MessageBox(NULL,_T("A snapshot of the current system state was not possible"),_T("processFinder error"),MB_OK|MB_SETFOREGROUND|MB_TOPMOST);
}
else
{
//success, use data
//create struct to hold details
PROCESSENTRY32 * processData=NULL;
processData=new PROCESSENTRY32;
//fill in the size, the reset is filled in on return
processData->dwSize=sizeof(PROCESSENTRY32);
//enumerate the processes
if(Process32First(thisObject->hSnapshot,processData)==TRUE)
{
//add to the pointer array
thisObject->processInfo.Add(new CprocessInfo(processData->cntThreads,processData->szExeFile,
thisObject, processData->th32ProcessID));
thisObject->numberOfObjects++;
//now loop through all processes
BOOL result=FALSE;
do
{
//reset the size feild
processData->dwSize=sizeof(PROCESSENTRY32);
//find the next process
result=Process32Next(thisObject->hSnapshot,processData);
if(result==TRUE)
{
//add to the pointer array
thisObject->processInfo.Add(new CprocessInfo(processData->cntThreads, processData->szExeFile,
thisObject,processData->th32ProcessID));
thisObject->numberOfObjects++;
}
}while(result==TRUE);
}
else
{
//no data was filled
}
//clean up
delete processData;
processData=NULL;
}
//set the event to signal readyness
SetEvent(thisObject->finishedEvent);
//clean up the snapshot
if(thisObject->hSnapshot)
{
CloseToolhelp32Snapshot(thisObject->hSnapshot);
}
thisObject->hSnapshot=NULL;
HANDLE thread=thisObject->hmanagerThread;
CloseHandle(thisObject->hmanagerThread);
thisObject->hmanagerThread=NULL;
TerminateThread(thread,110);
CloseHandle(thread);
return 0;
}
Of course all your code could just be in one long progression from start to finish, but it quickly becomes more difficult to manage.
I Salute You!!!
Wow! The help your giving is fantastic! Thanks. I think I realize how much I'm in over my head. I found a machine at work with Visual .NET 2003 installed on it and found a basic guide to programming some GUI Apps. Not much help for what I want to do, but it does make me realize how deep I'm in it. Oh well, if it was easy, everybody would be doing it!
I'll have to look at your code tomorrow and try to compile it. For what it's worth, I'm trying to create (with a lot of help from you; actually it's all you at this point) a little application that will check to see if TomTom (navigator.exe & windowed), iGuidance or OCN/Navigon is running. If it is, this application will prevent my JasJar (with MSFP AKU2.0) from going into 'Lock' Mode.
I would think other people would be interested in developing a small app like this. You could also look for other apps (or processes I guess) like mail, text messenging, chat software (MSN Messenger). Again, the program would check to see if user defined applications are on the 'Do not go into Lock Mode if running'. It could be very versitle and powerful. Anyway, that's where I'm trying to head.
This 'lock function' in the new ROM upgrade stinks!
Again, thanks for your help.
Justin

intro!

Hi Guys,
I'm going through the forum, I'm new to embedded developement, I've been able to do my first MessageBox("Hello World") in C using VS2005.
I want to understand how all this works, like :
- Accessing any "mass storage" device ? (the root FS ?, /, c:\, whatevername )
- Dumping the whole registry + values.
- Logging Process and activity even while "device locked" (new process, etc..)
And having more knownledge about the internals and devices, booting etc..
I'm kind of lost and my embedded knowledge is very thin..
The PPC i have is running WM5 on QTEK9100 (SPVM3000)..
Any pointers, posts, sources, small explication are more than welcome...
Hope you can help,
Regards,
r.
Welcome!
Wow those sure are some heavy requests for someone who is just starting.
How much experience do you have with C and Win32 APIs?
To start you off here is an excellent site for Windows Mobile programming tips and tricks:
www.pocketpcdn.com
Couple more pointers:
Device root is "\", no drives (SD cards mounted as folders) kind of like Linux.
All path are absolute - no ".\" or ".."
You can use standard C or Win32 functions for file operations.
Registry functions are also same as Desktop windows except you have to use the "Ex" version of of the function.
Example:
RegOpenKey - not implemented, use RegOpenKeyEx.
For process lists etc, google for ToolHelp32.
Thanks,
I'm at ease w/ ANSI C, have some familiarity w/ Win32 APIs,
but as far as I'm seeing I'm trying to code on Win32 Intel First,
then i try to "port" it to PocketPC Mobile, sometime it works
sometime functions doesn't even exists... MSDN doesn't seems very consistent over Win32 vs WM, but as I'm new I guess i'm missing a lot..
WinMain() prototype changes according to your target...otherwise
VS2005 yell about Overloading WinMain, It is VERY annnoying..anyway
Thanks for the links and the *Ex trick, I'll try to get deeper with this.
I have a strange problem trying to do my Own MessageBoxPrintf:
int MessageBoxPrintf(int, const char * title, const char * fmt, ...)
{
va_list ap;
char * buffer = NULL;
/* formatting and fixed size yes...*/
buffer = (char *) malloc (1024 * sizeof(char));
if (!buffer)
return -1;
memset(buffer, 0, 1024);
va_start(ap, fmt);
vsprintf(buffer, fmt, ap);
va_end(ap);
MessageBox(NULL, (LPCWSTR)buffer, (LPCWSTR)title, type);
return 0;
}
It does compile, but it display craps, since there is no stderr,stdout,stdin and
that I'm mostly coding on Win32/VMware, I don't know how to debug on my PPC (no USB connection), and I have no idea what's wrong.. it might be obvious, but it's late..
As I don't know what LPCWSTR stand for, I assumed char * and it did work on Win32 (XP) without hassle (except LPCWSTR types which are wrong for Win32 Target), so why it doesn't on WM5... is a mystery for me now..
Hope to be on speed ASAP to be able to release some stuff..
Thanks for your help,
Cheers,
r.
all WinAPI function on Pocket PC works with Unicode strings. So you have to convert from ANSI to Unicode.
ok, does the TEXT() macros convert to Unicode string, it seems not.
How to convert from ANSI to Unicode ?
you can work directly with wchar_t or use tchar that can be ansi or unicode, otherwise look for MultiByteToWideChar or CString object _T and TEXT Macro aren't for converting ansi but they makes unicode prefix strings... for example MessageBox(hWnd,_T("Hello World"),_T("my messagebox"),MB_OK);
I hope this help and don't forget MSDN have all replies
have fun,
Guybrush
ok it works! thanks!
just another question, how to dump the "disk" or how those devices are booting ROM?/Flash?
Currently I'm copying all the files from / to the SD card mount point is there anything else?
again thanks for your help.
++
r.

Simple Programming Question embedded VC++

I'm currently doing some programs myself with the free MS embedded VC++.. and I'm finding it comfortable to do a simple dialog-based programs for PPC. I think I can have most of the background code going, and I've just got the GUI .. alright.
Now the question, how do I do a copy/paste to/from clipboard? I had most of the stuff done using the included MFC Wizard. I can get and send data to/from an EditBox (TextBox, whatever you call it). However, the click-hold thing on PPC doesn't seems to work on my EditBox, and hence I'm thinking what's needed to enable a simple Copy/Paste on an EditBox.
Currently, I'm using the simple
Code:
m_editBox = _T("the message I want to show");
UpdateData(FALSE); //send it to the EditBox
Any guide from here would be appreciated. However, I'm thinking there may not be an easy way to do that, hence I've also tried adding a 'Copy' and 'Paste' button to do the job, but I've tried things like
Code:
SetClipboardData(x, x)
GetClipboardData(x)
None works.
I have also tried
Code:
COleDataObject DataObject;
and with the handle etc etc .. but I can't seems to find this COleDataObject , is that in some other environment (e.g. not PPC env)?
Help
Fast solution:
http://www.pocketpcdn.com/articles/sip.html
(this shows/hides sip on get/lost focus in edit controls and add the context menu too)
and this is a simple example how to copy datas into clipboard
if(OpenClipboard(NULL))
{
EmptyClipboard();
HLOCAL clipbuffer = LocalAlloc(0, 100);
wcscpy((WCHAR*) clipbuffer, (WCHAR*) (vtNumber.bstrVal));
SetClipboardData(CF_UNICODETEXT, clipbuffer);
CloseClipboard();
free(szMsg);
LocalFree(clipbuffer);
}
I hope this help u
bye
Thanks for your respond.. things work.. a bit
Code:
//put a test char
char *test;
test = (char*) malloc(100);
strcpy(test, "blah blah blah");
//codes you've given
if(OpenClipboard()) //OpenClipboard(NULL) gives me error
{
EmptyClipboard();
HLOCAL clipbuffer = LocalAlloc(0, 100);
wcscpy((WCHAR*) clipbuffer, (WCHAR*) test);
SetClipboardData(CF_UNICODETEXT, clipbuffer);
CloseClipboard();
//free(szMsg); //not sure what 'szMsg' is
LocalFree(clipbuffer);
}
Things somewhat works. I'm not really sure which part I've got wrong. I'm suspecting some memory allocation is giving me problems. The thing is, if I were to use 'CF_UNICODETEXT' on the 'SetClipboardData(x,x)' line, I get something to paste on other programs (PPC Notes). BUT, the thing pasted is some funny stuff (e.g. letters that cannot be rendered, hence I get the little squares). If I were to use 'CF_TEXT', I don't seems to able to send my stuff to the clipboard or it made it invalid for (PPC Notes) pasting (e.g. I'm not able to paste it in PPC Notes).
Thanks.
BTW, if you are in the mood, can you give me a Paste function as well. Thanks a bunch.
Hi hanmin.
Odd I didn't notice this thread sooner.
Any way if you still having problems with this code here is the solution:
You are working with char and strcpy so your text is in ASCII (each letter one byte).
But you are calling SetClipboardData with CF_UNICODETEXT so it expects WCHAR (UNICODE) where each letter is two bytes.
The strange letters are the result of two consecutive bytes being interpreted as a single letter (probably lends you in Chinese or Japanese region of the Unicode table)
Windows mobile doesn't usually work with ASCII so the text you get from the edit box will already be in Unicode and won't give you any trouble.
The code should look like this:
Code:
//put a test char
CString test; //since you are working with MFC save your self the trouble of memory allocation
test = L"The text I want on clipboard"; //The L makes the string Unicode
//codes you've given
if(OpenClipboard()) //OpenClipboard(NULL) gives me error
{
EmptyClipboard();
//not sure why you need to copy it again, but here goes:
HLOCAL clipbuffer = LocalAlloc(0, test.GetLength() * 2); //remember: every letter 2 bytes long!
wcscpy((WCHAR*) clipbuffer, (WCHAR*)(LPCTSTR)test); //LPCTSTR is an overloaded operator for CString
SetClipboardData(CF_UNICODETEXT, clipbuffer);
CloseClipboard();
//szMsg probably belongs to some larger application and is irrelevant
LocalFree(clipbuffer);
}
I never used the clipboard APIs my self so I can't guide you farther but this code should work.
Hope this helps.
Wooo hooo.. Thanks levenum. I'm back on business!
You code works wonderfully.. just the final code "LocalFree(clipbuffer);" seems to cause problems. Without that, it works. I'm not sure if it will cause a memory leak.. but that's not much of my concern now
Now my Paste also works, and it seems that the magic code is the "LPCTSTR", which I have NO idea what it is (I'm more of a pure C person and.. a Java person ) Thanks again.
Glad I could help.
I am working from Ubuntu right know (Linux distro in case you didn't know) so I do not have access to my off-line MSDN files, but I recommend you check out the documentation for SetClipboardData.
It is possible it releases the memory it self so when you call LocalFree the handle is no longer valid.
That could also be the reason why you need to allocate memory instead of passing it the string directly.
As for LPCTSTR it is simple and not C++ related:
#define const* WCHAR LPCTSTR
Its M$ way of saying Long Pointer to Constant STRing
T changes meaning based on what you are working with:
If you work with ASCII TCHAR is char
If you work with Unicode TCHAR is WCHAR
Basically these are just all redefinitions of variable types so you can distinguish what they are used for.
In C++ you can overload operators. For example you can have a function which changes the way ++ works with certain types of variables.
In our case CString class has a function which determines what happens when you try to cast (convert) it to a pointer to string.
Thats all the "magi" code.
Good luck with your app.
Small update:
Since I had to go in to XP anyway (to change PDAMobiz ROM which kept hanging at random and didn't let me use BT to latest PDAViet which for now seem very good) I took a quick peek at the help files.
Here is why you should not release the memory:
After SetClipboardData is called, the system owns the object identified by the hMem parameter. The application can read the data, but must not free the handle or leave it locked. If the hMem parameter identifies a memory object, the object must have been allocated using the LocalAlloc function
Click to expand...
Click to collapse
levenum, thanks. You've got me almost there. There are several stuff I need to polish up though. Attach is a pre-mature version of what I wanted to do. There are several issues (including the fact that, only the 4 characters of the password are effectively used, which can be easily fix, I think. Just need to find the bug and squash it) that I like to polish up. They are sorted in order of importance (to me):
[1] Keyboard (SIP) pop up.
For this, I digged around and got to know that the function
"SHSipPreference( HWND, SIP_UP)" is the one to used. However, it never did what it suppose to do. I have had it put inside the "OnSetfocusConfirmPasswordEdit()" of the edit box, which should be called when it is set focus. I suspect that is I haven't set the HWND correctly. I have tried "NULL" and also tried using the "CWnd* pParent" from my dialog constructor (generated code my MFC Wizard). None of them worked.
[2] Editbox focusing.
For some reason, the focus on my main-dialog is correct on the editbox of the 'message'. However, on the dialog which is to confirm the password (which I called using
Code:
CConfirmPasswordDlg confirmPasswordDlg;
int nResponse = confirmPasswordDlg.DoModal();
is focusing on the 'Ok' button. What I like it to do is to focus on the 'confirmPasswordEdit' box, and it ought to automatically pop up the keyboard (SIP).
[3]Reduced size pop up dialog
I was trying to make the 2nd confirm password dialog smaller, something like a pop up in the PPC rather than something that take up the whole screen without much contents in it. How would you go about doing that? Is it not possible in PPC? E.g, if you were to use Total Commander, and start copying files around, they do have a pop up that does take up the entire screen. I'm suspecting I shouldn't do a "confirmPasswordDlg.DoModal()", and should some what do something myself. I have tried, SetVisible(1) thing, but that doesn't work. Or it shouldn't meant to work because my 1st screen is a dialog screen?
[4]Timer?
I would like to have a function of which after a certain period of idle time, it will clear off the clipboard and close itself. How would I go about doing this? Some sort of background thread thing?
Anyone can shine a light on my issues above? On MS-embedded Visual C++ (free), with Pocket PC 2003 SDK (free)
Attached the Blender-XXTea edition
Works on PPC2005 and WM5 (should work on WM6)
Does not require .NET framework
VERY small (54K)
hanmin said:
[2] Editbox focusing.
For some reason, the focus on my main-dialog is correct on the editbox of the 'message'. However, on the dialog which is to confirm the password (which I called using
Code:
CConfirmPasswordDlg confirmPasswordDlg;
int nResponse = confirmPasswordDlg.DoModal();
is focusing on the 'Ok' button. What I like it to do is to focus on the 'confirmPasswordEdit' box, and it ought to automatically pop up the keyboard (SIP).
Click to expand...
Click to collapse
In your CConfirmPasswordDlg::OnInitDialog handler, call GetDlgItem(confirmPasswordEdit).SetFocus() and return FALSE. That should handle the focus and possibly the SIP popup.
3waygeek said:
In your CConfirmPasswordDlg::OnInitDialog handler, call GetDlgItem(confirmPasswordEdit).SetFocus() and return FALSE. That should handle the focus and possibly the SIP popup.
Click to expand...
Click to collapse
HEY! The focus works! The working code is
Code:
((CWnd*) CConfirmPasswordDlg::GetDlgItem(IDC_CONFIRM_PASSWORD_EDIT))->SetFocus();
BTW, I'm wondering, whats the effect of a return TRUE/FALSE on a 'OnInitDialog()'?
Anyway, the keyboard pop up is still not working. I'm using the command
Code:
void CConfirmPasswordDlg::OnSetfocusConfirmPasswordEdit() {
SHSipPreference( (HWND)g_pParent, SIP_UP);//
}
which I suspect the 'g_pParent' is NULL. If it is NULL, would it work?
Ok, I haven't used MFC for a while and almost not at all on PPC but I will give this a shot:
1) MFC forces dialogs to be full-screen. Here is a detailed explanation on how to change that. Note that for some reason this will work only once if you use the same variable (object) to create the dialog several times.
If you use a local variable in say a button handler thats not a problem because the object is destroyed when you exit the function.
2) There is a simple SetTimer API. You can give it a window handle and then add an OnTimer message handler to that window. Or you could give it a separate function which will be called (say TimerProc). In that case you can give it NULL as window handle.
Note that CWnd objects have a member function with the same name (SetTimer) which sets the timer with that window handle (so that window will receive WM_TIMER message). If you want the raw API call ::SetTimer.
Also note that the timer will continue to send messages / call your special function every x milliseconds until you call KillTimer.
3) I am not sure what the problem with the SIP is. CWnd and derived classes like CDialog have a function called GetSafeHwnd (or GetSafeHandle, I don't remember exact name). Try passing that to SHSipPreference.
If that does not work here is an article with an alternate solution.
WOHO!! Everything works NOW!!.. MUAHAHHAHA.. wait til you see my release version
Non maximized windows works using the code suggested at the page. Although I still do not understand where the heck this '.m_bFullScreen' property came from. It is not anywhere obvious to be seen.
Code:
CNfsDlg dlg;
dlg.m_bFullScreen = FALSE;
dlg.DoModal();
Timer works using the
Code:
xx{
//your code...
CBlenderDlg::SetTimer(1, 5000, 0); //event 1, 5 seconds, something
//your code...
}
void CBlenderDlg::OnTimer(UINT nIDEvent){
//do something here for the timer
}
although somehow, the OnTimer() only works if I went to the MFC class wizard to add the WM_TIMER function. Doesn't work when I add in the OnTimer() myself. Must be something else that I've missed. Anyway.
Keyboard issue solved using
Code:
SHSipPreference( CBlenderDlg::GetSafeHwnd(), SIP_UP);
Glad its working out for you.
Couple of comments:
1) Somewhere at the top of the cpp file, if I am not mistaking there is something called a message map. It's a bunch of macros that lets MFC know what window messages it handles. An entry there is what was missing when you added the function manually.
2) m_bFullScreen is just another among many undocumented features. M$ likes to keep developers in the dark. For instance WM 2003 and up have an API called SHLoadImage which can load bmp, gif, jpg and some other formats and return HBITMAP which all the usual GDI functions use.
This API was undocumented until WM 5 came out and even then they said it only works for gif...
hanmin said:
BTW, I'm wondering, whats the effect of a return TRUE/FALSE on a 'OnInitDialog()'?
Click to expand...
Click to collapse
The return value indicates whether or not the standard dialog handler (which calls your OnInitDialog) should handle setting the focus. As a rule, OnInitDialog should return TRUE, unless you change the focus within the handler (or you're doing an OCX property page on big Windows).
I haven't done much WinMob/CE development -- I've been doing big Windows for 15+ years, so window message handling is pretty much second nature. I started doing Windows development back in the days when you didn't have C++ or MFC boilerplate; you had to implement your own DialogProc, crack the messages yourself, etc. It's a lot easier now.
CommandBar / MenuBar
I'm back.. with more questions
Not much of a major issue, but rather an annoying thing I've found. Probably that's what evc/mfc/m$ intended to do that.
Anyway, I'm starting my way of getting around CommandBar. I created a MFC skeleton, studied the code, and that's what I've found, after I've created a CommandBar/MenuBar on evc and putting it in
Code:
if(!m_mainMenuBar.Create(this) ||
!m_mainMenuBar.InsertMenuBar(IDR_MAINMENUBAR) ||
!m_mainMenuBar.AddAdornments() ||
!m_mainMenuBar.LoadToolBar(IDR_MAINMENUBAR))
{
TRACE0("Failed to create IDR_MAINMENUBAR\n");
return -1; // fail to create
}
where I have the variable 'CCeCommandBar m_mainMenuBar' and I have created a MenuBar on evc with the Id 'IDR_MAINMENUBAR'. The menu bar works flawlessly on my dialog based application, when I have the 1st level as a pop up. Example
MenuBar --> 'File' --> 'New', 'Save'
Where 'File' is a folder-like thing that pop-ups and show the contents (i.e. in this example, 'New', and 'Save'). However, given the SAME code to load the CommandBar/MenuBar, it will not work, if I were to put the actual command at 1st level. Example, this will not work
MenuBar -> 'New', 'Save'
where there isn't any folder-like pop-up to store the commands 'New', and 'Save'.
I know that I can have buttons for these commands, and probably works. But, what I'm trying to do is to utilize the bottom-left-right softkey in WM5/6. If I were to have the 'File'->'New','Save' structure, it works fine with WM5, showing it as a softkey. But, if I were to do just 'New','Save' it will not show up in both WM2003 emulator and WM5.
As a matter of fact, even if I have (say) File->New,Load, and I added a new command (i.e. not folder-like-pop-up), example 'Help' on the CommandBar/MenuBar, the File->New,Load will not show up too. It seems like the 1st level command (ie. without a folder-pop-up), causes some problems and stop it from loading further.
Guys, ring any bell?
two bytes more
levenum said:
Hi hanmin.
Odd I didn't notice this thread sooner.
Any way if you still having problems with this code here is the solution:
You are working with char and strcpy so your text is in ASCII (each letter one byte).
But you are calling SetClipboardData with CF_UNICODETEXT so it expects WCHAR (UNICODE) where each letter is two bytes.
The strange letters are the result of two consecutive bytes being interpreted as a single letter (probably lends you in Chinese or Japanese region of the Unicode table)
Windows mobile doesn't usually work with ASCII so the text you get from the edit box will already be in Unicode and won't give you any trouble.
The code should look like this:
Code:
//put a test char
CString test; //since you are working with MFC save your self the trouble of memory allocation
test = L"The text I want on clipboard"; //The L makes the string Unicode
//codes you've given
if(OpenClipboard()) //OpenClipboard(NULL) gives me error
{
EmptyClipboard();
//not sure why you need to copy it again, but here goes:
HLOCAL clipbuffer = LocalAlloc(0, test.GetLength() * 2); //remember: every letter 2 bytes long!
wcscpy((WCHAR*) clipbuffer, (WCHAR*)(LPCTSTR)test); //LPCTSTR is an overloaded operator for CString
SetClipboardData(CF_UNICODETEXT, clipbuffer);
CloseClipboard();
//szMsg probably belongs to some larger application and is irrelevant
LocalFree(clipbuffer);
}
I never used the clipboard APIs my self so I can't guide you farther but this code should work.
Hope this helps.
Click to expand...
Click to collapse
I know it is a bit late! But there is a mistake the code snippet:
HLOCAL clipbuffer = LocalAlloc(0, test.GetLength() * 2); //remember: every letter 2 bytes long!
needs to be
HLOCAL clipbuffer = LocalAlloc(0, test.GetLength() * 2+2);
the terminating 0 is als 2 bytes long!
Those errors are sometimes fatal, with very less chance to find them!
ms64o

VB.net help needed for an app Im halfway through writing.

Ive got to a point where Ive got to the limit of my knowledge.
(admitedly, I no pro, I just dont know how to do this)
Ive got a loop which finds out how many images are in a folder
and it makes a new picturebox for each image, sets the image
property to show that image and gives it a name, height, width,
location and parent.
My problem is I want to add a mouseclick event for each of these
items as I create them. I just dont have a clue how to do this.
Anyone got any ideas?
Ive tried this kinda thing, but it didnt work (stupid compact framework):
Code:
picturebox.MouseClicked += new MouseEventHandler(function_name);
Good Help Forum
http://www.vbforums.com/
It must work... Not sure how it is in VB.NET, but in C# it is this:
... in some method ...
PictureBox pb = new PictureBox();
.. setting properties
pb.Click += new EventHandler(PictureBox_Click);
... end of the method
private void PictureBox_Click(object sender, EventArgs e)
{
... here goes your code, the picturebox clicked is in (sender as PictureBox), event args are in e
}
Thanks for you help
Ive not managed to get anything working properly so far
but I have within the past 10 mins figured out how to get around having to do this ^_^
See, this is a autoload image:
Me.PictureBox1.Image = New System.Drawing.Bitmap("figure2.bmp")
And Example:
http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/2896d5cd-06d1-4a70-a561-a2c3497e325c
I think this wouldn't have been a problem with older VB technology if it had supported WM development. By that I mean it supported object arrays and provided a method with an 'Index'. From what I can see .NET doesn't offer such a luxury.
Your code looks right (syntax); but would I be right in thinking that your loop recreates 'picturebox' each time it loops and you are trying to associate an array of 'picturebox' to a single 'MouseEventHandler' function?
Code:
picturebox.MouseClicked += new MouseEventHandler(function_name);
My method of programming .NET is pretty much trial and error so I can't say for sure, just waffling
This is an example on how i did this with c# and the paint event. You dont want the paint event but it should be easy enough to change.
private void GenerateDynamicControls(string extt)
{
PicBox = new PictureBox();
PicBox.Image = Properties.Resources.phone;
PicBox.Name = "picturebox" + extt.ToString();
PicBox.Width = 75;
PicBox.Height = 75;
PicBox.BackgroundImageLayout = ImageLayout.Center;
flowLayoutPanel1.Controls.Add(PicBox);
PicBox.Paint += new PaintEventHandler(picpaint);
}
private void picpaint(object Sender,System.Windows.Forms.PaintEventArgs e)
{
//Do whatever you need done here
}
//To Create the control do this.
GenerateDynamicControls(namethecontrolsomething);
Hope this helps.
In VB.Net, you need to use AddHandler. Quick search on the tutorial and I found, http://www.thescarms.com/dotnet/EventHandler.aspx
Hope this help.
smart device applcation
Sorry guys but I will use this thread to ask for your help regarding VB.Net.
Does anyone know how to browse the device and select a picture into a picture box?
Example:
I have a form with a picturebox and a button and what I want is by pressing the button to explore my device, choose a picture and update my picturebox with the picture selected.
There are loads of youtube videos with Windows Forms Applications tutorial but I just can not find one for a smart device applcation.
Any help?
Thanks

Categories

Resources