小编Jic*_*hao的帖子

在 WM_PAINT 中绘制(太慢)会导致闪烁?

我想使用以下代码在 WM_PAINT 消息处理程序中绘制很多行。

//DrawLine with double buffering
LRESULT CALLBACK CMyDoc::OnPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
    std::vector<Gdiplus::Point> points;
    std::vector<Gdiplus::Point>::iterator iter1, iter2;
    HDC hdc, hdcMem;
    HBITMAP hbmScreen, hbmOldBitmap;
    PAINTSTRUCT ps;
    RECT    rect;

    hdc = BeginPaint(hWnd, &ps);

    //Create memory dc
    hdcMem = CreateCompatibleDC(hdc);
    GetClientRect(hWnd, &rect);
    hbmScreen = CreateCompatibleBitmap(hdc, rect.right, rect.bottom);
    hbmOldBitmap = (HBITMAP)SelectObject(hdcMem, hbmScreen);

    //Fill the rect with white
    FillRect(hdcMem, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH));

    //Draw the lines
    Gdiplus::Graphics graphics(hdcMem);
    Gdiplus::Pen blackPen(Gdiplus::Color(255, 0, 0));

    points = m_pPolyLine->GetPoints();
    for (iter1 = points.begin(); iter1 != points.end(); iter1++) …
Run Code Online (Sandbox Code Playgroud)

winapi gdi+ gdi

1
推荐指数
1
解决办法
4622
查看次数

如何在C++类中使用引用变量?

我想在类中有一个引用数据成员,但我不想在构造函数中初始化它.

我怎么能这样做?

c++

1
推荐指数
1
解决办法
120
查看次数

如何使用std :: shared_ptr实现缓存管理器?

#include <mutex>
#include <assert.h>
#include <iostream>
#include <unordered_map>
#include <memory>
#include <string>
#include <stdio.h>

// 
// Requirements:
//  1: the bitmap could be used by multiple thread safely.(std::shared_ptr could?)
//  2: cache the bitmap and do not always increase memeory
//@NotThreadSfe
struct Bitmap {
    public:
        Bitmap(const std::string& filePath) { 
            filePath_ = filePath;
            printf("foo %x ctor %s\n", this, filePath_.c_str());
        }
        ~Bitmap() {
            printf("foo %x dtor %s\n", this, filePath_.c_str());
        }
        std::string filePath_;
};

//@ThreadSafe
struct BitmapCache {
    public:
        static std::shared_ptr<Bitmap> loadBitmap(const std::string& …
Run Code Online (Sandbox Code Playgroud)

c++ caching memory-management c++11

1
推荐指数
1
解决办法
2050
查看次数

self.backgroundcolor和self.layer.backgroundcolor之间有什么区别吗?

@implementation AVSuperView

- (AVSuperView*)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
//        self.backgroundColor = [UIColor redColor];
        self.layer.backgroundColor = [[UIColor redColor] CGColor];
        AVLayout* avLayout = [[AVLayout alloc] init];
Run Code Online (Sandbox Code Playgroud)

在上面的自定义UIView中,例如self.backgroundColor和似乎self.layer.backgroundColor相同。是self.backgroundColor包装纸self.layer.backgroundColor吗?

cocoa-touch core-animation ios

1
推荐指数
1
解决办法
238
查看次数

一个特定的C编程风格问题?

我听过很多关于编程风格的重要性.在我看来,缩进很容易处理.但其他事情让我很沮丧.考虑一个特定的例子来演示inet_makeaddr的使用.

/* demonstrate the use of host address functions */
#include <stdio.h>
#include <arpa/inet.h>
#include <netinet/in.h>

int
main(void)
{
 /* inet_makeaddr demo */
 uint32_t neta = 0x0a3e5500;
 uint32_t hosta = 0x0c;

 struct in_addr alla = inet_makeaddr(neta, hosta);

 printf("makeaddr of net: %08x and host: %08x = %08x\n", 
    neta, hosta, alla);

 return 0;
}
Run Code Online (Sandbox Code Playgroud)

有人可能想写如下:

 uint32_t neta;
 uint32_t hosta;
 struct in_addr alla;

 neta = 0x0a3e5500;
 hosta = 0x0c;
 alla = inet_makeaddr(neta, hosta);
Run Code Online (Sandbox Code Playgroud)

然后其他人可能总是在定义时初始化变量:

 uint32_t neta = 0;
 uint32_t hosta = 0;
 struct …
Run Code Online (Sandbox Code Playgroud)

coding-style

0
推荐指数
1
解决办法
725
查看次数

std :: string如何重载赋值运算符?

class mystring { 
private:
 string s;
public:
 mystring(string ss) { 
  cout << "mystring : mystring() : " + s <<endl; 
  s = ss;
 }
 /*! mystring& operator=(const string ss) { 
  cout << "mystring : mystring& operator=(string) : " + s <<endl;
  s = ss; 
  //! return this; 
  return (mystring&)this; // why COMPILE ERROR
 } */
 mystring operator=(const string ss) {
  cout << "mystring : mystring operator=(string) : " + s <<endl;
  s = ss;
  return *this;
 } 
 mystring operator=(const char …
Run Code Online (Sandbox Code Playgroud)

c++ string operator-overloading stdstring

0
推荐指数
1
解决办法
4743
查看次数

确定一个数字是否为素数的好算法?

可能重复:
更有效地检查int是否为素数

我需要测试一些非常大的整数来看它是否是素数.你能提供一些好的算法或库例程吗?

编辑:C/C++就行了.

谢谢.

algorithm primes

0
推荐指数
1
解决办法
702
查看次数

java GUI创建的线程安全问题

在以下示例代码中,

/*
 * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of …
Run Code Online (Sandbox Code Playgroud)

java swing

0
推荐指数
1
解决办法
1419
查看次数

EJB之前的生活是什么?

我正在读一本关于EJB的书.它列出了EJB的旧技术的一个优点,即它可以从一个特定的应用程序服务器供应商及其专有API中释放程序员.

我想知道EJB出现之前的生活是什么?程序员在过去使用了哪种特定的应用程序服务器?你能给我一个线索吗?谢谢.

ejb java-ee

0
推荐指数
1
解决办法
326
查看次数

有没有办法在python中查看float的内部表示?

python浮点教程中,

在碱2中,1/10是无限重复的部分

0.0001100110011001100110011001100110011001100110011 ...

如何让python解释器打印这种内心表示?repr(0.1)没有帮助.

python floating-point

-1
推荐指数
1
解决办法
886
查看次数