Wednesday, August 26, 2009

Windows Programming Pointers

Console Event Handling
http://www.codeproject.com/KB/winsdk/console_event_handling.aspx?msg=338390

Dialogs & Windows
http://www.codeproject.com/KB/dialog/index.aspx <== Here you can also find information about windows message handling using both MFC and SDK.


(From some webpost: http://stackoverflow.com/questions/764869/c-console-app-event-handling)
See the topic "Using Messages and Message Queues" in MSDN (under Win32 and COM Development > User Interface > Windows User Experience > Windows Management > Windows User Interface > Windowing > Messages and Message Queues; you'll probably need to take a look at the other articles and samples in the same section). Quick summary, omitting error handling and using C syntax rather than C# for reasons discussed below:

RegisterClass(...);
CreateWindow(...);
ShowWindow(...); // probably not in your case
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}

As you can see from the window setup boilerplate, this still relies on "silent windows," albeit created and message-pumped via the Win32 API rather than through WinForms. So you're not really gaining anything by doing this way. Hence my feeling there's not much point translating this stuff into C# -- if the only solution to your problem is an invisible window, you may as well use an invisible Windows Form and all the friendly wrappers that come with that platform.

However, if you're not actually using a Windows Forms control like the poster of the linked question, then you can quite happily use .NET events in a console application. The restriction to STA and the need for a message pump is specific to receiving events from WinForms and ActiveX controls like the WebBrowser (or messages from Win32 HWNDs, though that doesn't necessarily require STA).


Console App vs Win32 App
Console application can easily be changed to Windows application (Win32 App) by simply changing the entrypoint main() to WinMain() and changing the Linker | System | SubSystem option in the project properties options. The only catch is that with Win32 App, the console input output is gone. Forms or dialog boxes are needed to get user input & display outputs.

Windows++ & PixieLib
Former is a lean MFC style framework (much leaner though) & later is an extension to MFC classes and provide other utility classes. However I could not get it to run properly on VC++2008 (even when i was able to compile it)


String Conversions
Convert between various string types: wchar to char, etc. - Here

Nice Tutorial on using Win32 API

Simple Word Processing with an Edit Control
MSDN Example

New Line & Edit Control
Use \r\n instead of \n. Just using\n will show as small square character in the edit control.


Adding a Status Bar
MSDN Example or search for Status Bars which is part of common control dynamic-link library

No comments:

Post a Comment