Does anyone know how to use this?
I was browsing a few tutorials on the net, and I saw one that shows how to display stuff on the screen.
I added a few events.
This is my code: -
#include <windows.h> // FOR ANY DIFFICULTIES, REFER TO THE MSDN. IT IS VERY USEFUL.
-
-
HWND hwndMain;
-
-
LRESULT CALLBACK MainWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);//CALLBACK function prototype
-
-
-
int WINAPI WinMain(HINSTANCE hInstance,
-
HINSTANCE hPrevInstance,
-
LPSTR lpCmdLine,
-
INT nCmdShow)
-
{
-
MessageBox(NULL,"This is a test of Lesson 02", "Lesson 02 Test",MB_OK);
-
-
MSG msg; //var to store messages
-
WNDCLASSEX window; //WINDOW class information
-
-
//initialize all values of window struct to zero
-
ZeroMemory(&window,sizeof(WNDCLASSEX));
-
-
window.cbSize = sizeof(WNDCLASSEX);// Window Size. Must always be sizeof(WNDCLASSEX)
-
-
window.style = CS_HREDRAW|CS_VREDRAW |CS_DBLCLKS ; // Class styles. These are necessary for a proper functioning window
-
-
window.lpfnWndProc = (WNDPROC)MainWndProc; // Pointer to the callback procedure
-
-
window.cbClsExtra = 0; //Specifies the number of extra bytes to allocate following the window-class structure. The system initializes the bytes to zero.
-
-
window.cbWndExtra = 0; //Specifies the number of extra bytes to allocate following the window instance. The system initializes the bytes to zero. If an application uses WNDCLASSEX to register a dialog box created by using the CLASS directive in the resource file, it must set this member to DLGWINDOWEXTRA.
-
-
window.hInstance = hInstance; //Instance of the application. Notice that it is the same one from the WinMain prototype
-
-
window.hIcon = NULL; // Icon of the window class
-
-
window.hCursor = LoadCursor(NULL, IDC_ARROW);// Class cursor.
-
-
window.hbrBackground = (HBRUSH)(COLOR_WINDOW); /*Handle to the class background brush.
-
This member can be a handle to the physical brush to be used for painting the background, or it can be a color value.
-
A color value must be one of the following standard system colors (the value 1 must be added to the chosen color).
-
*/
-
window.lpszMenuName = NULL; //Menu resource
-
-
window.lpszClassName = "Lesson2"; // Name of this class
-
-
window.hIconSm = LoadIcon(NULL,"logo.bmp"); // Small icon for this class
-
-
// Register this window class with MS-Windows
-
if (!RegisterClassEx(&window))
-
return 0;
-
-
-
//Now to create the window!
-
-
// Create the window
-
-
hwndMain = CreateWindowEx(0, //Extended window style
-
"Lesson2", // Window class name
-
"Lesson 2 - A simple win32 application", // Window title
-
WS_OVERLAPPEDWINDOW, // Window style
-
CW_USEDEFAULT,CW_USEDEFAULT, // (x,y) pos of the window
-
CW_USEDEFAULT,CW_USEDEFAULT, // Width and height of the window
-
HWND_DESKTOP, // HWND of the parent window (can be null also)
-
NULL, // Handle to menu
-
hInstance, // Handle to application instance
-
NULL); // Pointer to window creation data
-
-
-
// Check if window creation was successful
-
if (!hwndMain)
-
return 0;
-
-
//Make window visible
-
-
ShowWindow(hwndMain,SW_SHOW);
-
-
// Process messages coming to this window
-
-
while (GetMessage(&msg,NULL,0,0))
-
{
-
TranslateMessage(&msg);
-
DispatchMessage(&msg);
-
}
-
-
-
-
// return value to the system
-
-
return msg.wParam;
-
}
-
-
LRESULT CALLBACK MainWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
-
{
-
PAINTSTRUCT paintStruct;
-
-
-
HDC hDC;
-
char message[] = "KILL ALL HUMANS";
-
-
-
switch (msg)
-
{
-
case WM_DESTROY:
-
// User closed the window
-
MessageBox(NULL, "Exit","CAPTION",NULL);
-
PostQuitMessage(0);
-
break;
-
case WM_LBUTTONDOWN:
-
//User pressed the left mouse button
-
MessageBox(hwnd,"BEEP","BEEP",MB_OK | MB_APPLMODAL);
-
MessageBeep(MB_OK);
-
MessageBox(NULL,"PRINTING TO SCREEN","CAPTION",NULL);
-
-
//paint to screen
-
hDC = BeginPaint(hwnd,&paintStruct);
-
-
/* Set Text color to blue */
-
SetTextColor(hDC, COLORREF(0x00FF0000));
-
-
/* Display text in the middle of the window */
-
TextOut(hDC,150,150,message,sizeof(message)-1);
-
-
//Tell OS you are done painting
-
EndPaint(hwnd, &paintStruct);
-
-
return 0;
-
break;
-
-
case WM_CHAR:
-
//User Pressed a character from the keyboard
-
MessageBox(NULL, "You Pressed a Key","CAPTION",NULL);
-
break;
-
// case WM_ACTIVATE:
-
// MessageBox(NULL,"THE FORM IS ACTIVE","CAPTION",NULL);
-
// break;
-
-
-
default:
-
// Call the default window handler
-
return DefWindowProc(hwnd,msg,wParam,lParam);
-
}
-
return 0;
-
}
-
I searched and searched and I just cand find why it does not work.
Have I got my theory wrong?
3 12637
hi,
Did u try Updatewindow() after showwindow?
Xoinki
Banfa 9,065
Recognized Expert Moderator Expert - case WM_LBUTTONDOWN:
-
//User pressed the left mouse button
-
MessageBox(hwnd,"BEEP","BEEP",MB_OK | MB_APPLMODAL);
-
MessageBeep(MB_OK);
-
MessageBox(NULL,"PRINTING TO SCREEN","CAPTION",NULL);
-
-
//paint to screen
-
hDC = BeginPaint(hwnd,&paintStruct);
-
-
/* Set Text color to blue */
-
SetTextColor(hDC, COLORREF(0x00FF0000));
-
-
/* Display text in the middle of the window */
-
TextOut(hDC,150,150,message,sizeof(message)-1);
-
-
//Tell OS you are done painting
-
EndPaint(hwnd, &paintStruct);
-
-
return 0;
-
break;
-
BeginPaint and EndPaint are only for use while handling a WM_PAINT message (I suggest you look them up on MSDN).
UpdateWindow forces a the window to be sent a WM_PAINT message forcing a screen update if you have implemented a WM_PAINT handler.
You should either - Call GetDC and Release DC instead of BeginPaint and EndPaint in you WM_LBUTTONDOWN handler
- Implement the WM_PAINT handler and move the code that draws to the screen into that handler
BeginPaint and EndPaint are only for use while handling a WM_PAINT message (I suggest you look them up on MSDN).
UpdateWindow forces a the window to be sent a WM_PAINT message forcing a screen update if you have implemented a WM_PAINT handler.
You should either - Call GetDC and Release DC instead of BeginPaint and EndPaint in you WM_LBUTTONDOWN handler
- Implement the WM_PAINT handler and move the code that draws to the screen into that handler
I see. I shall try that
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Chi Tang |
last post by:
Hi,
I need to implement a stand alone gui application which need to call some
other regular DLL functions (unmanaged code). Should I use .net with C# or
just use Win32 API to write this exe? Is it easy to call any DLL function
from .net/C# program?
The 2nd question is that on a win32 app, I can use 'UNICODE' to support
localization...
|
by: Eitan |
last post by:
Hello,
I am using Visual Studio.net 2003.
I am trying to find how to create Win32 DLL & Win32 Static Library.
When going through the wizard it does not show me the option for these two
project types.
Any Idea?
Eitan
|
by: dthom |
last post by:
Hi,
I have a C# service application - and a Win32 / C++ service application
running on my system.
I need someway to interact between those two - the Win32 application is pure
Win32 - so im not using any components or anything like that.
The 2 alternatives i could think of was, messages or creating a TCP/IP
socketserver on the C# end,...
|
by: Tony Johansson |
last post by:
Hello!
I just wonder what the difference is between a native win32-app and MFC.
What I know is that you can use Win32 API in both cases.
I think an MFC application is connected with a GUI which a win32 is not. You
may correct me if I'm wrong on this point.
//Tony
|
by: sandycat05 |
last post by:
Hello all, I am a new Perl programmer. Below is the beginnings of a code that I am using to manipulate an Excel spreadsheet via Perl using win32::OLE. However, what I'd like to do is the following: instead of either opening a file or creating a new one, I'd like to do BOTH. I was thinking of creating a loop where I could basically say something...
| |
by: Gil |
last post by:
I need to create a web page in which its content should be controlled by
some win32 application. this application may add or remove some gif images
from the page and it should be smooth as possible as can.
Can someone here direct me how to start that.
Thanks in advance
Gil
|
by: coss |
last post by:
Hi, I`m currently working with Borland C++Builder v6.0
In my program at it's startup some text should be read from file and displayed in the form, on top of the image. I use Canvas->TextOut(), but text is not displayed. I quess some layer covers it, but can't find way how to fix it. But when the program is already loaded and I press button that...
|
by: =?Utf-8?B?Q29saXZpZXI=?= |
last post by:
If anyone can help me with this I would really appreciate it:
I have an assembly into which I have linked a manifest file as a Win32
resource. This is necessary since I want to use a class in this assembly with
registration-free COM interop from a Win32 application.
I also want to use this assembly with a .Net application that I want to...
|
by: user1357 |
last post by:
Hi all,
i am trying to run the following code
use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |