 |
|
|
 |
|
|
 |
|
 |
hi,
i want to use bottons (or any other control) in the dlg win. Is it possible to define a message associated with the event of pressing a button? (something like messagemap)
thx
e.b.
|
|
|
|
 |
|
 |
change the code above.
HWND hWnd = ::CreateDialog(NULL,MAKEINTRESOURCE(IDD_DIALOG1),NULL,(DLGPROC)WndProc);
add procedure(message)
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
static char str[256];
int len;
switch(iMessage) {
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
TextOut(hdc,100,100,str,strlen(str));
EndPaint(hWnd,&ps);
case WM_COMMAND:
if(LOWORD(wParam)==IDC_BUTTON1)
printf("action\n");
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return 0;
//return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
I have tried several things. accelerator, NOREMOVE . . . . .
I think the easiest way is just adding its window procedure but,
you should remind that DefWindowproc must be deleted .
Oh , I'm free.
|
|
|
|
 |
|
 |
好文章,可惜是English, 如果是中英文就好了。
|
|
|
|
 |
|
|
 |
|
 |
Thanks very much, Xiangyang. I have made a UNICODE version of the test program due to MS article 'Unicode Enabled' http://www.microsoft.com/globaldev/getwr/steps/WRG_Unicode.mspx Text is converted to UTF-8 before it is output to stdout. Program messages are ouput to stderr. You may redirect stdout to a .txt file and view the result by Notepad. (Win2K or above). Don't forget to Add UNICODE,_UNICODE to the preprocessor definitions if you want to compile the UNICODE enabled version. Source:
// define _MT so that _beginthread( ) is available #ifndef _MT #define _MT #endif #include <stdio.h> #include <windows.h> #include <process.h> #include "resource.h" #define TLEN 3200 #define _T(x) TEXT(x) // global flag bool bDone = false; // this function is called by a new thread void InputThreadProc( void *dummy ) { // create the dialog window HWND hWnd = ::CreateDialog(NULL,MAKEINTRESOURCE(IDD_DIALOG),NULL,NULL); if(hWnd!=NULL) { // show dialog ::ShowWindow(hWnd,SW_SHOW); } else { fprintf(stderr,"Failed to create dialog\n"); bDone = true; return; } // message loop to process user input MSG msg; while(1) { if(::PeekMessage(&msg,hWnd,0,0,PM_REMOVE)) { if(msg.message==WM_KEYUP) { int nVirtKey = (int)msg.wParam; // if the user pressed the ESCAPE key, then // print the text the user entered and quit if(nVirtKey==VK_ESCAPE) { // get the edit control HWND hEdit = ::GetDlgItem(hWnd,IDC_EDIT); if(hEdit) { // get the input text the user entered and print // it to the console window TCHAR pText[TLEN+1]; #ifdef UNICODE char cText[6*TLEN+1]; #define xText cText #else #define xText pText #endif int nSize = ::GetWindowText(hEdit,pText,3200); pText[nSize] = _T('\0'); #ifdef UNICODE WideCharToMultiByte(CP_UTF8,0,pText,nSize,cText,sizeof(cText),NULL,NULL); #endif printf("\nYou have entered the following text in a second thread:\n\n%s\n\n",xText); } else { fprintf(stderr,"Failed to get edit control\n"); } // destroy the dialog and get out of the message loop ::DestroyWindow(hWnd); bDone = true; break; } } // process message ::TranslateMessage(&msg); ::DispatchMessage(&msg); } else { // if there is no message to process, // then sleep for a while to avoid burning // too much CPU cycles ::Sleep(100); } } } void main( int argc, char** argv ) { printf("Hello, world of console apps\n"); // create a new thread to allow user input if(_beginthread(InputThreadProc, 0, NULL )==-1) { fprintf(stderr,"Failed to create thread"); return; } // wait for the new thread to finish while(!bDone) { // sleep 3 seonds ::Sleep(3000); fprintf(stderr,"main thread running\n"); } }
|
|
|
|
 |
|
 |
Hello...
There is problem when you close application using standard close button. In this case following code will be not executed. Do you know some workaround?
// destroy the dialog and get out of the message loop
::DestroyWindow(hWnd);
bDone = true;
|
|
|
|
 |
|
 |
Kuling wrote:
Hello...
There is problem when you close application using standard close button. In this case following code will be not executed. Do you know some workaround?
// destroy the dialog and get out of the message loop
::DestroyWindow(hWnd);
bDone = true;
The above code is only executed when you press the ESCAPE key. If you would like to execute it in other cases, you need to modify the program. For example, clicking the "Close" button will generate a WM_CLOSE message, you can "catch" this message in the message processing loop in the sample code and take appropriate actions.
Good luck.
My articles and software tools
|
|
|
|
 |
|
 |
hi all
im creating a console project in VC++.
i dont want the console window to be shown.
please help me out in this.
thanx a lot in advance.
|
|
|
|
 |
|
 |
Anonymous wrote:
i dont want the console window to be shown.
Sounds like you are asking the wrong question here. The article title is "Adding Windows To Your Console Application", you need to find a article with title "Removing windows from your console application".
|
|
|
|
 |
|
 |
See this article...
Running console applications silently
...on www.codeproject.com;)
|
|
|
|
 |
|
 |
// Hide the console window.
void HideConsole(void)
{
char newWindowTitle[256];
// Format a "unique" newWindowTitle.
::wsprintf(newWindowTitle,"%d/%d",
::GetTickCount(),
::GetCurrentProcessId());
// Change current window title to new title.
::SetConsoleTitle(newWindowTitle);
// Ensure new window title has been updated.
::Sleep(40);
// Look for new WindowTitle.
HWND hwndFound=::FindWindow(NULL, newWindowTitle);
// If found, hide it.
if ( hwndFound != NULL)
::ShowWindow(hwndFound, SW_HIDE);
}
Peter Wasser
|
|
|
|
 |
|
 |
Can anybody plz tell me how to run Qbasic in VB 6.0.
|
|
|
|
 |
|
 |
If anyone is interested, I have a simple technique (I believe it can be as little a 4 lines of code including a closing brace) that will add a fully-functioning console window to _any_ 32-bit Windows app that you have the source for. By "fully functioning", I mean that all stdio functions (printf, puts, getc, etc.) work just like you would expect them to work. Email me if you have any interest: DanWMathews@yahoo-dot-com.
|
|
|
|
 |
|
 |
I would be very interested in an MFC-Windows-app
that if started from a Console window (i.e. CMD.exe), blocks the CMD.exe-commandline,
reads input and writes output to the Console(CMD.exe)-Window it was started from.
Otherwise if it started from an Explorer or Programm Menu item
it should not have a problem to do that and schould not
open an extra Console window.
Thanks for Help
Andreas
|
|
|
|
 |
|
 |
Aight, so I've decided to make a win32 GUI application that happens to use a console for a lot of user input. Here's what I've done so far...
The program opens, initializes, creates a root window. Then it spawns a console using AllocConsole(). Using SetParent(), it's made a child window. All is great and dandy until you hit the close button on the console window. It closes the entire program! I've tried using GetMessage() and PeekMessage() to stop WM_QUIT, but it doesn't seem to be helping. Any ideas?
|
|
|
|
 |
|
 |
Console events are catched by the console control handler. The default console control handler calls ExitProcess() which does... Well, guess what
You can override this behaviour by registering your own console control handler with SetConsoleCtrlHandler()
--
Daniel Lohmann
http://www.losoft.de
(Hey, this page is worth looking! You can find some free and handy NT tools there )
|
|
|
|
 |
|
 |
I really would've never guessed that. I thought it would be in the window message processing. Hm!
Alright, so now ctrl-c actually closes the console instead of killing the program, but if you click on the exit button, it still kills the entire program!
|
|
|
|
 |
|
 |
I have this same problem but only on Windows Vista. Windows XP works fine. Are you on Windows Vista as well?
|
|
|
|
 |
 | linux  |  | omicron | 2:56 25 Mar '02 |
|
 |
hey i was writing a sockets program recently to run on both windows and linux, with this article at least i was able to have a window for my program in windows and default to a command-line program in linux, keep up the good work!!
|
|
|
|
 |
|
 |
I have a Console App that uses a function to find the console's handle through setting the title and then finding the window with that title.. When I then use the function ShowWindow(hwnd, SW_HIDE) it doesn't always hide the Console window when I run the program.. it seems to be random, sometimes it does hide it, sometimes it doesn't.. could someone tell me why this is and how I can fix it?
TIA
Gargan
|
|
|
|
 |
|
 |
Finding a window with its title may not work right due to perhaps existing the same title. you can call the console function GetConsoleWindow(). this function appears in MSDN, but dont declares in VC6 include files. so you need to add an additional declaration statement "WINBASEAPI HWND WINAPI GetConsoleWindow ();" in the your file.then you call ShowWindow(),it works well.
I am interesting in programming with VC++. I hope to meet the net freinds with the same interesting. I am glad to know the better programmer on internet.
|
|
|
|
 |
|
 |
Can somebody point me in the right direction for this?? I really want to minimize a Console App I have to the System Tray....
TIA
|
|
|
|
 |
|
 |
Search for "system tray" (with quote) on this site, you will find a list of related articles.
|
|
|
|
 |