15,899,314 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Carlos_never (Top 7 by date)
Carlos_never
20-Sep-10 23:37pm
View
don`t forgot RegisterClassEx
Carlos_never
20-Sep-10 23:36pm
View
sorry for late reply.. I write the code follow your style.
WNDCLASSEX only have two more parameters, cbsize and smIcon, maybe you had used cbsize, but ignore smIcon.
add this code
wc.cbSize=sizeof(WNDCLASSEX);
wc.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
and then use createWindowEx .
good luck
Carlos_never
18-Sep-10 7:08am
View
do not forget the <windows.h>,
Carlos_never
18-Sep-10 7:05am
View
I used UNICODE as the char* type, so I add "L" before each char*. if you use ASCII, please delete the "L"
Carlos_never
18-Sep-10 7:02am
View
my fault! I find the code,copy here directly,without runnning!
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) // call back function
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
}
return DefWindowProc(hWnd,msg,wParam,lParam);
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
HWND hwnd; //handle to the main window
MSG Msg;
WNDCLASS wcex;
wcex.style = 0; // window style
wcex.lpfnWndProc=WndProc; // appoint the call back function, you loss it
wcex.lpszClassName=L"Hello";
wcex.lpszMenuName=NULL; // no menu
wcex.hInstance=hInstance; // current instance handle,which was one parameter of main function
wcex.hIcon=LoadIcon(NULL,IDI_APPLICATION); // the icon style
wcex.hCursor=LoadCursor(NULL,IDC_ARROW); // the cursor style
wcex.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); // the black ground color is whit
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
if(!RegisterClass(&wcex))
{
return 0;
}
hwnd = CreateWindow(L"Hello",L"Hai",WS_OVERLAPPEDWINDOW,0,0,500,400,NULL,NULL,hInstance,NULL);
if(hwnd == NULL)
return 0;
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg,NULL,0,0)) // message loop
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
Carlos_never
18-Sep-10 1:03am
View
I think you are sleep now. you can do like blow, and when you create a window successfully,you should compare the difference.
#include<windows.h>
LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam); // call back function
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return(0);
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
HWND hwnd; //handle to the main window
MSG Msg;
WNDCLASSEX wcex;
wcex.style=0;
wcex.lpfnWndProc=WndProc; // appoint the call back function, you loss it
wcex.lpszClassName="Hello";
wcex.lpszMenuName=NULL; // no menu
wcex.hInstance=hInstance; // current instance handle,which was one parameter of main function
wcex.hIcon=LoadIcon(NULL,IDI_APPLICATION); // the icon style
wcex.hCursor=LoadCursor(NULL,IDC_ARROW); // the cursor style
wcex.cbSize=sizeof(&wcex);
wcex.cbClsExtra=NULL; // no extra style
wcex.cbWndExtra=NULL; // no extra style
wcex.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); // the black ground color is whit
RegisterClassEx(&wcex);
hwnd=CreateWindowEx(NULL,"Hello","Hai",WS_OVERLAPPEDWINDOW,0,0,500,400,NULL,NULL,hi,NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while( GetMessage(&Msg,NULL,0,0)) // message loop
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
Carlos_never
18-Sep-10 0:40am
View
write the code follow the Answer 4. "LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) " is your call back function,which was transfered by OS. Messages which you could use to control the window are sent to that function.
"while (GetMessage(&msg, NULL, 0, 0)) DispatchMessage(&msg);" is a message queue, you use it to get messages from OS,and then send the messages to your call back funtion.
in your WNDCLASS object,there is a parameter called lpfnWndProc,which you could appoint the call back funtion. wcex.lpfnWndProc = WndProc
Show More