Click here to Skip to main content
15,899,314 members

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;
}